Serial port for Raspberry Pi embedded
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
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.
0 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Raspberry Pi Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!