Let's Make Robots!

Matlab and PICAXE comms

Anyone out there who knows how to make Matlab work with serial communications?

I'm in the early stages of writing a matlab program to do inverse kinematics for a leggy kinda robot, and I want to get it to send the numbers to a picaxe via rs232 - seems fairly straightforward?

My test program is behaving wierdly

*code*

 

Picaxe = serial('COM4');

set(Picaxe,'BaudRate', 9600, 'DataBits', 8, 'Parity', 'none','StopBits', 1, 'FlowControl', 'none'); 

fopen(Picaxe);

fprintf(Picaxe,'1234');

Picaxe.ValuesSent

B = fread(Picaxe)

stopasync(Picaxe)

fclose(Picaxe);

delete(Picaxe)

clear Picaxe

*/code*

The Picaxe code goes like this

 

main:

serrxd w1

pause 50

sertxd(w1)

goto main

 

The idea is that the picaxe gets the recieved data and sends it straight out again, but when the string is more than 1 character, as it is here, it just returns the first value, no sign of the others. Also I can't get it to terminate once Matlab has recieved the data, it just sits there until it times out and gets upset.

Feel free to ask if I haven't been clear, any and all help gratefully recieved...

Mike

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

You need some sort of line termination. Since your protocol looks like it uses plain ascii i would suggest carriage return or line feed.

Carriage return is noted \r in C and properly also in matlab and has the HEX code 0x0D

Line feed is noted \n and has the HEX code 0x0A

I don't know what I was thinking.

For knowing when it is end of string I send and test for a zero. That must be possible to program somehow in matlab.