Pages: [1]   Go Down
Author Topic: Serial.print(0x00, BYTE) has very strange behavior  (Read 1685 times)
0 Members and 1 Guest are viewing this topic.
Lille - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
God Member
*****
Karma: 1
Posts: 588
LumiNet rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tested with this code:
Code:
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?
« Last Edit: March 09, 2009, 02:00:29 pm by bohne » Logged


Lille - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?

Logged

0
Offline Offline
God Member
*****
Karma: 1
Posts: 588
LumiNet rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Lille - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
God Member
*****
Karma: 1
Posts: 588
LumiNet rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Lille - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: