matlab serial communication with mbed

3 views (last 30 days)
Kun Su
Kun Su on 2 Jun 2016
Answered: Walter Roberson on 2 Jun 2016
I am trying to use mbed LPC1768 to read sensors and use matlab to collect the data by serial port. If I use PuTTy, I am able to see the data of serial port perfectly. However, when I try to use matlab, it does not work.
the command on matlab is simple like:
mbed = serial('COM5')
fopen(mbed)
value = fscanf(mbed,'%f')
I can read the first two values but after that, the value will always the same.. I use the LEDs on mbed to debug, the code of mbed does not have problems. However, the LED of the USB connector will not blink if I use matlab. The problem is the the data will not continually be sent. Could anyone help me about this?

Answers (1)

Walter Roberson
Walter Roberson on 2 Jun 2016
You should configure the BaudRate and Terminator properties of the serial object, and probably the FlowControl property as well.
If your data is line-oriented I recommend using fgetl() to fetch a line, and then sscanf() to read from the stored line. fgets() can cause you problems if the data you receive does not have the line boundaries that you expect.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!