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

FUNCTION I2COUT (DATApin, CLKpin, addr, OUTcnt, BYREF OUTlist as string)


I2COUT will send OUTcnt bytes from OUTlist bytes as i2c serial data on CLKpin and DATApin to the i2c device at addr.  If OUTcnt is 0, then the string will be sent until a 0, CR or LF character is found in OUTlist.  If the i2c device does not respond 0 is returned by I2COUT, otherwise 1.

I2COUT returns a 1 if an I2C device responds, else 0.

The data rate is 280Kb.  See the #defines to change this rate.


#include <I2C.bas>

DIM shortMessage(20) as STRING

' test the EEPROM 24LC02 on pins 0 == SDA and 1 == SCL
shortMessage(0)= 0                  ' address into EEPROM
shortMessage(1)= 11                ' data
shortMessage(2)= 22
shortMessage(3)= 33
shortMessage(5)= 44
shortMessage(6)= 55
shortMessage(7)= 66

present = I2COUT (0, 1, 0xA0, 8, shortMessage) 
if present = 0 then print "NO i2c device ***"

Differences from other BASICs

See also