Question about FullDuplexSerial (from obex by Chip Gracey, Jeff Martin)
Hi guys,
At the risk of looking stupid
. I'm have a little problem with a chunk of code.
. Any ideas what I'm doing wrong?
At the risk of looking stupid
repeat 6
outa[16]~~
outa[16]~
repeat until tmp1 >= $00
outa[3]~~
outa[3]~
repeat
waitcnt(cnt + clkfreq / 10000)
until ser.rxcount > 0
tmp1 := ser.rx
Buff[tmp0] := tmp1
tmp0++
I can't seem to hold the program in the inner most loop " repeat until ser.rxcount > 0" It doesn't seem to matter how I code it. the program will jump the loop after 1mS. Even with out the waitcnt it still jumps ship :frown:. I'm trying to wait for a 6 byte serial stream, that is on a 50mS interval. If I could just sync to this serial packet, I would have a bunch of time for other fun stuff
Comments
Also, you're using tmp1 >= $00 which isn't a comparison (greater or equal). In SPIN that's an assignment (like +=). You want tmp1 => $00.
PUB rxcount : count '' Check for bytes in receivebuffer (never waits) '' returns the number of bytes count := (rx_head - rx_tail) & 15 if count == 0 count := -1CON _clkmode = XTAL1|PLL16X _xinfreq = 5_000_000 OBJ serial: "FullDuplexSerial" VAR byte Buff[32] PUB null | tmp0, tmp1 serial.start(31, 30, %0000, 115200) dira[16]~~ dira[17]~~ tmp0~ repeat 6 outa[16]~~ outa[16]~ repeat outa[17]~~ outa[17]~ waitcnt(cnt + clkfreq / 10000) until (tmp1 := serial.rxcheck) <> -1 Buff[tmp0++] := tmp1 repeat tmp0 from 0 to 5 serial.tx(Buff[tmp0]) DATThis demo stays in the inner loop until it gets a character then breaks out, stores it and repeats. After having collected 6 characters it sends them back through the serial link. HTHThanks
For the sake of it I added an rxcount method and ran this test
repeat !outa[16] waitcnt(cnt + clkfreq / 10) until serial.rxcount > 0Which stays in that loop until I press a key.Does your serial link work otherwise, i.e. do you get what you expect from normal interactions with a terminal?
thanks Kuroneko