Help with receiving data in Spin
Don M
Posts: 1,653
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:
Here are the 2 methods called from the Main:
Here is what I see on PST:
And here is what the Logic analyzer sees:
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
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:
And here is what the Logic analyzer sees:
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
Comments