I2CIN
 
Syntax


void I2CIN  (int sda_pin, int scl_pin, int slaveADDR, int opt1, int opt2, int opt3, int opt4, int opt5, int cnt , char *inList);

 

Description


I2CIN will read a series of bytes from an I2C slave device.  sda_pin is any expression defining the SDA pin to use.  scl_pin will be designated the SCL pin.  slaveADDR will select a device on the I2C bus.

Up to 5 optional byte values may be writen out prior to reading the inList . If the optX value is -1 then it will not be sent out.  Most i2c devices have a sub-address field that is written immediately before reading.  This field would be held in opt1.  For devices that do not have a sub-address, opt1 can be set to -1.  In this case, no I2C write is performed before the I2CIN.  For some slow i2c devices, they can not respond to a write of sub-address, immediately followed by a read of the device.  For these slow devices (often implemented with a slower micro-processor), it is necessary to do seperate I2COUT and I2CIN with a delay in between.

After any write of the optX ,a series of cnt bytes will be read from the slave to fill the character array inList

I2C is a byte oriented bus, so each transaction will either send a byte value (0 to 255) or receive a byte for each element of the inList .

Data is shifted in at 350 Kbits/sec.

Example

   case 41:   // test EEPROM 24LC02 on pins 0 == SDA and 1 == SCL
    shortMessage[0] = 0;  // address into EEPROM
    for (i=1; i<8; i++) shortMessage[i] = 0x30+i; // set shortMessage to "1234567" 
    present = I2COUT (0, 1, 0xA0,8, shortMessage);
    
    if (present == 0) printStr("NO i2c device ***\n"); else printStr("i2c device found\n");
    I2CIN(0, 1, 0xA0, 0, -1, -1, -1, -1, 7, shortResponse);

See also