Pages: [1]   Go Down
Author Topic: Is Wire Library screwing up my app?  (Read 462 times)
0 Members and 1 Guest are viewing this topic.
Near San Diego
Offline Offline
Jr. Member
**
Karma: 1
Posts: 69
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Is this possible?
Logged

DELHI
Offline Offline
God Member
*****
Karma: 7
Posts: 741
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please mention The shield you are using.

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
Logged

AMPS

Offline Offline
Faraday Member
**
Karma: 61
Posts: 2890
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Faraday Member
**
Karma: 61
Posts: 2890
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Even if you are using some modified GPS protocol in which every message has the exact same number of bytes,
you still need to deal with it.

There are several different ways.

If you know always exactly how many bytes will arrive,   modify the code so you always wait for that
many characters.

Otherwise,  modify the code to that the parts of the message you are getting,  get put back together
into a complete message.
Logged

DELHI
Offline Offline
God Member
*****
Karma: 7
Posts: 741
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Its better you put code to check the mistake.I wanted to know what is ur expected result @ end of program

I refer put delay in you program before  new data is arrived
@ end of your program clear buffer , Once you ensure that you got proper data.
« Last Edit: January 16, 2013, 01:50:01 am by AMPS-N » Logged

AMPS

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

See this about I2C: http://gammon.com.au/i2c

Mentioned there is that the Wire library has a buffer size of 32 bytes.

Perhaps post your code if you have more questions.
Logged

Near San Diego
Offline Offline
Jr. Member
**
Karma: 1
Posts: 69
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Thanks again
Regards......... Jim
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: