Serial port for Raspberry Pi embedded

4 ビュー (過去 30 日間)
Marco
Marco 2014 年 7 月 21 日
編集済み: Walter Roberson 2015 年 7 月 25 日
Hello everybody,
I'm trying to access a serial port of Raspberry Pi. My aim is to have an embedded code, so I'm using simulink, with a Matlab function and a small c-code.
It's all pretty basic right now, since I get an error just with these few lines which should initialize and open the serial port.
The Matlab Function is:
function fcn(var)
%#codegen
persistent initflag;
if strcmp(coder.target, 'rtw'),
if isempty(initflag),
%initialiaze
coder.ceval('serialpi_init',var)
initflag = 1;
end
end
The c-code is:
#include </home/pi/wiringPi/wiringPi/wiringPi.h>
#include </home/pi/wiringPi/wiringPi/wiringSerial.h>
void serialpi_init (double var){
int fd;
fd = serialOpen ("/dev/ttyACM0", 9600) ;
}
void serialpi_output(double var){
}
The error that I get is when simulink try to download the model:
The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
Error executing SSH command: make: Entering directory `/home/pi/prova_seriale_rasp_rtt'
"gcc" -I"./" -O3 -D"MODEL=prova_seriale_rasp" -D"NUMST=1" -D"NCSTATES=0" -D"HAVESTDIO=" -D"ONESTEPFCN=0" -D"TERMFCN=1" -D"MAT_FILE=0" -D"MULTI_INSTANCE_CODE=0" -D"INTEGER_CODE=0" -D"MT=0" -D"CLASSIC_INTERFACE=0" -D"TID01EQ=0" -D"_USE_TARGET_UDP_=" -D"_RUNONTARGETHARDWARE_BUILD_=" -c ./linuxUDP.c ./codice_c_raspberry.c ./ert_main.c ./prova_seriale_rasp.c ./prova_seriale_rasp_data.c
"gcc" ./linuxUDP.o ./codice_c_raspberry.o ./ert_main.o ./prova_seriale_rasp.o ./prova_seriale_rasp_data.o -lm -ldl -lpthread -lrt -o ./MW/prova_seriale_rasp
./codice_c_raspberry.o: In function `serialpi_init':
codice_c_raspberry.c:(.text+0x8): *undefined reference to `serialOpen'*
collect2: ld returned 1 exit status
make: *** [MW/prova_seriale_rasp] Error 1
make: Leaving directory `/home/pi/prova_seriale_rasp_rtt'
Some ideas?
Many thanks,
Marco

回答 (2 件)

Murat Belge
Murat Belge 2014 年 9 月 8 日
You did not specify the source code for serialOpen() in your System Object. Change your C-code to the following:
#include </home/pi/wiringPi/wiringPi/wiringPi.h>
#include </home/pi/wiringPi/wiringPi/wiringSerial.h>
#include </home/pi/wiringPi/wiringPi/wiringPi.c>
#include </home/pi/wiringPi/wiringPi/wiringSerial.c>
void serialpi_init (double var){
int fd;
fd = serialOpen ("/dev/ttyACM0", 9600) ;
}
void serialpi_output(double var){
}
Note the inclusion of two C-files specifying the source for wiringPi.c and wiringSerial.c.

walid AL-ATABANY
walid AL-ATABANY 2015 年 7 月 24 日
Dear Marcu,
Do you know how can I access the bluetooth instead of the serial port in raspberry pi. also where should I put this c-code? is it in the same matlab function?
Regards

カテゴリ

Help Center および File ExchangeRun on Target Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by