gcross2

I am dealing with a puzzling issue in my Arduino code, perhaps you can help. The setup is as follows:

I have an Arduino Uno communicating over Serial to a console program on OSX written using termios. For reference, the OSX application uses posix file descriptors and grand central dispatch to perform reads, though neither of these appears to be at fault. The baud rate is set at 460800 - lowering it has no effect on the problem.

The two devices use a packet structure to communicate over serial. Writes on the Arduino side are executed by taking data out of a buffer and writing it using Serial.write, like so:

Serial.write(PREAMBLE);//PREAMBLE Is a constant that identifies new data

for (uint8_t i=0; i < BUFFER_SIZE; i++) {Serial.write(buffer[i]);}

During setup(), three packets are transmitted and are received without issue on the terminal. Once loop() has started, the terminal sends a packet to the device, which is received in a manner similar to:

void loop(){if (Serial.available()){//do Serial.read() until we detect the end of the packet (~10 bytes in this case), then stop//write a response here}}

I should note that Serial.read() is only called until the end of the meaningful data is received, NOT until Serial.available() is false. The response is written in the form described above. serialEvent() is not used in this program.

The issue arises when the response is written - specifically the arduino stalls completely. I have managed to figure out (using LEDs) that the lock up takes place in HardwareSerial.cpp on line 390:

gcross2

Sorry for the delayed reply, I've been having some computer difficulties. Apparently the FTDI serial to USB driver for the older Arduinos cause OSX 10.8 to fail at boot. That problem is unrelated to this one, however.

The code is spread across multiple files, so I shortened it while asking the question.

In any case, the error was in the Arduino code. Turns out I was using Arduino 1.0.1. The bug, which has been presented in the blog posting I linked, was fixed in 1.0.3. My bad for not checking for updates.