Send String with SCI transmit

6 ビュー (過去 30 日間)
Daniel
Daniel 2011 年 2 月 21 日
コメント済み: Kamal Joshi 2015 年 11 月 26 日
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.

採用された回答

Walter Roberson
Walter Roberson 2011 年 2 月 22 日
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 件のコメント
Daniel
Daniel 2011 年 2 月 22 日
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 2011 年 2 月 22 日
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.)

サインインしてコメントする。

その他の回答 (4 件)

Walter Roberson
Walter Roberson 2011 年 2 月 21 日
This earlier SCI Question might be beneficial to you.
  2 件のコメント
Daniel
Daniel 2011 年 2 月 22 日
It was useless, if you don't know just don't post please.
Walter Roberson
Walter Roberson 2011 年 2 月 22 日
Guess you aren't interested in the solutions I researched, then, since I don't KNOW from personal experience that they will work.

サインインしてコメントする。


Daniel
Daniel 2011 年 2 月 22 日
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 2011 年 2 月 22 日
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 件のコメント
Joris Lambrecht
Joris Lambrecht 2013 年 7 月 8 日
編集済み: Joris Lambrecht 2013 年 7 月 8 日
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>

サインインしてコメントする。


Daniel
Daniel 2011 年 2 月 22 日
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 件のコメント
Kamal Joshi
Kamal Joshi 2015 年 11 月 26 日
any luck with this Daniel ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeString についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by