Help with converting SEROUT to propeller
I am working on a min-sumo project and am converting it chip from the BS2 to the Propeller. On the BS2 powered version, I ran the motors with a simple serout command: SEROUT 1, 84, [2, 127] where the pin is 1, the baud is 84, and two data values are transmitted. I have tried to convert this with both he BS2_FUNCTIONS object and the Full_Duplex_Serial object and have not been able to run the motors with the propeller. Any help would be appreciated!
Comments
'' ================================================================================================= '' '' File....... '' Purpose.... '' Author..... '' E-mail..... '' Started.... '' Updated.... '' '' ================================================================================================= con { timing } _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' use 5MHz crystal CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq ' system freq as a constant MS_001 = CLK_FREQ / 1_000 ' ticks in 1ms US_001 = CLK_FREQ / 1_000_000 ' ticks in 1us BAUD = CLK_FREQ / 9600 con { io pins } RX1 = 31 ' programming / terminal TX1 = 30 SDA = 29 ' eeprom / i2c SCL = 28 MCTRL = 0 obj var pub main high(MCTRL) ' set to idle state repeat waitcnt(0) pub update_motors(speed1, speed2) serout(speed1) serout(speed2) pub serout(b) | t '' TX single byte '' -- driven/true mode b := (b | $100) << 2 ' add start and stop bits t := cnt repeat 10 waitcnt(t += BAUD) ' hold for bit timing outa[MCTRL] := (b >>= 1) ' output the bit con { ------------- } { B A S I C S } { ------------- } pub pause(ms) | t '' Delay program in milliseconds if (ms < 1) ' delay must be > 0 return else t := cnt - 1776 ' sync with system counter repeat ms ' run delay waitcnt(t += MS_001) pub high(pin) '' Makes pin output and high outa[pin] := 1 dira[pin] := 1 pub low(pin) '' Makes pin output and low outa[pin] := 0 dira[pin] := 1 pub toggle(pin) '' Toggles pin state !outa[pin] dira[pin] := 1 pub input(pin) '' Makes pin input and returns current state dira[pin] := 0 return ina[pin] pub pulse_out(pin, us) | pwtix, state pwtix := us * (clkfreq / 1_000_000) ' pulse width in ticks state := ina[pin] ' read incoming state of pin if (ctra == 0) ' ctra available? if (state == 0) ' low-high-low low(pin) ' set to output frqa := 1 phsa := -pwtix ' set timing ctra := (%00100 << 26) | pin ' start the pulse repeat until (phsa => 0) ' let pulse finish else ' high-low-high high(pin) frqa := -1 phsa := pwtix ctra := (%00100 << 26) | pin repeat until (phsa < 0) ctra := 0 ' release counter return us elseif (ctrb == 0) if (state == 0) low(pin) frqb := 1 phsb := -pwtix ctrb := (%00100 << 26) | pin repeat until (phsb => 0) else high(pin) frqb := -1 phsb := pwtix ctrb := (%00100 << 26) | pin repeat until (phsb < 0) ctrb := 0 return us else return -1 ' alert user of error dat {{ Terms of Use: MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. }}
if you create an code-archive (zipfile) from within the propellertool and attach this to a posting we (the forum-members) can take a look into your code.
Just a few guessings:
- You have to start the FullDuplexSerial-object b ycalling the start-method before you can use it. Did you do that?
- the propeller-chip is a 3.3V device. What voltage does the receiver use?
- As JM mentioned 84 must be translated to 9600 for the propeller-chip FDX-method
Did you do some basic tests with your code like a closed loop Tx to Rx trying to receive data?
Did you test the propeller-chip sending some testdata to the PST.EXE?
best regards
Stefan