I2CIN
 
Syntax


#include <I2C.bas>                                 ' source in /Program Files/Coridium/BASIClib

SUB I2CIN ( DATApin, CLKpin, addr, OUTcnt, BYREF OUTlist as string, INcnt, BYREF INlist as string)
Description


I2CIN will send OUTcnt bytes from OUTlist and then receives INlist bytes as i2c serial data on CLKpin and DATApin from the i2c device at addr. OUTcnt may be -1 and OUTlist empty. If OUTcnt is 0, then the string will be sent until a 0, CR or LF character is found in OUTlist .

If INcnt is 0, then the string will be filled with bytes until a 0, CR or LF character is received.  Note that no bounds checking is performed on the input, and if a 0, CR, or LF is never received then this routine will hang.    As there is no bounds checking its possible to overwrite other variables, if less than 256 bytes have been allocated for the InputList string.

Data is shifted in at 280 Kbits/sec. See the #defines to change this rate.

Example

#include <I2C.bas>
  '...
DIM shortMessage(20)  as STRING
DIM shortResponse(20)  as STRING
 '...

' test the EEPROM 24LC02 on pins 0 == SDA and 1 == SCL
shortMessage(0)= 0                  ' address into EEPROM

I2CIN(0, 1, 0xA0, 1,shortMessage, 7, shortResponse)  


Differences from other BASICs

See also