Shop OBEX P1 Docs P2 Docs Learn Events
prop and velbus — Parallax Forums

prop and velbus

TumblerTumbler Posts: 323
edited 2011-10-04 22:57 in Propeller 1
Hello,

I'm trying to trow some packets on the velbus via rs232
Using the ppdb.

I can receive packets, but sending fails. Seems that the packets not arrived on the bus
Can someone take a look at this example?

Luc
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

Obj
 
  Serial : "FullDuplexSerial"
  pst : "Parallax Serial Terminal"  

var
  long temp
  
PUB Main| data, d

  pst.Start(38_400) 
  Serial.Start(6,7,%0000,38_400)

  Serial.rxflush
  'pst.Str(String("START"))
  'repeat
  '  temp := serial.rx
  '  pst.char(temp)

  serial.tx(string("0F F8 20 04 00 08 00 00 CD 04"))
  waitcnt(clkfreq / 100 + cnt)
  serial.tx(string("0F FB 20 02 F8 08 D4 04"))
  waitcnt(clkfreq / 100 + cnt)
  serial.tx(string("0F FB A0 08 FB 08 00 00 20 00 00 01 2A 0"))
  waitcnt(clkfreq / 100 + cnt)
  serial.tx(string("0F F8 20 04 00 00 08 00 CD 04"))
  waitcnt(clkfreq / 100 + cnt)
  serial.tx(string("0F FB 20 02 F8 08 D4 04"))
  waitcnt(clkfreq / 100 + cnt)
  serial.tx(string("0F FB A0 08 FB 08 00 01 20 00 00 01 29 04"))
  waitcnt(clkfreq / 100 + cnt)
  serial.tx(string("0F F8 A0 04 00 08 00 00 4D 04"))
  waitcnt(clkfreq / 100 + cnt)
  serial.tx(string("0F FB 20 02 F5 08 D7 04"))
  waitcnt(clkfreq / 100 + cnt)
  serial.tx(string("0F FB A0 08 FB 08 00 00 00 00 00 00 4B 04"))
  serial.tx(string("0F F8 A0 04 00 00 08 00 4D 04"))
 ' pst.Str(String("next "))
  waitcnt(clkfreq / 100 + cnt) '
  

  Serial.Stop

Comments

  • JonnyMacJonnyMac Posts: 9,202
    edited 2011-10-02 11:38
    You're sending the packets as ASCII -- is that what the system wants?

    [ Edit ] I don't think so. I found this document that explains the protocol. It looks like you need to send binary values, that is, you don't need to convert them to (human readable) ASCII.

    http://www.hqpower.eu/downloads/Velbus_ProtocolSummary.pdf

    Having looked at that document I think you might want to do something like this.
    pub velbus_tx(priority, address, dlen, dpntr) | chksum
    
      chksum := STX                                                 ' $0F
      velbus.tx(STX)
    
      chksum += priority
      velbus.tx(priority)
    
      chksum += address
      velbus.tx(address)
    
      repeat dlen
        chksum += byte[dpntr]
        velbus.tx(byte[dpntr++])
    
      chksum := -chksum & $FF
      velbus.tx(chksum)
    
      velbus.tx(ETX)                                                ' $04
    

    The velbus object handles serial IO (you can use fullduplexserial), dlen is the length of data in the packet, dpntr is the address of a byte array that holds your command and data. I tested the checksum algorithm against the test data in the documentation and it matches.
  • TumblerTumbler Posts: 323
    edited 2011-10-04 20:12
    Thx Jon,

    Sorry for this late reply
    I'm searchin for some examples using arrays in spin, but couldn't find some.

    The dpntr var is giving me real headache :innocent:
  • JonnyMacJonnyMac Posts: 9,202
    edited 2011-10-04 22:57
    You should consult the manual about variable definitions before tackling a protocol implementation. You might, for example, do this:
    [b]byte[/b]  txdata[8]
    

    ... to create an array. You can pass the address of any array (any variable, actually) using the @ operator.
Sign In or Register to comment.