Pages: [1]   Go Down
Author Topic: Bug in serial lib? Can't read without writing...  (Read 544 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using the serial functions provided by wiring_serial.c in the 0008 arduino core release.
I have an Arduino NG (ATmega168). I just discovered that I can't read anything from the serialport if I don't also write something to it.
The loop below only works when I uncomment the serialWrite() call! When commented out (no writing), it's like the serialport receives nothing, not even the rx led on the arduino blinks... Is this a bug in wiring_serial.c?

Code:
   for (;;) {
        // serialWrite(0xFF);
        digitalWrite(13,HIGH);
        delay(100);
        if(running) digitalWrite(13,LOW);
        delay(100);
        if(serialAvailable()) {
            unsigned char c;
            switch(c = serialRead()) {
                case 0x10:
                    running = 1;
                break;
                case 0x11:
                    running = 0;
                break;
            }
        }
    }
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What are you using to send data to the board?

Also, the serialRead() and serialAvailable() functions are deprecated in favor of Serial.read() and Serial.available(), so they don't really get tested.  Can you use the latter functions instead?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What are you using to send data to the board?

Also, the serialRead() and serialAvailable() functions are deprecated in favor of Serial.read() and Serial.available(), so they don't really get tested.  Can you use the latter functions instead?

I'm using my linux box to send serial data over USB.
I see that HardwareSerial.cpp simply wraps serialRead(), serialAvailable() and the other funcs directly, so there's no difference using Serial.read() instead of serialRead()... (Since I write everything else in C I don't want to use the C++ Serial object)

Isn't it strange that the RX led don't even light up when I send to the arduino and the arduino isn't sending anything? Should this led light up even if the arduino isn't actually handling the data? If so, the problem must be that my computer doesn't send anything unless it recieved something...
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It was my code on the computer-side that was the problem, glib's IOChannels use a lot of buffering, so the bytes wasn't actually sent to the arduino. A call to g_io_channel_flush() did the trick... Yes, I'm probably too tired and should get some sleep. smiley
Logged

Pages: [1]   Go Up
Jump to: