Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 2 months ago.
about ID selectable CAN receive
sirs.
Please help me. And sorry for my poor English.
I'm trying to receive messages from a receiver connected to PIN29 and PIN30. And I can receive some IDs.
But I cannot receive by ID selectable.
I make the code below.And the exam's report is below too. I'd like to receive only ID174(on HEX).
But MBED get another ID data. How can I get ONLY ID174 data.
----code--------
- include "mbed.h"
Serial pc(USBTX, USBRX);MBED USB CAN vcan(p30, p29);can
double wt=0.01; int inchk; int inchar;
int vcaninchk; int vcaninchar;
int main() { pc.baud(460800);bps pc.format(8, Serial::None, 1);bits,parity,stop_bit vcan.frequency(500000); CANMessage id174rx(372 , CANStandard);0x174 = 372
while(1) {
vcaninchk = vcan.read(id174rx); if(vcaninchk == 1){ pc.printf("\nID174 %d %d %d,%d,%d,%d,%d,%d,%d,%d",vcaninchk,id174rx.id,id174rx.data[0],id174rx.data[1],id174rx.data[2],id174rx.data[3],id174rx.data[4],id174rx.data[5],id174rx.data[6],id174rx.data[7]); }
wait(wt);
} }
-----exam.-------
ID174 1 381 80,51,64,12,128,0,128,0
ID174 1 381 80,51,64,12,128,0,128,0
ID174 1 1376 0,0,0,4,127,192,128,0
ID174 1 381 80,51,64,12,128,0,128,0
ID174 1 381 80,51,64,12,128,0,128,0
ID174 1 398 0,0,0,0,241,76,28,20
ID174 1 381 80,51,64,12,128,0,128,0
ID174 1 381 80,51,64,12,128,0,128,0
ID174 1 398 0,0,0,0,241,76,27,20
ID174 1 381 80,51,64,12,128,0,128,0
ID174 1 381 80,51,64,12,128,0,128,0
ID174 1 381 80,51,64,12,128,0,128,0
ID174 1 398 0,0,0,0,241,76,25,20
ID174 1 381 80,51,64,12,128,0,128,0
1 Answer
8 years, 2 months ago.
Hello koji dohi-san.
Your original code (formatted):
include "mbed.h" Serial pc(USBTX, USBRX); //MBED USB CAN vcan(p30, p29); //can double wt=0.01; int inchk; int inchar; int vcaninchk; int vcaninchar; int main() { pc.baud(460800); //bps pc.format(8, Serial::None, 1); //bits,parity,stop_bit vcan.frequency(500000); CANMessage id174rx(372 , CANStandard); //0x174 = 372 while(1) { vcaninchk = vcan.read(id174rx); if(vcaninchk == 1) { pc.printf("\nID174 %d %d %d,%d,%d,%d,%d,%d,%d,%d",vcaninchk,id174rx.id,id174rx.data[0],id174rx.data[1],id174rx.data[2],id174rx.data[3],id174rx.data[4],id174rx.data[5],id174rx.data[6],id174rx.data[7]); } wait(wt); } }
try with:
include "mbed.h" Serial pc(USBTX, USBRX);MBED USB CAN vcan(p30, p29); //can double wt=0.01; int inchk; int inchar; int vcaninchk; int vcaninchar; int main() { pc.baud(460800); //bps pc.format(8, Serial::None, 1); //bits,parity,stop_bit vcan.frequency(500000); CANMessage id174rx(372 , CANStandard); //0x174 = 372 while(1) { vcaninchk = vcan.read(id174rx); if(vcaninchk) { if (id174rx.id ==0x174){ pc.printf("\nID174 %d %d %d,%d,%d,%d,%d,%d,%d,%d",vcaninchk,id174rx.id,id174rx.data[0],id174rx.data[1],id174rx.data[2],id174rx.data[3],id174rx.data[4],id174rx.data[5],id174rx.data[6],id174rx.data[7]); } } wait(wt); } }
reference example:
https://developer.mbed.org/questions/2789/CanBus-CANExtended-read-what-am-I-doing-/
Sanjiv Bhatia-san arigatou!!
Thank you very much. Maybe I understand the function with your advice.
Now, My understanding about your saying is
MBED doesn't have the function that search and get CAN data by ID selectable from CAN buffer. MBED only can get most newest CAN data from CAN buffer by "*.read(msg)" command.
Can buffer is "Last In First Out" and "First In Last Out" like stack.
Is it all right?
posted by 11 Sep 2016Sanjiv Bhatia-san
Sorry,I see
Today, I do any tests to MBED, And finally I did it!
MBED has only 2 buffer for CAN receive, So We need to get receive data before drop from buffer by " CAN frame received interrupt"function that is "attach"command.
https://developer.mbed.org/handbook/CAN
posted by 11 Sep 2016
You need to use CAN::filter function. Insert something like "vcan.filter(0x174, 0xFFFFFFFF, CANAny);" after "vcan.frequency(500000);" line. And read CAN Class description here https://developer.mbed.org/handbook/CAN
posted by Mike Rodin 11 Sep 2016