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 CenterFile Exchange에서 Run on Target Hardware에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by