11 years ago.

Canbus example not working.

Hello, I have modified the Canbus example to print to the Hyperterminal and then connected pin 10 to pin 30 and pin 9 to pin 29 on the mbed NXP LPC1768.

When running it sends OK but will not read the message it just sent.

Here is the code:

  1. include "mbed.h"

Serial pc(USBTX,USBRX); Ticker ticker; DigitalOut led1(LED1); DigitalOut led2(LED2); CAN can1(p9, p10); CAN can2(p30, p29);

char counter = 0; void send() { pc.printf("send()\n\r"); if(can1.write(CANMessage(1337, &counter, 1))) { pc.printf("wloop()\n\r"); counter++; pc.printf("Message sent: %d\n\r", counter); } led1 = !led1; }

int main() { pc.printf("main()\n\r"); ticker.attach(&send, 1); CANMessage msg; while(1) { pc.printf("loop()\n\r"); if(can2.read(msg)) { pc.printf("Message received: %d\n\r", msg.data[0]); led2 = !led2; } wait(0.2); } }

This is Hyperterminal output...... loop() loop() loop() send() wloop() Message sent: 40 loop() loop() loop() loop() loop() send() wloop() Message sent: 41 loop() loop() loop() loop() loop()

..Any help much appreciated.

Question relating to:

1 Answer

10 years, 6 months ago.

This is likely too late for Murray, but perhaps for other that happen upon this page.

With a CAN transceiver chip, what is transmitted can also be sensed, so the CAN bit processor knows if it successfully sent a packet, or not. As you are wiring it, I believe it cannot sense that. While it is possible to diode or and resistor bias the discrete pins to let the two ports talk, it is nearly as simple (and more scalable to other devices) to use CAN transceiver chips as you see in the Handbook - CAN page.

Accepted Answer