Shop OBEX P1 Docs P2 Docs Learn Events
Simple_Serial.spin Bug — Parallax Forums

Simple_Serial.spin Bug

hippyhippy Posts: 1,981
edited 2007-09-11 01:07 in Propeller 1
It took hours to locate, so I'd best save others the trouble ...
PUB rx | t, b

'' Receive a byte; blocks program until byte received

  if started and rxOkay
   b := 0                                              ' <=== ADD THIS
   dira[noparse][[/noparse]sin]~                                          ' make rx pin an input
    waitpeq(inverted & |< sin, |< sin, 0)               ' wait for start bit
    t := cnt + bitTime >> 1                             ' sync + 1/2 bit
      repeat 8
      waitcnt(t += bitTime)                             ' wait for middle of bit
      b := ina[noparse][[/noparse]sin] << 7 | b >> 1                       ' sample bit 
    waitcnt(t + bitTime)                                ' allow for stop bit 

    return (b ^ inverted) & $FF                         ' adjust for mode and strip off high bits


If the 'b:=0' isn't added, you'll get corrupt characters under some circumstances, but not all. I presume it depends on how the stack has been used before rx is called and that local variables are not initialised to zero. I'd also recommend adding a 'waitpne(inverted & |< sin, |< sin, 0)' before the waitpeq just to make sure the line has returned to idle before looing for the start bit.

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-09-11 00:05
    Yes that IS a bug! It says on p. 286/287 of the Manual:

    "All local variables ....are left uninitialized upon each call to the method."
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-09-11 01:07
    hmmm....I was having problems with Simple Serial giving me garbage and I thought it was because my code wasn't keeping up with the input data rate. I'll have to go back and revisit that.....

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


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
Sign In or Register to comment.