Shop OBEX P1 Docs P2 Docs Learn Events
Help with receiving data in Spin — Parallax Forums

Help with receiving data in Spin

Don MDon M Posts: 1,653
edited 2012-04-25 07:01 in Propeller 1
I am building a sniffer that receives data in on 2 pins @ 9600 baud. It is a Master / Slave configuration whereby neither one talks at the same time. I am displaying the data on PST and also logging to an SD card.

Here is the Main loop:
  repeat
    if (term.rxcheck == "q")
      outa[SD_LED]~ 
      sd.pclose
      term.str(string("SD card file closed. Program stopped."))
      repeat
    d := mdbm.rx_time(1) 
    c := mdbs.rx_time(1)
    if(d <> -1)
       Get_Master(d)
    if(c <> -1)
       Get_Slave(c)

Here are the 2 methods called from the Main:
pub Get_Master(d) | i, num_bytes  
          
    buf[0] := d & $FF
    i := 1
    repeat
      d := mdbm.rx_time(1)
      if(d == -1) or (i => 36)
        quit
      buf[i] := d
      i++
    num_bytes := i  
    DispTime3
    term.str(string(" M: "))
    sd.pwrite(string("M:"),2)
    repeat i from 0 to num_bytes - 1
      term.hex(buf[i], 2)
      sd.pwrite(num.hex(buf[i],2),2)
      sd.pwrite(string(","),1)
      term.tx(" ")
    term.tx(13)

pub Get_Slave(c) | i, num_bytes        
              
    buf[0] := c & $FF
    i := 1
    repeat
      c := mdbs.rx_time(1)
      if(c == -1) or (i => 36)
        quit
      buf[i] := c
      i++
    num_bytes := i  
    DispTime3
    term.str(string(" S: "))
    sd.pwrite(string("S:"),2) 
    repeat i from 0 to num_bytes - 1
      term.hex(buf[i], 2)
      sd.pwrite(num.hex(buf[i],2),2)
      sd.pwrite(string(","),1)
      term.tx(" ")
    term.tx(13)

Here is what I see on PST:

PST 1.PNG


And here is what the Logic analyzer sees:

Polls.jpg


The PST display should look like this:

06:03:35: M: 0B 0B
06:03:35: S: 00
06:03:35: M: 12 12
06:03:35: S: 00
06:03:35: M: 33 33
06:03:35: S: 00

and so on.....

I am trying to get it to display on PST (and log to SD card) in the same order as seen on the Logic trace. I have tried using an IF statement in the loop to QUIT if the Slave is receiving data but that didn't work.

What am I doing wrong here?

Thanks.
Don
282 x 339 - 8K
1024 x 293 - 41K

Comments

  • Don MDon M Posts: 1,653
    edited 2012-04-25 07:01
    Hmmm... I found that commenting out the time stamp "DispTime3" will let it report as I am looking for. Then about every second or so I see it messes up a little and I'm guessing that is when the SD card is writing. So somehow I need to seperate these subroutines from one another so as not to affect the reading in of data. Any sugestions?
Sign In or Register to comment.