Shop OBEX P1 Docs P2 Docs Learn Events
Trying to sniff and display data. Need some help with code. — Parallax Forums

Trying to sniff and display data. Need some help with code.

Don MDon M Posts: 1,653
edited 2012-08-13 14:28 in Propeller 1
I am sniffing a 9600 baud buss. I'm having trouble getting the data to display correctly.

Here's my code:
 repeat
    
   d := mdbm.rx_time(2)
   if(d <> -1)                                          ' anything from Master?
      bufm[0] := d & $0_FF                              ' strip off address bit
      i := 1                                            ' set index counter to 1
      repeat                                            ' if data present repeat until
        d := mdbm.rx_time(2)                            ' no data present or until 36 bytes received
        if(d == -1) or (i => 36)                        ' exit repeat
          quit                                          ' store data in bufm indexed by i
        bufm[i] := d                                    ' increment index i
        i++                                             ' assign i to num_bytes
      num_bytes := i                                    ' print M" on PST
      term.str(string(" M: "))                          ' print data on PST from bufm
      repeat i from 0 to num_bytes - 1
        term.hex(bufm[i], 2)
        term.tx(" ")
      term.tx(13)

And here's a screen shot from the Logic Analyzer:

Polls 2A.jpg


You can see there is quite a delay once the data quits and the data is printed to PST.

I have tried changing mdbm.rx_time from (1) to (2) ms and with 1 ms it prints each individual byte on each line like this:

PST 2B.PNG


Changing it to (2) ms prints the 2 bytes together on the line like I want but sometimes it misses a beat and prints either 1 or 3 bytes.

PST 2A.PNG


I think my problem is with the code determining when the data quits coming into the buffer but I don't know how to solve it.

Maybe I need to do this a different way? Looking for any help or suggestions. I'll be adding a second receive line that responds to this and try to get it to line up and print correctly.

Sorry if I'm not explaining myself well here.

Thanks.
Don
1024 x 121 - 24K
810 x 632 - 20K
606 x 621 - 22K

Comments

  • Don MDon M Posts: 1,653
    edited 2012-07-02 19:30
    I should mention that each byte at 9600 baud takes just a tad over 1 ms for each byte according to the Logic trace.

    The rx_time(x) method waits x ms for data and returns a -1 if no data.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-07-02 21:01
    Does the data use some sort of beginning or end of message marker?

    My guess is you'd be better off just using rxcheck instead of rx_time and use a separate cog to monitor for idle times (unless you can use a beginning or ending marker).

    Edit: This might be easy to do from the PASM part of the driver. You could start a timer after each stop bit and indicate to the parent object when a delay above a set amount of time occurs.

    Which serial driver are you using?
  • Don MDon M Posts: 1,653
    edited 2012-07-03 08:03
    The serial driver is similar to FDS modified for 9 bit data. It works the same way as FDS.

    The problem is that the commands vary in length and different manufacturers of "Masters" send the data at different intervals so timing becomes an issue.

    After some thought here I think I'm going to go a different route. I'm going to look at using one cog to collect the data using case statements to define the length of the data collection since they are known and defined. Then use a main cog to display the data that was stored in the buffers.
  • JonnyMacJonnyMac Posts: 9,194
    edited 2012-07-04 11:31
    The problem is that the commands vary in length and different manufacturers of "Masters" send the data at different intervals so timing becomes an issue.

    For asynchronous serial communications to work both the sender and receiver need to agree on the bit rate and the number of bits in a word. You may need a "smart" logic analyzer to watch your data and interpret it.
  • Don MDon M Posts: 1,653
    edited 2012-08-13 14:20
    Duane Degn wrote: »
    My guess is you'd be better off just using rxcheck instead of rx_time and use a separate cog to monitor for idle times (unless you can use a beginning or ending marker).

    Edit: This might be easy to do from the PASM part of the driver. You could start a timer after each stop bit and indicate to the parent object when a delay above a set amount of time occurs.

    Duane- I tried using rx_check method and I will only get 1 byte at a time. I have been working with this off and on for a while and it seems to me that the only difference between rx_check and rx_time is how long after the data starts that it waits to see if there is more. There is a 1.6ms gap between the end of the last byte from the first command and the first byte of the second command. It seems to me that the rx_time method is not accurate enough or there is some other overhead that gets in the way.

    I don't know what to do at this point and really need some help with this.

    Don
  • Don MDon M Posts: 1,653
    edited 2012-08-13 14:28
    The time area between the green markers is where I'm trying to get it to quit the repeat loop.



    Poll timing.jpg
    1024 x 277 - 43K
Sign In or Register to comment.