Writing to mbed from MATLAB

13 Oct 2011

Hi! I have been trying to receive characters from matlab but im having trouble in getting it done. here is my mbed code. what it does is that it switches on the led based on the key pressed. it is working fine with other serial terminals like putty, but not on matlab.

include "mbed.h" DigitalOut leds[]={(LED1),(LED2),(LED3),(LED4)}; Serial in(USBTX,USBRX);

int main()

{

unsigned char i,j;

j=4;

while(1)

{

i=in.getc();

i-=49;

if(leds[i]==1)

continue;

leds[i]=1;

if(j<4)

leds[j]=0;

j=i;

}

}

here is the matlab code

mbed=serial('COM15','BaudRate',9600,'Parity','none','DataBits',8,'StopBits',1);

fopen(mbed);

fprintf(mbed,'%c','1');

fclose(mbed);

Any help would be greatly appreciated.

Thank you!

17 Oct 2011

Maybe try fwrite, which is what I'm using.

mbedComm = Serial('COM4'); set(mbedComm, 'BaudRate', 115200); fwrite(mbedComm, 'A'); fclose(mbedComm);