Shop OBEX P1 Docs P2 Docs Learn Events
Need help sending serial data — Parallax Forums

Need help sending serial data

Matthew HMatthew H Posts: 23
edited 2008-03-11 21:37 in Propeller 1
Hello,

I need some help programing my Propeller chip to send a serial command to a Pololu Micro Dual Serial Motor Controller. According to the manual, it expects eight bits at a time at a constant baud rate between 1200 to 19200 baud. The command must also be at logic levels and non-inverted. I have used this motor controller with my BS2 and in BS2 the command looks like this:

SEROUT 5, 84, [noparse][[/noparse]$80,0,5,127]



I am trying to send this string of data ($80,0,5,127) on pin 14 of of my Propeller, the code I am currently using is the following:

Tx.Start(0,14,0,9600)            'Start serial driver
Tx.str(string($80,0,9,127))     'Send command:  Motor 4 on at full speed




Tx refers to the FullDuplexSerial object that comes with the Propeller Tool. When I try to load it to RAM or EEPROM it says that I can't have a 0 in a string. The manual for the motor controller can be found here.

Thanks for any help you can offer,
Matthew

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-11 02:04
    The error message is correct. Strings in Spin use a zero byte to indicate the end, so you can't have one as explicit data.

    Best thing to do is to send one byte at a time by using the .tx() method in FullDuplexSerial. In your case, you'd have
    Tx.tx($80)
    Tx.tx(0)
    Tx.tx(9)
    Tx.tx(127)
    
  • grasshoppergrasshopper Posts: 438
    edited 2008-03-11 02:06
    Perhaps you could try this
    
    Tx.str(@string_one)     'Send command:  Motor 4 on at full speed
    
    
    dat
    string_one byte "8009127"
    
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-11 02:35
    grasshopper,
    Your suggestion will prevent the error message, but it won't do the job. It will send the characters "8", "0", "0", "9", "1", "2", "7", then it will send whatever stuff follows the "7" until it stumbles across a zero byte in memory which will stop the transmission.
  • JCeeJCee Posts: 36
    edited 2008-03-11 04:55
    I had the same problem and found out it works best to send the data byte by byte. Attached is a little test program I wrote that works with the Pololu Serial Motor Contoller.
  • Cats92Cats92 Posts: 149
    edited 2008-03-11 12:34
    May I add another problem with fullduplexserialplus : if receiving strings with zeros?
    I have a spin program which receive data with fulld.getdec and seems to give some strange results.
    This data are strings which may enclose zeros (for exemple : 105) . And as for sending strings with zeros , is receiving strings with zeros a source of errors? and how to avoid it?

    Cats92
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-11 14:15
    Cats92,
    Do you have specific examples of data that doesn't convert properly? Exactly what are the characters and what do you get as a result?

    Remember that there are two different values discussed here with the name "zeros". One is the digit zero as a character ("0" or $31).
    The other is the byte with the value zero which is used internally in Spin as a marker for the end of a character string.

    FullDuplexSerial can transmit and receive the zero byte except in the "string" receive and transmit routines where it is used as the
    string terminator.
  • Matthew HMatthew H Posts: 23
    edited 2008-03-11 21:37
    Thanks to Mike and JCee's help I now have my motor controller working!

    Thanks for the help, Matthew
Sign In or Register to comment.