Go Down

Topic: SoftwareSerial - Can not send 0x00 (Read 956 times) previous topic - next topic

maomao

Hi, sorry if it's a stupid question but I try to send a synchronisation pattern (0x55 0x55 0x00 0x00 0xFF) to one of my board via the SoftwareSerial library (arduino v1.0.3).

I use these lines:
mySerial.write(0x55);
mySerial.write(0x55);
mySerial.write(0x00);
mySerial.write(0x00);
mySerial.write(0x00);
mySerial.write(0xFF);

At the first "mySerial.write(0x00);" I got this error: call of overloaded 'write(int)' is ambiguous

Can somebody help?

Thx

Coding Badly


Code: [Select]
mySerial.write( (uint8_t) 0x00 );

...or...

Code: [Select]
mySerial.write( (byte) 0x00 );

If you're feeling especially verbose...

Code: [Select]
const uint8_t ZeroByte = 0x00;
mySerial.write( ZeroByte );


michinyon

Why is this only a problem for the 0x00 ,  and not a problem for the 0x55  ?

And wouldn't it be easier to put this sequence into some kind of string or array or even a loop,  rather
than waste code space with 5 calls to the same function ?

maomao

Thx Coding Badly, it's working perfectly now.

CrossRoads

Yes, why do 0x55 & 0xFF get interpreted as bytes, while 0x00 gets interpreted as an int?

creating a variable:
const byte ZeroByte = 0;

and then using that seems simple enough:

mySerial.write(0x55);
mySerial.write(0x55);
mySerial.write(ZeroByte);
mySerial.write(ZeroByte);
mySerial.write(ZeroByte);
mySerial.write(0xFF);



Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Coding Badly

Why is this only a problem for the 0x00 ,  and not a problem for the 0x55  ?


http://arduino.cc/forum/index.php?topic=97460.0

Quote
And wouldn't it be easier to put this sequence into some kind of string or array or even a loop,  rather than waste code space with 5 calls to the same function ?


It's only a "waste" if the amount of Flash available is approaching or has surpassed zero.

Coding Badly

Yes, why do 0x55 & 0xFF get interpreted as bytes, while 0x00 gets interpreted as an int?


See the link above.

Quote
creating a variable ... const byte ZeroByte = 0; ... and then using that seems simple enough:


I like it more than the typecast.

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

PeterH


Can somebody help?


It would IMO be cleaner, as well as resolving your problem, to put the byte sequence into a const byte array and make one call to Serial.write() to send the array.
I only provide help via the forum - please do not contact me for private consultancy.

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