fl { 8-channel touch sensor-module driver PropForth 5.5 2013/11/11 20:41:37 touch sensor-module Propeller VDD ---- 3.3V GND ---- GND INT SCL ---- P28 SDA ---- P29 } \ =========================================================================== \ Constants \ =========================================================================== \ Slave addres for RH6010 \ h78 wconstant RH6010 hF0 wconstant RH6010 \ register name 0 wconstant Config1 1 wconstant Config2 2 wconstant Key hFC wconstant config hF5 wconstant sls \ =========================================================================== \ Word for I2C_device \ =========================================================================== : err_msg ." I2C error" ; \ If error, print message \ ( n1 -- ) n1:t/f : err? if err_msg cr then ; \ Read data from register in i2c_device \ ( n1 n2 -- n3 t/f ) n1:register n2:slave_address n3:data t/f:true if there was an error : i2c_rd \ Start I2C _eestart \ Write slave address[wr], then receive Acknowledge-bit(ACK:Lo NACK:Hi) tuck _eewrite \ ( n2 n1 t/f ) st? \ Write register swap _eewrite or \ ( n2 t/f ) st? swap \ ( t/f n2 ) \ Start read_process _eestart st? \ Write slave address[rd], then receive Acknowledge-bit(ACK:Lo NACK:Hi) 1 or st? _eewrite st? or \ ( t/f ) st? \ Read 1byte ,then set sda to Hi(NACK:master->slave) -1 _eeread \ Stop I2C _eestop swap \ (n3 t/f ) st? ; \ Write data to register in i2c_device \ ( n1 n2 n3 -- t/f ) n1:data n2:register n3:slave_address t/f:true if there was an error : i2c_wr \ Start I2C _eestart \ Write slave address[wr], then receive Acknowledge-bit(ACK:Lo NACK:Hi) _eewrite \ ( n1 n2 t/f ) st? \ Write register swap _eewrite or \ ( n1 t/f ) st? \ Write data swap _eewrite or \ ( t/f ) st? \ Stop I2C _eestop ; : test config Config1 RH6010 i2c_wr err? sls Config2 RH6010 i2c_wr err? begin Key RH6010 i2c_rd err? hex . cr d100 delms fkey? swap drop until ; { 0 RH6010 i2c_rd err? sc ST: 0000_00F0 0000_0000 0000_0000 ST: 0000_00F0 0000_0000 ST: 0000_0000 0000_00F0 ST: 0000_0000 0000_00F1 ST: 0000_0000 FFFF_FFFF ST: FFFF_FFFF ST: 0000_00FF FFFF_FFFF I2C error Prop0 Cog6 ok 2 RH6010 i2c_rd err? sc ST: 0000_00F0 0000_0002 0000_0000 ST: 0000_00F0 0000_0000 ST: 0000_0000 0000_00F0 ST: 0000_0000 0000_00F1 ST: 0000_0000 FFFF_FFFF ST: FFFF_FFFF ST: 0000_00FF FFFF_FFFF I2C error Prop0 Cog6 ok Prop0 Cog6 ok 0 0 RH6010 i2c_wr err? ST: 0000_0000 0000_0000 0000_0000 ST: 0000_0000 0000_0000 ST: 0000_0000 Prop0 Cog6 ok 0 1 RH6010 i2c_wr err? ST: 0000_0000 0000_0001 0000_0000 ST: 0000_0000 FFFF_FFFF ST: FFFF_FFFF I2C error Prop0 Cog6 ok }