Serial issue receiving binay data - lots of 0xFF bytes
Little-endian
Posts: 91
I'm using using the code below to receive binary serial data from a device sending at 19,200, 8bit, 1 stop, 1 start bit.The device has a pullup to 3.6v and I'm using a 220ohm resistor between it and the Prop.
It's working and the data I'm receiving is valid. Each frame starts with 0x72 and they are 10 bytes long. When I receive the data using fdserial_rxCheck it appears it's even capturing a spurious 0xFF within the frame. This is my first time using the the Prop to receive serial data and I just wanted to confirm I should be receiving 0xFF bytes while the line is pulled up and eight bits ticks by w/o a stop or start bit? Maybe I'm supposed to, just not sure as I've never done this before. It appears the spurious 0xFF bytes are eliminated when using fdserial_rxTime. I was hoping I could use the time between the frames when no bytes are waiting to determine when a frame started/stopped as well as parsing and processing the data in the frame.
Any help would be appreciated.
This is using c = fdserial_rxTime(xbee, 1);
This is using c = fdserial_rxCheck(xbee); Getting some random 0xFF within the valid frame.
Here's what the Saleae output looks like between the frames beginning with 0x72.
It's working and the data I'm receiving is valid. Each frame starts with 0x72 and they are 10 bytes long. When I receive the data using fdserial_rxCheck it appears it's even capturing a spurious 0xFF within the frame. This is my first time using the the Prop to receive serial data and I just wanted to confirm I should be receiving 0xFF bytes while the line is pulled up and eight bits ticks by w/o a stop or start bit? Maybe I'm supposed to, just not sure as I've never done this before. It appears the spurious 0xFF bytes are eliminated when using fdserial_rxTime. I was hoping I could use the time between the frames when no bytes are waiting to determine when a frame started/stopped as well as parsing and processing the data in the frame.
Any help would be appreciated.
#include "simpletools.h" #include "fdserial.h" fdserial *xbee; fdserial *term; int main() { xbee = fdserial_open(9, 8, 0, 19200); term = fdserial_open(31, 30, 0, 115200); simpleterm_close(); char c; fdserial_rxFlush(xbee); while (fdserial_rxReady) { c = fdserial_rxCheck(xbee); //c = fdserial_rxTime(xbee, 1); if (c != -1) { dprint(term, "%x ", c); } } }
This is using c = fdserial_rxTime(xbee, 1);
This is using c = fdserial_rxCheck(xbee); Getting some random 0xFF within the valid frame.
Here's what the Saleae output looks like between the frames beginning with 0x72.
Comments
http://learn.parallax.com/propeller-c-simple-protocols/full-duplex-serial
In the next example further down on the page c is defined as int.
All I needed to do to resolve this is change c from char to int in my example above. Not sure I completely understand why char does not work since it's defined as a one byte.
so you need int not char. to distinguish $FF from -1 (no char available)
Enjoy!
Mike
That explains it! Thanks!