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.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hi,
I'm trying to test out the CAN functionality with a simple network:
But I never get a received message. I'm using the sample code:
#include "mbed.h" Serial pc(USBTX, USBRX); // tx, rx CAN can1(p9, p10); CAN can2(p30, p29); char counter = 0; Ticker ticker; void send() { pc.printf("send()\n"); if (can2.write(CANMessage(1337, &counter, 1))) { pc.printf("wloop()\n"); counter++; pc.printf("Message sent: %d\n", counter); } } int main() { pc.printf("main()\n"); can2.frequency(100000); can1.frequency(100000); ticker.attach(&send, 1); CANMessage msg; while (1) { pc.printf("loop()\n"); if (can1.read(msg)) { pc.printf("Message received: %d\n", msg.data[0]); } wait(0.2); } }I verified that CAN1 and CAN2 were properly connected to the MBED because if the RX/TX were swapped, it would only send 3-4 messages. I also swapped the send/receive for CAN1 and CAN2 (CAN1 would send CAN2 receive and vice versa) but still no luck. I also tried setting the frequency to 500,000 and not setting it. Any ideas?
Cheers, Sebastian