I'm trying to use a 20X2 as a i2c slave. I also would like the 20X2 to execute serout and serin commands. The i2c master is an arduino uno. I can get the arduino to read in 2 bytes from the scratchpad ok when the 20X2 is not trying to read the serial port but as soon as the serial port is active I cant read the i2c data. The manual indicates a potential internal interrupts conflict. So to try and get around the issue I get the arduino to set an enable input on the 20X2. Whenever the enable is high the serin and serout commands are never called. No success. I was wondering if anyone has struck this issue before and have been able to successfully run a 20X2 as an i2c slave as well as have it execute serout and serin commands. My 20X2 slave code is attached. David
'20X2 Slave to Arduino interface
'xbee rx feeds signal to 20X2 pinc.7 then arduino reads 4 bytes of tempersture data from scratchpad
#picaxe 20x2
#no_data
dirsC=%10001111 'c.7 output to xbee, c.6=input from xbee rx, c.4 input from arduino/mcp23017
dirsB=%11111111
pullup ON
setfreq m16 'need m16 to make i2c slave work at i2c 400khz
hi2csetup i2cslave, 0xA0 'initialise 20x2 i2c slave operation
pinc.7 = 1 'see picaxe serout T2400 recommendation
pause 20
w8 = 0 'program counter
for b23 = 0 to 15 'initialise xbee link, send a few serout's, populate w2,w1 temperature registers
gosub poll_sensors
pause 2000
next b23
'----------------------------------------------
main:
if pinc.4 = 1 then :goto main :endif 'dont poll sensors if pinc.4 high
if w8 = 9200 then :gosub poll_sensors :w8 = 0 :endif 'poll ~ every 30 secs
w8 = w8+1 'inc program counter
goto main
'----------------------------------------------
poll_sensors:
serout c.7, T2400_16,("RP") 'poll remote temperature sensor
serin [200,jump], c.6,T2400_16,("RQ"),b5,b4,b3,b2 'look for 4 return bytes from remote
put 1,b5 'store in 20X2 scratchpad ready for arduino i2c master read
put 2,b4
put 3,b3
put 4,b2
jump:
return
'20X2 Slave to Arduino interface
'xbee rx feeds signal to 20X2 pinc.7 then arduino reads 4 bytes of tempersture data from scratchpad
#picaxe 20x2
#no_data
dirsC=%10001111 'c.7 output to xbee, c.6=input from xbee rx, c.4 input from arduino/mcp23017
dirsB=%11111111
pullup ON
setfreq m16 'need m16 to make i2c slave work at i2c 400khz
hi2csetup i2cslave, 0xA0 'initialise 20x2 i2c slave operation
pinc.7 = 1 'see picaxe serout T2400 recommendation
pause 20
w8 = 0 'program counter
for b23 = 0 to 15 'initialise xbee link, send a few serout's, populate w2,w1 temperature registers
gosub poll_sensors
pause 2000
next b23
'----------------------------------------------
main:
if pinc.4 = 1 then :goto main :endif 'dont poll sensors if pinc.4 high
if w8 = 9200 then :gosub poll_sensors :w8 = 0 :endif 'poll ~ every 30 secs
w8 = w8+1 'inc program counter
goto main
'----------------------------------------------
poll_sensors:
serout c.7, T2400_16,("RP") 'poll remote temperature sensor
serin [200,jump], c.6,T2400_16,("RQ"),b5,b4,b3,b2 'look for 4 return bytes from remote
put 1,b5 'store in 20X2 scratchpad ready for arduino i2c master read
put 2,b4
put 3,b3
put 4,b2
jump:
return
Attachments
-
1.2 KB Views: 1