Shop OBEX P1 Docs P2 Docs Learn Events
Serial issue receiving binay data - lots of 0xFF bytes — Parallax Forums

Serial issue receiving binay data - lots of 0xFF bytes

Little-endianLittle-endian Posts: 91
edited 2014-11-04 20:54 in Propeller 1
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.
#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);
i-2w8wbzt-XL.jpg


This is using c = fdserial_rxCheck(xbee); Getting some random 0xFF within the valid frame.
i-Mptm4x6-L.jpg


Here's what the Saleae output looks like between the frames beginning with 0x72.
i-HCkFKG6-XL.jpg

Comments

  • Little-endianLittle-endian Posts: 91
    edited 2014-11-03 17:37
    Okay, it's my turn to make the walk of shame. After double checking everything, including the documentation I noticed both fdserial_rxChar and fdserial_rxTime return an int. I had originally started working with the example here in the tutorial here where c is defined as char:

    http://learn.parallax.com/propeller-c-simple-protocols/full-duplex-serial

    /*   XBee Loopback.c */  #include "simpletools.h" #include "fdserial.h"  fdserial *xbee;  int main() {   xbee = fdserial_open(9, 8, 0, 9600);    writeChar(xbee, CLS);   dprint(xbee, "Click this terminal, \n");   dprint(xbee, "and type on keybaord...\n\n");    char c;     while(1)   {     c = fdserial_rxChar(xbee);     if(c != -1)     {       dprint(xbee, "You typed: %c\n", c);     }   }   }
    

    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.
  • T ChapT Chap Posts: 4,223
    edited 2014-11-03 17:43
    It is very common to post something and then really quickly find the problem.
  • msrobotsmsrobots Posts: 3,709
    edited 2014-11-04 14:02
    usually rx_check returns -1 for no char available and 0-255 for a char if character was received.

    so you need int not char. to distinguish $FF from -1 (no char available)

    Enjoy!

    Mike
  • Little-endianLittle-endian Posts: 91
    edited 2014-11-04 20:54
    msrobots wrote: »
    so you need int not char. to distinguish $FF from -1 (no char available)

    Enjoy!

    Mike

    That explains it! Thanks!
Sign In or Register to comment.