I2C Master/Slave communication using two SUB-20 boards

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

Post Reply
serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

I2C Master/Slave communication using two SUB-20 boards

Post by serg »

This topic explains how to configure two SUB-20 boards as a I2C master and slave and establish communication between them
We will use the SUB-20 tool application for this demonstration. All the pictures are attached in an archive, see at the bottom of the post

SETUP. Connect boards using 3 wires

MASTER SLAVE COLOR ON PICTURE
SCL GPIO HEADER PIN 1 <-> SCL GPIO HEADER PIN 1 RED
SDA GPIO HEADER PIN 2 <-> SDA GPIO HEADER PIN 2 GREEN
GND GPIO HEADER PIN 34 <-> GND GPIO HEADER PIN 34 WHITE
board connection wires
board connection wires
IMG_0450.JPG (2.44 MiB) Viewed 20070 times
LAUNCH TWO INSTANCES OF THE SUB20-TOOL APPLICATION
01.png
01.png (56.67 KiB) Viewed 20070 times
SLAVE CONFIGURATION

SELECT SUB-20 TOOL INSTANCE FOR THE SLAVE DEVICE
We choose the top one(SN 0000) to be a master and the bottom one(SN 041C) to be a slave

SET THE SLAVE ADDRESS
On I2C tab, put slave address into the "Slave addr(hex)", we use 43. This is a hexadecimal value, click the "Set Config" button on the right
02.png
02.png (57.12 KiB) Viewed 20070 times
FIFO CONFIGURATION
On the FIFO tab check the I2C checkbox and click the "Set Config" button
03.png
03.png (53.5 KiB) Viewed 20070 times
6) WRITE DATA TO THE SLAVE FIFO

On the FIFO, put the data in the "Data(hex)" field. This is a white space separated list of hexadecimal data bytes
04.png
04.png (51.46 KiB) Viewed 20070 times
MASTER CONFIGURATION

SET I2C SCL FREQUENCY

On the MASTER I2C Tab, write the I2C clock frequency into the "Freq(Hz)" field. This is a decimal value in Hz. We use 100000Hz
Click the "Set" button
05.png
05.png (54.33 KiB) Viewed 20070 times
8) I2C BUS SCAN
On the MASTER I2C Tab, click the "Scan" button. The master should find one I2C slave device
06.png
06.png (52.79 KiB) Viewed 20069 times
9) READING DATA
On the MASTER I2C Tab, put the number of bytes to read, we put 8 and click the "Read" button
08.png
08.png (55.13 KiB) Viewed 20069 times
You can see that master is reading 02 03 ... 08 ff. This is because the first scan procedure is using a I2C read operation to find out what slaves are available.
LIMITATIONS: Please note that the slave device WILL NOT be found if the slave FIFO is empty. It should contain at least one dummy byte prior the "scanning". If the number of bytes to read exceeds the number of bytes in the FIFO the buffer is padded with ff at the end
Attachments
master_slave_i2c.zip
pictures in archive
(2.72 MiB) Downloaded 1586 times

Post Reply