Shop OBEX P1 Docs P2 Docs Learn Events
Can't read Simple Serial fast enough using SPIN — Parallax Forums

Can't read Simple Serial fast enough using SPIN

Ken PetersonKen Peterson Posts: 806
edited 2007-08-24 09:56 in Propeller 1
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?

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-08-23 18:41
    The bitcell length with 9600 baud is around 100 us, about 20 us is already used inside RX . As you use quite complex code for each character you get near this limit!

    Can you instruct your sender to send two stopbits? This should help.
    A little codeoptimizsation can also help, i.e.
    inbufp := @inbuf
    repeat
       x := rx
       byte[noparse][[/noparse]inbufp++] := x
     until x == prompt
    
    
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-08-23 21:28
    Hmmmm....

    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?
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-08-23 21:32
    Oh, by the way:· Nope, I cannot change the UART settings on the sender other than increase baud rate shakehead.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-08-23 22:12
    OK....got it working!· hop.gif

    I created a new Simple_Serial object and called it "Shaved_Simple_Serial" smilewinkgrin.gif·· I eliminated some extra code from the rx loop that I didn't need such as error checking, shared pin, and bit inversion.

    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?
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-24 06:34
    Congrat!
    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 smile.gif

    Post Edited (deSilva) : 8/24/2007 10:57:34 AM GMT
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-08-24 09:56
    Thanks for your help, deSilva. I did double check the clock and it's 16x. I'm using a demo board, so unless they put the wrong crystal on it, I should be at 80 MHz. I have been thinking of trying the ViewPort because it looks so cool! Hopefully it doesn't require that I install anyting, otherwise...well, our IT guys are kinda shy about that stuff. I had to beg and plead to get them to install the Prop Tool.

    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?
Sign In or Register to comment.