Using TNC-PI via i2c Interface

Enabling i2c on PI

Note. On Version 1 boards (without the two mounting holes) the i2c bus on the main header is number 0. On Version 2 boards it is number 1.

To use i2c, (which you need if you want to run more than one TNC-PI) you need to enable loading of the Kernel i2c module, and load the i2c userspace interface

Edit /etc/modprobe.d/raspi-blacklist.conf, and remove line blacklist i2c-bcm2708.

Edit /etc/modules and add line i2c-dev

Install i2c tools - not essential, but useful when testing sudo apt-get install i2c-tools

Reboot the PI

By default user PI won't have access to the i2c bus. Ypu can run everything as root using sudo, but it is better to give pi access to the i2c bus by adding user pi to group i2c

sudo usermod -a -G i2c pi

You'll need to log in again to pick up the new groups. If all this has worked you should be able to run the command

i2cdetect 1    (or i2cdetect 0 if using a Version 1 board).This lists all devices sound on the bus.

Configuring TNC

The TNC is shipped configured to use the serial port. To enable i2c you have to change the value in location 7 of the NVRAM. If you have more than one TNC you have to do one at a time - you cant have two TNCs using the serial port at the same time. So plug in one of the TNCs, and run

./pitnc_getparams 0 0 - you should get something like

01 TXDelay - Zero means use ADC  00
02 Persistance 64
03 Slottime (in 10 mS) 10
04 TXTail 0
05 Full Duplex - Not used 0
06 Our Channel (Hex) 00
07 I2C Address (0 = async) Hex 00
ADC Value 28
8 0 00 40 a 0 0 0 0 1c 74 c0 sum 2
Set the i2c address - I usually start from 16 (for no very good reason)

Warning - the i2c address must be between 3 and 119.

./pitnc_setparams 0 0 7 16   This should now show that location 7 is 16 (10 hex) Confirm with another get_params. Note that it wont switch to i2c mode till the TNC is reset. To do this set reg 15 to 2

./pitnc_setparams 0 0 15 2   The leds should flash, but you wont get a response (as the program is still in serial mode). Now read the params in i2c mode

./pitnc_getparams 1 16   (assuming it is a Version 2 board (with the mounting holes). It should now respond.

You can also use i2cdetect to check that the TNC is visible on the i2c bus.

John Wiseman G8BPQ