chipKIT® Development Platform

Inspired by Arduino™

I2C Slave Receive Problems

Created Sat, 12 Nov 2011 16:27:00 +0000 by photomankc


photomankc

Sat, 12 Nov 2011 16:27:00 +0000

Ok I found what was driving me nuts last night and why my Arduino code will not run correctly on the Uno32. The Wire library calls my Recieve interrupt handler for each individual byte rather than interrupting once all the bytes are recieved. That was causing the buffer index to be reset to zero each byte since the index was a local variable. That also causes my code to see the first byte that comes in as a command, which it is, but none of the followup data has been recieved yet so it goes and executes the command without the needed data that has not arrived yet.

My code is acting as a slave so it can't know ahead of time how many bytes it will be getting. So.... how do I tell when the master has finished transmitting all the bytes and it is now safe to examine the my command buffer? I can move the variables that index my buffer up to globals but the way this works I can't see how I would know that the master has finished sending data.

I suppose my command testing switch could be forced to also check the buffer index each time through the loop and only execute when it is in the right position butI was hoping there is something less.... inelegent...to notice that the I2C trasmission is done.

Does anyone know why the rx buffer is not being used in the library? Why interrupt for each byte rather than bring them all to the buffer thats declared in and interrupt when the i2c STOP condition indicates all the bytes have been obtained?


avenue33

Sat, 26 Jan 2013 23:34:40 +0000

Please refer to this thread :arrow: Wire onReceive(handler) issue.