Go Down

Topic: Serial.write() fails on the number 3 (!) (Read 827 times) previous topic - next topic

Hi,

I am pretty sure I've found a serious bug in the Serial library - for some reason it writes some numbers but not others. In particular, whenever you try to write the number 3, nothing is sent, but other numbers like 0,1,2, and 4 get sent ok. hex 13 is also sent ok, so it's not just down to certain bits being set. I know this is bizarre but I have done a pretty conclusive test and it looks like this is what's happening.

This code works (prints alternating 0x04's and 0x83's):

Code: [Select]

void setup() {
 Serial.begin(19200);
}

void loop() {
 unsigned int valOut;  // print out the results from a strike
 unsigned char cOut;
 cOut=0x04;
 Serial.write(cOut);
 cOut=0x83;
 Serial.write(cOut);
 delay(random(MINDEL,MAXDEL));
}


But this doesn't:

Code: [Select]

void setup() {
 Serial.begin(19200);
}

void loop() {
 unsigned int valOut;  // print out the results from a strike
 unsigned char cOut;
 cOut=0x03;
 Serial.write(cOut);
 cOut=0x83;
 Serial.write(cOut);
 delay(random(MINDEL,MAXDEL));
}


It just prints a series of 83 characters with no 03's at all:

Code: [Select]

00000000  83 83 83 83 83 83 83 83  83 83 83 83 83 83 83 83  |................|
00000010  83 83 83 83 83 83 83 83  83 83 83 83 83 83 83 83  |................|
00000020  83 83 83 83 83 83 83 83  83 83 83 83 83 83 83 83  |................|
00000030  83 83 83 83 83 83 83 83  83 83 83 83 83 83 83 83  |................|


I'm using arduino version 0022. Could someone verify this on another board and post here so I know my arduino isn't at fault?

robtillaart

MINDEL,MAXDEL not defined ...

which program do you use to capture the serial stream on the PC ?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

The MINDEL MAXDEL bit was my cut and paste error in copying the code. They are both defined as 250.

I got a reply in my original thread pointing out that 0x03 is ctrl-C, so the problem may be caused by the way the serial port is set up, not the arduino library. Sorry about this.

My stty settings are:

Code: [Select]

andy@monkey:~/Desktop/projects/drum/software/midimapper$ stty -aF /dev/ttyUSB0
speed 19200 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^A; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk inpck -istrip -inlcr -igncr icrnl -ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig -icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke


If anyone knows how they should be set for sending raw data, that would be a help; otherwise I'll do some research and try to work through it myself.

andy

RuggedCircuits

Try:

Code: [Select]
stty -F /dev/ttyUSB0 raw

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

Thanks - I just tried this and it's working fine. Sorry for the false alarm!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy