Send String with SCI transmit
조회 수: 8 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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:
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
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
2011년 2월 21일
댓글 수: 2
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
2011년 2월 22일
댓글 수: 1
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>
참고 항목
카테고리
Help Center 및 File Exchange에서 String에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!