Pages: [1]   Go Down
Author Topic: Serial.write() fails on the number 3 (!)  (Read 709 times)
0 Members and 1 Guest are viewing this topic.
uk
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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:
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?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13478
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

MINDEL,MAXDEL not defined ...

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

Rob Tillaart

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

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

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

0
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try:

Code:
stty -F /dev/ttyUSB0 raw

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

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

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

Pages: [1]   Go Up
Jump to: