Shop OBEX P1 Docs P2 Docs Learn Events
Receiving valid data? — Parallax Forums

Receiving valid data?

charleyshfcharleyshf Posts: 165
edited 2011-02-21 12:40 in Propeller 1
Hi,

I have been trying to read some information from a Robo Claw motor controller using packet serial mode with my prop(this is so I can using the wheel encoders with the robo claw), I've been able to get some things working, however I am stuck on something and hoping to get some direction on what it is that I am doing wrong.

From the manual on the robo claw this is the info I am currently working on:

24 - Read Main Battery Voltage Level
Read the main battery voltage level connected to B+ and B- terminals. The voltage is returned in 10ths
of a volt. Command syntax:
Sent: [Address, CMD]
Received: [Value.Byte1, Value.Byte0, CRC]
The command will return 3 bytes. Byte 1 and 2 make up a word variable which is received MSB fi rst
and is 10th of a volt. A returned value of 300 would equal 30V. Byte 3 is the CRC. It is calculated the
same way as sending a command and can be used to validate the data. The following example will
read the main battery voltage with Robo Claw address set to 128.
hserout [128, 24] ;read main battery voltage
hserin [Value.Byte1, Value.Byte0, CRC]


In my code which is attached, the prop and the robo claw are communicating at 2400 baud, I am also using 2.2k resistors on the rx and tx lines between the two.

The code as it works now, I receive this in PST:

First = 23
Second = 127
Third = 0


End

The second result(127) is actually the voltage 12.7v, I have check this with a voltmeter on the robo claw. The manual for the robo claw can be found at http://downloads.basicmicro.com/downloads/datasheets/motor_controller_robo_claw_B0099.pdf

Any ideas what I am doing wrong?

Thank you in advance.

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2011-02-21 12:00
    You simply mixed up the order! You read into x[ 0 ], x[ 1 ] and x[ 2 ] in this order and then you output x[ 2 ] and name it First.

    0 and 127 belong together and are the voltage. So, at 35 volt you would receive 350 with 350/256 = 1 in the high byte and 350//256 = 94 in the low-byte.

    The 23 is the checksum. The rules for generating the checksum should be mentioned somewhere.
  • charleyshfcharleyshf Posts: 165
    edited 2011-02-21 12:40
    Thank you for responding! I've been programming for days on this project and got lost on the MSB and LSB, need some advil and a break me thinks!!

    The CRC is 7 bit (8th bit masked) calculated as follows: address(in my case 128) + command(in my case 24) + data(in my case 127) = CRC(23), 279//256 = 23 in the low-byte..

    thanks again!
Sign In or Register to comment.