I am using the Wire library to move some data from a shield to the Arduino.
The shield always puts out exactly 36 bytes (GPS Device) but the Arduino sees two data transfers that together add up to 36 bytes. Not always the same count in each of the transfers but always 36 bytes total. The setup() routine is re-run every time the data comes in.
Its as if the library is re-entering the Arduino application and screwing it royally.
The shield always puts out exactly 36 bytes (GPS Device) but the Arduino sees two data transfers that together add up to 36 bytes. I could not able to understand above sentence please elaborate briefly
It is not the shield or the arduino that has the problem. You need to understand how serial communications work.
there is a reason the GPS serial data has headers and message terminations.
each time the arduino executes it's loop() function, it reads the data which has already come in.
It is doing this process much faster than the data is actually arriving. It will empty the buffer faster
than the serial communication is filling it, and will end the loop() before the message completes.
The next loop() will get the rest of the data. This is not a malfunction, it is how reading serial ports
works. You need to organise your program to deal with it.
James-Brown:
The shield always puts out exactly 36 bytes (GPS Device) but the Arduino sees two data transfers that together add up to 36 bytes. Not always the same count in each of the transfers but always 36 bytes total.
Nick - You were spot on. There were actually two problems interacting.
The first causing the setup() routine to be re-entered was because one of my functions was running away with itself while building a String item. The string became so large that it blew up the application and somehow re-entered the setup().
The other problem, as you pointed out, was that my shield (my own design) always puts out 36 bytes but the buffer in the wire library is 32 bytes and was causing the problem. I have since switched the SoftwareSerial library and am using the shields UART for the job. Works fine.
You can modify a couple of constants in the Wire library to increase the buffer size if you have to. However as I recall each extra byte takes 5 as it makes 5 copies of the buffer.