Shop OBEX P1 Docs P2 Docs Learn Events
Serial Communication using propeller — Parallax Forums

Serial Communication using propeller

lolobondlolobond Posts: 14
edited 2011-05-03 12:09 in Propeller 1
Hi! I really need help trying to figure this out before my capstone deadline. I am trying to send a numeric value 1 through the serial port of the propstick to the propeller. So far the code in spin works when typing 1 on the PST. But when I use matlab to send the numeric value 1 to the propeller the communication led on the chip blinks once in blue (so it means it is receiving something) but the led that is supposed to turn on is not turning on.

The code in spin:
CON

_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

OBJ
ser : "FullDuplexSerialPlus"

PUB main | Number

ser.Start(31, 30, 0, 9600)
waitcnt(clkfreq*2+cnt)

dira[4]~~
repeat
  ser.Str(String("Value received from PST:"))
  Number := ser.rx
  ser.tx(13)
  if Number == "1"
    !outa[4]            ' toggle LED for each incoming 1

The code in Matlab
s=serial('COM3','BaudRate',9600);
fopen(s);
ledon=[1];
fwrite(s,ledon)
fclose(s);

Any help will be greatly appreciated!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-27 12:49
    1) I believe you've already posted a similar message elsewhere in these forums. It's very much against forum rules to do so.

    2) I don't know MATLAB, but I suspect that your MATLAB program is not sending the character "1". It's probably sending a byte with the value 1. Change your MATLAB program to send the character "1" instead. You probably don't want to change your Spin program since, the way it's written, you can type a "1" using PST for testing. It's harder to use PST to send a byte value of 1.
  • lolobondlolobond Posts: 14
    edited 2011-04-27 17:14
    I Though PST was sending the number 1 instead of the character "1", thanks for the feedback and sorry for not reading the rules, I will be careful for next time. Thank you again
  • lolobondlolobond Posts: 14
    edited 2011-05-03 12:09
    Just wanted to thank you and let you know that I solved the problem. The problem was in the Matlab Code, I needed to pause the program for two seconds right after opening the port for serial communication. Now, it works perfectly.
Sign In or Register to comment.