I'm having trouble on characters conversion

2 views (last 30 days)
Hi, I'm using a microcontroller (freedom board from Freescale) to send some data to MatLab (using serial). I'm sending numbers in character format. However, when I do the conversion on MatLab (from char to double) I get some problems. For example: I'm sending the number 128 (I do the conversion in the microcontroller), when I receive this data on MatLab and I do the conversion, I get the number 8364. Maybe the MatLab is using another ascii table as reference (probably HTML). However, I don't know how to fix this problem. It occurs the same for the number 129 (appears 65533 and 130=8218).
Can someone help me?
Thank you.
  4 Comments
Guillaume
Guillaume on 6 Oct 2015
Edited: Guillaume on 6 Oct 2015
"MatLab is using another ascii table as reference (probably HTML)"
There is only one ASCII table and in any case most non-ascii character encodings (such as unicode, and the many windows codepages) use the same coding for numbers.
HTML has got nothing to do with character encoding. It is a protocol for encoding webpage content.
The fact that you're confusing HTML with character encoding or maybe transmission protocol means you probably should learn more about encoding characters. It also means that in all likelyhood the problem is with your code, either on the sending or receiving side. So, as others have said, show us your code.
MathWorks Student Competitions Team
The Serial Transmit block for the Freescale FRDM-KL25Z board has two different modes for sending serial data. One mode, 'putc' can only send uint8 data, which means that if you are trying to send some other data type, you would need to split that datatype into its component bits and then reassemble them into the original datatypes on the receiving side. The second mode, 'printf', takes whatever datatype you give it, converts the value into ascii characters (e.g. the number 128 becomes the characters '1', '2', and '8') and sends over one character at a time, these need to be converted from char to some numerical datatype on the receiving end (unless you wanted characters on the receiving end).
To help you further, please provide:
  • the initial datatype of the data you are trying to send over serial,
  • code for the "conversion" that you are doing on the microcontroller before you send it to the serial transmit block,
  • what mode the serial transmit block is in?
  • what code/functions are you using to receive the data in MATLAB?
  • what are the raw values received in MATLAB?
  • what code/functions do you use to "convert" these values to numbers?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!