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.
7 years, 10 months ago.
Mbed Can message transfer
Hi, i'm quite new on the programing world and i would like some advices for my problem. I've been asked to build a program on a LPC1768 that would receive some data on a CAN bus set to 500k bits/sec (frequency). Then i need to sen those data on a different CAN bus set to 1M bits/sec (frequency). Here's what my program look so far, sadly i've not been able to get any decent results. I'm using PCANview to send CAN messages to the LPC1768 but it seems it doesn't receive it.
- include <mbed.h> <</code>> DigitalOut led2(LED2); DigitalOut led1(LED1); Serial pc(USBTX, USBRX); CAN can1(p30, p29); CAN can2(p9, p10); CANMessage msg;
***************** Programme principal ******************
int main() { led2=1; led1=1; can1.frequency(500000); can2.frequency(1000000); while(1){ if (can1.read(msg)){ can2.write(msg); led2= !led2; } } }
1 Answer
7 years, 10 months ago.
You'll need to tackle this one piece at a time. Start with CAN1. Does peripheral initialize correctly? i.e. Do you not get any mbed error messages on the serial port? If the CAN peripheral fails to initialize mbed will let you know. Then connect it to your PC and simply send data from the board to the pc in a loop. Use an oscilloscope or logic analyzer to see if you get data coming out on the TX pin, then make sure you have data on the bus. Basically you have to build this up piece by piece.
Check the board for potential hardware conflicts on the CAN output pins. It does look to me like those pins run directly to the DIP header so should be good.
You didn't mention them, but you are using CAN transceivers for the bus right? And you've terminated each end of the bus with a 120ohm resistor? These micro's appear to require transceiver chip to generate the right bus voltages and differential signal. And then on the PC side you would need a piece of hardware to connect USB to CAN bus, again with it's own internal transceiver. Does your PCANview program come with a hardware dongle of some sort? If you posted a sketch of your setup it might help generate useful feedback.