I2C return 255 problem

josefvs

New Member
I'm trying to read serial data with a 20X2 set-up as an I2C slave, the master 28X2 reads the data when it is required. every 4-5 valid data sets I get 255 in place of the data. Does anybody knows why? Thanks


Slave Code:

#picaxe 20x2

init:
hi2csetup i2cslave, %10100000

main:


serin b.1,n9600,("#A"),b0,b1,b0,b2
'b0 is for the commas in the text string, #A is the qualifier
pause 50
put 0,b1,b2
pause 50
goto main

Master Code:

#picaxe 28x2

init:

hi2csetup i2cmaster, %10100000, i2cslow, i2cbyte


Read_Data:

hi2cin 0,(b0,b1)
pause 100
sertxd (#b0," ",#b1,13,10)

goto Read_Data
 

Buzby

Senior Member
I can't test it here, but I'm fairly sure your problem is due to serin being a 'blocking' command.

Just to test, try replacing the serin with a couple of incrementing bytes, and see if the problem goes away.
 

geoff07

Senior Member
It may be that (it may depend on the sparseness of the input stream), or simply the long (unnecessary?) time delays in the slave code. You could put the serin in an ISR and trigger the interrupt with the leading edge of the serial stream which the ISR then reads. The 'put' also goes in the ISR. Then the slave main program is no more than 'do:loop'. You could also use the same serial technique to send the data to the master. Or, the master could handle the serin and no need for the slave. As it is, the master won't know when there is new data so will likely read and report the same data over again looking for changes.
 

josefvs

New Member
Thanks, it seems to be the serin command, I need the I2C set up as the plan is connected multiple slaves such as GPS, compass and XBee and have the information taken by the main controller when needed.
 
Top