Shop OBEX P1 Docs P2 Docs Learn Events
BS2 to Prop — Parallax Forums

BS2 to Prop

Earl FosterEarl Foster Posts: 185
edited 2009-04-13 16:56 in Propeller 1
I have been playing with a new serial device that requires me to initialize the unit prior to receiving data.· After numerous attempts on the Prop I moved back to my comfort zone (STAMP) and was able to initialize the device and start monitoring the output.
·
Below is the Stamp that works
' {$STAMP BS2px}
' {$PBASIC 2.5}
PNI_RX          CON     1
PNI_TX          CON     0
N9600           CON     16780
char            VAR     Byte
PAUSE 250
Main:
  SEROUT PNI_TX, N9600, [noparse][[/noparse]$00,$05,$15,$BD,$61]
  PAUSE 100
start:
  SERIN PNI_RX, N9600, [noparse][[/noparse]char]
  DEBUG HEX char
GOTO start

Here is the SPIN code that I have been using without results.
con
  _clkmode = xtal1 + pll16x  
  _xinfreq = 5_000_000        
obj
  debug[noparse][[/noparse]2]:        "FullDuplexSerialPlus"           'Debug object
  
var
  byte pni
   
pub main
    Debug[noparse][[/noparse]0].start(31, 30, 0, 9600)        'Start the debug terminal
    debug[noparse][[/noparse]0].str(string("Starting"))
    debug[noparse][[/noparse]1].start(16,17,0,9600)
    waitcnt(clkfreq/4 + cnt)
    debug[noparse][[/noparse]1].tx($00)
    debug[noparse][[/noparse]1].tx($05)
    debug[noparse][[/noparse]1].tx($15)
    debug[noparse][[/noparse]1].tx($BD)
    debug[noparse][[/noparse]1].tx($61)            
    waitcnt(clkfreq/4 + cnt)
    repeat
       debug[noparse][[/noparse]0].hex(debug[noparse][[/noparse]1].rx,1)         'Receive btye and display

I do have the standard 5vDC protection in place for the the Prop I/O and I have checked and rechecked the connections but I can not get the Prop to initialize the serial device.· It is possible that the 3.3v output signal is not detectable on the serial device and that is my problem.· I have not heard back from the manufacturer yet on that question.

Can someone·tell me if I am doing something wrong with the SPIN code?·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
WWW.HAPB.NET

"Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2009-04-11 00:24
    We should all have a logic level converter like this one http://www.sparkfun.com/commerce/product_info.php?products_id=8745 (Unfortunately out of stock) for testing. I don't see anything wrong with you Spin code except you are pausing 1/4 second in Spin and only 0.1 seconds on the Stamp. I just noticed a 1/4 second pause before Main on the Stamp and no pause in Spin.

    John Abshier
  • localrogerlocalroger Posts: 3,451
    edited 2009-04-11 13:39
    While most serial ports will forgive the Stamp for putting out 0-5V instad of -5-+5V, some will not forgive the Prop for putting out 0-3V. 3V just isn't enough. You can receive RS232 into the Prop with just a couple of resistors but to transmit reliably you need a level converter; a MAX232 being best of course, but even just a transistor to pull logic 1 up to 5V instead of 3 would do the trick.
  • Earl FosterEarl Foster Posts: 185
    edited 2009-04-11 22:40
    Earlier today I wrote a BS2 program that programs the PNI device to output heading, temperature, pitch, and roll with the following code
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    PNI_RX          CON     1
    PNI_TX          CON     0
    N9600           CON     16780
    char            VAR     Byte
    idx             VAR     Byte
    value VAR Word
    value2  VAR     Byte
    PAUSE 250
    Main:
      SEROUT PNI_TX, N9600, [noparse][[/noparse]$00,$0A,$03,$04,$05,$07,$18,$19,$84,$BF] 'heading, temp, pitch, roll
      PAUSE 100
      SEROUT PNI_TX, N9600, [noparse][[/noparse]$0,$5,$15,$BD,$61] 'KStartIntervalMode
      PAUSE 250
    start:
      SERIN PNI_RX, N9600, [noparse][[/noparse]WAIT($0,$1A,$5,$4),SPSTR 24]
      idx = 0
      DO
         GET idx, char
         DEBUG IHEX char
         idx = idx + 1
      LOOP UNTIL idx = 24
    GOTO start
     
    '5 Sample outputs
    'preample     Heading         Temperature     Pitch            Roll
    '$0$1A$5$4 $5 $42$CF$B7$B1 $7 $41$E7$C0$0 $18 $C0$44$7B$85 $19 $40$29$A0$D7
    '$0$1A$5$4 $5 $42$CF$83$85 $7 $41$E8$40$0 $18 $C0$44$79$7E $19 $40$29$9A$79
    '$0$1A$5$4 $5 $42$CF$9C$3B $7 $41$E7$80$0 $18 $C0$44$99$BB $19 $40$29$90$8F
    '$0$1A$5$4 $5 $42$CF$80$9D $7 $41$E8$0$0  $18 $C0$44$31$B7 $19 $40$29$D5$19
    '$0$1A$5$4 $5 $42$CF$AD$24 $7 $41$E7$C0$0 $18 $C0$44$97$38 $19 $40$29$68$1A9
    

    The output has been verified to be correct but when I listen in with the Prop I get a completely different and incorrect output.· This is a seperate issue from being able to TX to the device.
    con
       _clkmode = xtal1 + pll16x  
       _xinfreq = 5_000_000        
    obj
       debug[noparse][[/noparse]2]:        "FullDuplexSerialPlus"           'Debug object
    pub main
       Debug[noparse][[/noparse]0].start(31, 30, 0, 9600)        'Start the debug terminal
       debug[noparse][[/noparse]0].str(string("Starting"))
       debug[noparse][[/noparse]1].start(16,17,0,9600)
       repeat
          debug[noparse][[/noparse]0].hex(debug[noparse][[/noparse]1].rx,1)         'Receive btye and display
     
    '5 Sample outputs
    
    '0CB5759D93E31ADD1F751D5FE9D0
    '00B5759D3DF35ABD131D2D5FE590
    '00B5759D3DF35ABD131D2D5FE590
    '00B5759D51F3D6641F951D5FE970
    '0FB5759D1FF3926417D31D3FFD30
    

    Any ideas why that might be the case?

    I added a side-by-side output image.· It is interesting how the STAMP is clean and the Prop output is all zeros between data burst and they do not come close to matching(besides the $ I have the stamp producing in the output)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    WWW.HAPB.NET

    "Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman

    Post Edited (Earl Foster) : 4/12/2009 12:58:36 AM GMT
    1306 x 628 - 287K
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-12 05:24
    Hello Earl,

    your codeline

          debug[noparse][[/noparse]0].hex(debug.rx,1)         'Receive byte and display
    
    



    send only ONE digit. one byte are TWO hexadecimal digits

    so change it to
          debug[noparse][[/noparse]0].hex(debug.rx,2)         'Receive byte and display
    
    




    If this does not help

    Post a picture of how you have connected your device to the propeller.

    What voltagelevels does the device have for low and high ?

    Did you check your propeller-setup with a terminalsoftware.
    I mean a terminalsoftware that is known to send proper data connected to the propeller on object debug
    receiving data from the terminalsoftware

    sending a $00 watch what the propeller receives
    sending a $FF watch what the propeller receives

    sending a $01 watch what the propeller receives
    sending a $FE watch what the propeller receives

    sending a $02 watch what the propeller receives
    sending a $FD watch what the propeller receives
    ...
    best regards

    Stefan
  • Earl FosterEarl Foster Posts: 185
    edited 2009-04-12 18:14
    It took a while and some rethinking but I was able to start receiving the correct data.· I needed to invert the TX mode which I took into account when setting up the Stamp but forgot to do with the Prop.· Actually, I tried all modes but unless you send the PUSH command to the unit it will not·transmit any data.· Once I·tapped in·the Stamp serial connections and used it to trigger the device I could start to see the correct data.· Great!· But now .... I need to trigger the device.

    I am facing one of two issues.· Either my code is incorrect or the device needs 5v signal.· I have experimented with both, but troubleshooting 2 issues is not the way to go. Need to eliminate one before moving on to the other.

    Hence my question
    I need to send, in·HEX, the·following·PUSH command frame 000515BD61 where
    ··· 00 05· - Int16 which is the byte count including CRC
    ··· 15····· -·UInt8 packet frame id (start pushing data command)
    ··· BD 61· - UInt16 is CRC-CCITT (XModem)

    Would the code below·correctly send 000515BD61 to the device?·
    I have also tried droping the leading zeros resulting in 0515BD61 with no results.
    con
      _clkmode = xtal1 + pll16x  
      _xinfreq = 5_000_000       
    
     
    obj
      debug[noparse][[/noparse]2]:        "FullDuplexSerialPlus"
     
    pub main
        Debug[noparse][[/noparse]0].start(31, 30, 0, 9600)
        debug[noparse][[/noparse]0].str(string("Starting"))
        waitcnt(clkfreq + cnt)
        debug[noparse][[/noparse]1].start(1,0,1,9600)                                           
        debug[noparse][[/noparse]1].tx($00)
        debug[noparse][[/noparse]1].tx($05)
        debug[noparse][[/noparse]1].tx($15)
        debug[noparse][[/noparse]1].tx($BD)
        debug[noparse][[/noparse]1].tx($61)
        repeat
           debug[noparse][[/noparse]0].hex(debug[noparse][[/noparse]1].rx,2)            'Receive btye and display
    
    




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    WWW.HAPB.NET

    "Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
  • Earl FosterEarl Foster Posts: 185
    edited 2009-04-12 22:32
    I just tried using these two different circuits to interface·the Prop with the PNI devices·and neither of them seems to have worked so I am starting to think it is the code.

    Any suggestions?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    WWW.HAPB.NET

    "Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
    462 x 257 - 13K
  • Earl FosterEarl Foster Posts: 185
    edited 2009-04-13 14:08
    OK I have eliminated the 3.3 to 5·issue.· Using the transistor circuit I captured the attached waveforms at 3.3v and 5v.

    I could use some suggestion and ideas of what the problem could be.· The stamp program has no problem getting the PNI device to transmit data.· AH - let me look at the Stamp waveform and compare them.· The attached plots are the waveform of the push command sent to the PNI device.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    WWW.HAPB.NET

    "Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman

    Post Edited (Earl Foster) : 4/13/2009 2:14:04 PM GMT
    985 x 608 - 104K
    988 x 605 - 106K
  • Earl FosterEarl Foster Posts: 185
    edited 2009-04-13 16:15
    I ran a trace on the Stamp and detemined that the Prop TX signal is inverted which is why I can not get it start the PNI data push.· Its interesting that the Stamp does not invert it TX signal and the Prop does ...

    So I need to invert the TX signal from the Prop.· Hopefully that will take care of the problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    WWW.HAPB.NET

    "Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
    988 x 606 - 102K
  • Earl FosterEarl Foster Posts: 185
    edited 2009-04-13 16:56
    Used a transistor to invert the signal and it working like a champ. Thanks for being a sounding board.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    WWW.HAPB.NET

    "Don't ask yourself what the world needs - ask yourself what makes you come alive, and then go do it." - H.T.Whitman
Sign In or Register to comment.