Home‎ > ‎'Desktop' Linux Distributions‎ > ‎Slackware‎ > ‎

i2c

TCN75 Temperature sensor 

The TCN75 is a low power i2c temperature sensor.  We will use this for the i2c demonstration.  These instructions apply only to Slackware, however they are close to what's needed on Debian


For convenience, all address lines (A0-2) are connected to Vdd (that's +3.3v), we only have one device, so it doesn't matter what address it takes.  INT/CMPTR is left unconnected.

On the Bifferboard

Vdd (and A0-A2) are connected to Pin 1 of J1 (3.3v)
GND is connected to Pin 6 of J1 (GND)
SDA will be connected to Pin 2 of J1, (TMS), mapped to GPIO 11
SCL will be connected to Pin 3 of J1, (TDI), mapped to GPIO 13

The Bifferboard already has 10k pull-ups on the JTAG GPIO lines, so we don't need any i2c pull-ups making the circuit very simple.

Required Software

We will need some software to communicate with the i2c device.  I am assuming you've already configured your Bifferboard for compiling software, so go back to that page if you get any errors from the following instructions.

Compile and install the i2c tools:

root@darkstar:/# wget http://dl.lm-sensors.org/i2c-tools/releases/i2c-tools-3.0.2.tar.bz2
root@darkstar:/# tar xvf i2c-tools-3.0.2.tar.bz2
root@darkstar:/# cd i2c-tools-3.0.2
root@darkstar:/# make install

Kernel modules

We need to load some kernel modules to talk to the i2c device we've connected to GPIOs 11 and 13.  The default Slackware kernel doesn't have module unload support, so I'm afraid you'll have to get this right first time! :).

First of all, we need the GPIO subsystem, which is itself a module, so load that:

root@darkstar:/# modprobe rdc321x_gpio
RDC321x GPIO driver: 'bank1' enabled
RDC321x GPIO driver: 'bank2' enabled

Then load the various i2c library modules:

root@darkstar:/# modprobe i2c-core
root@darkstar:/# modprobe i2c-algo-bit
root@darkstar:/# modprobe i2c-gpio

Load the 'custom' module, which maps the GPIO pins to the i2c driver.  Here's where you specify the pins used in your circuit. Three parameters are required for this module, the first is a logical bus name, we'll use zero, increase this number if you want more i2c busses.  The second and third are the SDA and SCL pins respectively.

root@darkstar:/# modprobe i2c-gpio-custom bus0=0,11,13
Custom GPIO-based I2C driver version 0.1.1
i2c-gpio i2c-gpio.0: using pins 11 (SDA) and 13 (SCL)

The i2c-dev module was left out of the Slackware tarball, but can be downloaded from here. (Put it somewhere in /lib/modules/yourkernelname
then run depmod -a. ) You also need that:

root@darkstar:/# modprobe i2c-dev


Application software


Run i2cdetect to check the bus got loaded:

root@darkstar:~# i2cdetect -l
i2c-0 i2c       i2c-gpio0                       I2C adapter

Then run i2cdetect with this bus number to detect devices on the bus:

root@darkstar:/# i2cdetect -y 0
    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4f
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

You can get the temperature by byte-reading the default register, e.g.:

root@darkstar:/# i2cget -y 0 0x4f
0x15


You can convert this to decimal using a simple bash trick:

root@darkstar:~# echo $(($(i2cget -y 0 0x4f)))
21

Run i2cget (and i2cset) without arguments for other options.


Veroboarding the TCN75

Although the TCN75 is surface-mount, it's possible to put it on standard 0.1 inch stripboard.  The interrupt pin isn't needed for Bifferboard applications, so I simply removed it (being careful not to twist it, that's why it looks untidy):


Now if two of the address lines can be tied together, we can align pins 1 and 8 to one strip, pins 2, 6, 7 on another, and pins 4 and 5 on the third.  I ended up with a board looking like this:


In this circuit the address pins (A0-2) are all connected to GND instead of Vdd, so it appears on the I2C bus at address 0x48.

The connector on the left mirrors J1: 3.3v at the top, GND at the bottom.  In this circuit SDA and SCL are GPIO pins 9 and 12 respectively, I used:

root@darkstar:/# modprobe i2c-gpio-custom bus0=0,9,12

A ribbon cable with 6-way female connectors at each end joins the Bifferboard to the module:


ċ
i2c-dev.ko
(9k)
Biff Eros,
Nov 28, 2009, 6:02 AM
ċ
kmod-i2c-dev_2.6.30.5-biff-1_i386.ipk
(5k)
Biff Eros,
May 9, 2010, 1:42 PM
Comments