Go Down

Topic: Serial.print(0x00, BYTE) has very strange behavior (Read 1 time) previous topic - next topic

enzo

Hi

I have a strange thing, I get no problem with the code:
-------------------
void c328r_init(void)
{
 Serial.begin(9600);
 do
 {
   // Send SYNC sequence
   Serial.print(0xAA, BYTE);
   Serial.print(0x0D, BYTE);
   Serial.print(0xAA, BYTE);
   Serial.print(0xAA, BYTE);
   Serial.print(0xAA, BYTE);
   Serial.print(0xAA, BYTE);
   delay(1000);
 } while(!c328r_look_for_ack());
}

int ledpin = 13;  

void setup(void)
{
 delay(10000);
 c328r_init();
 digitalWrite(ledpin, HIGH);  
}

void loop(void)
{
}
----------------
With the above code, i can read AA 0D AA AA AA AA if i use gtkterm

HOWEVER if i modify the code to :
-------------------
void c328r_init(void)
{
 Serial.begin(9600);
 do
 {
   // Send SYNC sequence
   Serial.print(0xAA, BYTE);
   Serial.print(0x0D, BYTE);
   Serial.print(0x00, BYTE);
   Serial.print(0x00, BYTE);
   Serial.print(0x00, BYTE);
   Serial.print(0x00, BYTE);
   delay(1000);
 } while(!c328r_look_for_ack());
}

int ledpin = 13;  

void setup(void)
{
 delay(10000);
 c328r_init();
 digitalWrite(ledpin, HIGH);  
}

void loop(void)
{
}
----------------
Well with the above code, I get for example (with gtkterm):
AA 0D 00 0A 00 00
AA 0D 00 00 5D 3E
AA 0D 00 0A 00 00
AA 0D 00 0A C0 D8

=> in a conclusion, the first hexa are good (AA, 0D, 00) but not the other 3

one would say that after the first print(0x00, BYTE), next print(0x00, BYTE) are completely crapy...

Bug ?
Please let me now, i really think this is a bug in software...

bohne

#1
Mar 09, 2009, 07:58 pm Last Edit: Mar 09, 2009, 08:00 pm by bohne Reason: 1
I tested with this code:
Code: [Select]

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

void loop()
{
  Serial.print(0xAA, BYTE);
  Serial.print(0x0D, BYTE);
  Serial.print(0x00, BYTE);
  Serial.print(0x00, BYTE);
  Serial.print(0x00, BYTE);
  Serial.print(0x00, BYTE);
  delay(1000);
}


And I started hterm (on windows) and read the values in this order:
AA 0D 00 00 00 00

so no problem on windows and Diecimila. I would say that this is not a bug in the Arduino core.

Oh and I have these settings for my FTDI driver:
USB packetsize: 512 bytes
BM delay: 16ms
maybe your usb driver produces the errors because of bad usb timing?
http://www.dorkbot.de
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236434254
http://www.luminet.cc

enzo

Well i do the same sketch, and the \x00 is random again...
I don't know where to set the FTDI driver settings you're talking about bohne, where are they ?

I'm on Linux, I use gtkterm as serial terminal

With Duemilanove with ATmega 328

I really don't see where this problem comes from !

Someone with this config could do this test to check ?


bohne

just search for the FTDI Application Notes. The ones that explain the driver settings for Windows are:

Application Note AN_107 Advanced Driver Options
or the older version:
AN232B-10 Advanced Driver Options

and some more information can be found in this document:
AN232B-04 Data Throughput, Latency and Handshaking

So on windows you can change these settings and it really improves communication (on low baud rates) with the Arduino.

If you find a way to change these parameters on Linux then please let me know.
http://www.dorkbot.de
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236434254
http://www.luminet.cc

enzo

Thanks

However, after discovering the impressive tool hterm, I had no problem, \x00 are correctly sent, and my device has well responded

Thanks for making me discover hterm !
really a great tool as it works also on Linux

bohne

hterm is great, indeed.

So your terminal program was the only problem?
Did you try other terminal applications and had the same problems that you have with gtkterm?
http://www.dorkbot.de
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236434254
http://www.luminet.cc

enzo

Yes the terminal was only involved in the bug

I've tried my code on windows, it was ok with hterm, and it was also ok on linux using hterm again

I haven't tried another serial terminal

Thanks for your help bohne !

Go Up