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.
10 years, 9 months ago.
CAN hardware filter returns 0
Hi all,
I use this little snippet to test out the CAN hardware acceptance filter:
CAN hw acceptance filter
#include "mbed.h" CAN can(p30, p29); DigitalOut led1(LED1); Serial pc(USBTX, USBRX); int handle; void isrr() { CANMessage m; if(can.read(m,handle)) { led1=!led1; pc.printf("ISR!"); } } int main() { led1=0; can.reset(); handle = can.filter(0x100, 0xff, CANStandard); can.frequency(500000); can.attach(&isrr); pc.printf("MAIN:%d\n", handle); char a = 0; while(1){ can.write(CANMessage(0x10,&a,1)); a++; wait(1); } return 0; }
The problem is that, handle gets the value 0. This is what the api documentation says: "Returns 0 if filter change failed or unsupported"
What can I do to fix this, so I can use the hardware acceptance filter?
Im using the mbed LPC1768.
Cheers, Boris
2 Answers
10 years, 9 months ago.
Boris, I also have the same issue (just posted a question yesterday about the same thing) and I can add that can.frequency(500000) is also returning 0 each time your using it. I looked over the forum for other examples that have been used and not had any success.
If you try this: Does it work for you?
if(!can.frequency(500000)) printf("baud rate faild");
Filter example I found
can->reset(); // reset and clear all filters (accept all messages) h1 = can->filter(0x100, 0x700, CANStandard); // Accept standard messages with id 0x100-0x1FF h2 = can->filter(0x200, 0x7FF, CANStandard); // Accept standard message 0x200 as well [...] h2 = can->filter(0x300, 0x7FF, CANStandard, h2); // Accept standard message 0x300, overwrite 0x200 CANMessage msg = CANMessage(); int r = can.read(msg, h1); // Should only return messages with id 0x100-0x1FF int r = can.read(msg, h2); // Should only return messages with id 0x300 int r = can.read(msg); // Returns 0x100-0x1FF if pending, otherwise 0x300, otherwise any message
10 years, 9 months ago.
Yeah i found the same example, but even when trying to reset first, it still returns 0. I'm not sure wether my can.frequency(500000) returns 0 as well, but I can confirm, that it sets the frequency to 500000 in my program (as i tested it with another device at 500000 frequency).
Hopefully someone knows the answer to this?
Nope, unfortunately not. I was hoping someone of the mbed team would have an explanation for this??
posted by 31 Mar 2014Hi Rob, I found this snippet: http://mbed.org/users/ym1784/code/CAN_MONITOR/file/fe1f886dff76/main.cpp which works for me!
It would have been a lot nicer if the standard library would just work though.
posted by 31 Mar 2014