Can't read Simple Serial fast enough using SPIN
I posted this in the middle of another thread, but the thread seems to be dead and I guess I didn't get to the root of my problem.· I'm trying to read bytes into a buffer at 9600 baud using Simple_Serial and SPIN.· The device I'm working with is a Rogue Robotics uMP3 player.· When you send it "V", it returns with a version code (approx 15 characters) and ends up with a ">" (prompt).· My code reads until it gets the prompt.·
It works with FullDuplexSerial but not with Simple Serial (I get garbage after the first 2-3 characters).· I am pretty sure I'm not reading it fast enough and falling out of sync, based on the garbage that I got.· For instance, the first byte that is wrong is $97 instead of $2E, which is 1 bit off if you count the·stop bit.· I've read that Simple Serial can work up to 19.2K baud and I'm only using 9600 baud and I can't seem to keep up in SPIN.· Is there a better way to code this?
I don't want to use FullDuplexSerial (or assembly) because I'm short on cogs.·Here's my code:
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
· tx_pin = 0
· rx_pin = 1
· baud = 9600
· prompt = $3E
· CR = $0D
VAR
· byte inbuf[noparse][[/noparse]255]
OBJ
· serial_u· :·· "simple_serial"
· tv_text : "tv_text"
··
PUB start | c , i
· serial_u.start(rx_pin, tx_pin, baud)
· tv_text.start(12)
· i := 0
· serial_u.str(@version)
· repeat
· until (inbuf[noparse][[/noparse]i++] := serial_u.rx) == prompt
· inbuf[noparse][[/noparse]i-1] := 0 ' <-- remove prompt and delimit string.
· tv_text.str(@inbuf)
DAT
······· version········ byte··· "V", CR, 0
Thanks!
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
It works with FullDuplexSerial but not with Simple Serial (I get garbage after the first 2-3 characters).· I am pretty sure I'm not reading it fast enough and falling out of sync, based on the garbage that I got.· For instance, the first byte that is wrong is $97 instead of $2E, which is 1 bit off if you count the·stop bit.· I've read that Simple Serial can work up to 19.2K baud and I'm only using 9600 baud and I can't seem to keep up in SPIN.· Is there a better way to code this?
I don't want to use FullDuplexSerial (or assembly) because I'm short on cogs.·Here's my code:
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
· tx_pin = 0
· rx_pin = 1
· baud = 9600
· prompt = $3E
· CR = $0D
VAR
· byte inbuf[noparse][[/noparse]255]
OBJ
· serial_u· :·· "simple_serial"
· tv_text : "tv_text"
··
PUB start | c , i
· serial_u.start(rx_pin, tx_pin, baud)
· tv_text.start(12)
· i := 0
· serial_u.str(@version)
· repeat
· until (inbuf[noparse][[/noparse]i++] := serial_u.rx) == prompt
· inbuf[noparse][[/noparse]i-1] := 0 ' <-- remove prompt and delimit string.
· tv_text.str(@inbuf)
DAT
······· version········ byte··· "V", CR, 0
Thanks!
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
Comments
Can you instruct your sender to send two stopbits? This should help.
A little codeoptimizsation can also help, i.e.
I tried your code, but I didn't get anything, not even garbage.· I tried the following and at least I get garbage again.
· i := @inbuf -1
· serial_u.str(@version)
· repeat
··· byte[noparse][[/noparse]++i] := serial_u.rx
· until byte[noparse][[/noparse]i] == prompt
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
I created a new Simple_Serial object and called it "Shaved_Simple_Serial"
That seemed to be enough to allow it to keep up!· Still have some testing to do, but so far so good.
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
However this stays a little bit mysterious...
Without any other information, I would say, you are not running at 80 MHz but at 40....
There is another remote possibility: In the old days of real teletype machines, it was possible to use 1, 2 or 1.5 (!) stop bits, as this was also used to tune to the speed of the printing mechanism. 0.5 stop bits were never in use but are possible, especially when generating the bitstream by software only.
BTW: This looks as if it would be a good opportunity to check out the fabulous ViewPort tool
Post Edited (deSilva) : 8/24/2007 10:57:34 AM GMT
I wish could adjust the stop bit on the mp3, but the only thing it allows me to change is the baud from 9600 to 19.2K, 38.4K, 57.6K, 115.2K. 9600 is the default.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?