Send String with SCI transmit

8 visualizaciones (últimos 30 días)
Daniel
Daniel el 21 de Feb. de 2011
Comentada: Kamal Joshi el 26 de Nov. de 2015
Anyone here know how to send a string with the SCI Transmit block.
I tried creating an embedded matlab function that simply returns
y = uint8('fu');
but the SCI transmit block spits out an error message saying it only accepts scalars. Is there any way to send a vector? Only other option i have is to create a function that runs a for loop and transmits each character at a time but i don't want to do this if a tool for this already exist. The matlab embedded tools cost so much I can't believe they don't have a simple serial send command that can accept an array of numbers or characters.

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Feb. de 2011
When you are in enough of a hurry that you can't afford to follow a lead from someone who is trying to help, then it is time to call Mathworks technical support. The people who answer questions here are volunteers, and most of them are not Mathworks staff. When you see someone's name here in a link, look right after the link: Mathworks staff have the little Mathworks icon -- but even those staff are volunteers.
------
In your hurry, you omitted to say what your device is. I researched all of the devices that are documented as supporting SCI. The links to their SCI Transmit blocks are:
And the general description of SCI transmit block configuration is here
All of the blocks explicitly state they support vectors of data, including vectors of uint8. There is, however, an important clue in the mpc555 description:
The Serial Transmit block transmits bytes via either of the MPC555 QSMCM submodules SCI1 or SCI2. You can use it either to transmit a fixed number of bytes, or, by enabling the second input, transmit a variable number of bytes each time this block is called. With SCI1, a hardware buffer is used that allows up to 16 bytes to be queued for transmission. With SCI2, the buffer allows only up to one byte to be queued each time the block is called. Once bytes are queued for transmit, they will be sent as fast as possible by the serial interface hardware with no further intervention required by the rest of the application.
Thus, if you happen to be using mpc555 and you are using it with two input ports, one of which is the number of bytes to transmit, then in that mode only one byte is accepted per trigger of the block, and so that one mode would complain if you tried to pass in a vector.
Corresponding two-input uses are not documented for the c28* series. I do not have the toolbox so I cannot experiment to see if the same construction applies.
There is also a relevant technical support note that is suggestive in the situation: 1-92LEMV . It presumes that vectors can be sent, but notes that in some circumstances you have to do klutzy things to build the vectors.
  2 comentarios
Daniel
Daniel el 22 de Feb. de 2011
I can easily send out more than one byte, i need to make that readable in hyper terminal. hyperterminal will display ascii characters, for example if i send a number 33(decimal) it will print out "!" because this is the ascii presentation of decimal 33. Look up ASCII maps.
I did call their support they have an ascii encode for xpc targets but not for TI F28335 chip. Their answer was to create an s-function, and as i said before there is a huge learning curve for this and in my oponion it will make the simulink code i'm writing harder to maintain if i start writting some of it in C.
By coming here i'm hoping that someone has ran into this and maybe even give me an s-function.
Anyone here know how to essential do a number to string conversion, matlab has a num2str() which would be perfect but it is not compatible with embedded matlab fcn.
Walter Roberson
Walter Roberson el 22 de Feb. de 2011
Your problem description says that you are having difficulty getting the SCI Transmit blocks to accept vectors. Is that no longer the case -- did you solve that issue?
atoi within simulink is a different topic, and would likely be better off as a new Question. (No need to mention SCI in that question, just list your target chip and indicate that it does not support the ascii encode block.)

Iniciar sesión para comentar.

Más respuestas (4)

Walter Roberson
Walter Roberson el 21 de Feb. de 2011
This earlier SCI Question might be beneficial to you.
  2 comentarios
Daniel
Daniel el 22 de Feb. de 2011
It was useless, if you don't know just don't post please.
Walter Roberson
Walter Roberson el 22 de Feb. de 2011
Guess you aren't interested in the solutions I researched, then, since I don't KNOW from personal experience that they will work.

Iniciar sesión para comentar.


Daniel
Daniel el 22 de Feb. de 2011
I don't mean to be rude, just that i'm in a hurry to find a solution to this. Essentially i need to see the output in hyperterminal in a human readable format.
So what it comes down to is a number to string convertion, but the num2str is not compatible in embedded matlab. Simulink has no tool that can convert a number to ascii or any other ascii encoder. This is the first time i have seen this in a compiler. Simulink real time embedded tools package was really expensive but it is very weak when it comes to basic software libraries.
Essentially i might have to create a c s-fucntion that uses the itoa() and atoi() functions, although the s-functions there is a huge learning curve with s-functions.

Daniel
Daniel el 22 de Feb. de 2011
By the way my embedded target is not an xPC target, i'm saying this because they have an ascii encode and decode function. I tried using it but now luck :-(
  1 comentario
Joris Lambrecht
Joris Lambrecht el 8 de Jul. de 2013
Editada: Joris Lambrecht el 8 de Jul. de 2013
In many cases you can use the ASCII Encode block with C2000 devices (with minor modification). Locate the file "asciiencode.c" in "<MATLABROOT>\toolbox\rtw\targets\xpc\target\build\xpcblocks" and comment out the line as follows: //#include <windows.h>

Iniciar sesión para comentar.


Daniel
Daniel el 22 de Feb. de 2011
Anyone here know how to do a number to string conversion, matlab has a num2str() which would be perfect but it is not compatible with embedded matlab fcn.
  1 comentario
Kamal Joshi
Kamal Joshi el 26 de Nov. de 2015
any luck with this Daniel ?

Iniciar sesión para comentar.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by