7 years, 12 months ago.

lpc1768 , canbus communicate ,lpc serial communicate

LPC1768 CAN BUS COMMUNİCATİON

CANT READ DATA FROM CANBUS LINE BY LPC1768

/media/uploads/satoglu/can_bus1.png

hii , ı want make canbus communication project. ı will read sensors by 2 atmega328p microcontrollers and send data to canbus line by mcp2515 module. ı made till that. then ı will take data by lpc1768 from canbus line. then ı will send data to computer(c# monitor) .But ı cant get data to lpc1768 from canbus line. ı use these codes at down. ı read some sharings here but ı could not solve my problem. my frequency is 500000 and first can ıd =1, and second canıd is =2. what ıs my wrong or what ı must to do? thanks for your help.

<< code >>

  1. include "mbed.h"
  2. include "CAN.h"

Serial pc(USBTX, USBRX); Serial uart(p28, p27);

CAN can(p30, p29); CANMessage msg; float signal;

int main() { pc.baud(9600); can.frequency(500000); can.reset(); CANMessage msg; create empty CAN message printf("received a CANbus message...\n"); Write to serial terminal

while(1) {

if(can.read(msg)) { pc.printf("CAN message received\r\n"); pc.printf(" ID = 0x%.3x\r\n", msg.id); pc.printf(" Type = %d\r\n", msg.type); pc.printf(" Format = %d\r\n", msg.format); pc.printf(" Length = %d\r\n", msg.len); pc.printf(" Data =");

if(msg.id==1){

for(int i = 0; i < msg.len; i++){ pc.putc(msg.data[i]); pc.printf(" %.2x", msg.data[i]);

}} else { for(int i = 0; i < msg.len; i++){ pc.putc(msg.data[i]); pc.printf(msg.data[i]); pc.printf(" %.2x", msg.data[i]);

signal = *reinterpret_cast<float*>(msg.data); pc.printf(" signal = %5.2f\r\n", signal); }} wait(0.1); } wait(0.1); } }

<</code>>

ı removed "CAN.h" lib. and ı am using uart . still same ,ı cant read data on canbus line.

posted by ibrahim SATOGLU 03 Dec 2016

1 Answer

7 years, 11 months ago.

Hi,

Your code doesn't seem to have problems. Could you be more precise about your problem ? Are you sure that the ATmega send the messages (ie. did you check the CAN bus lines with an oscilloscope ?) Also, how long are your CAN bus lines ? Sometimes, only one 1 terminal resistor is needed (for short lines < 1m) and adding another one messes with the communication. If you're sure that the LPC1768 is the problem, then I'm afraid I won't be of great help...

ı built that circuit on board. canbus line is max 10cm.ı didn't check the CAN bus lines with an oscilloscope but ı can see data when ı use arduino mega2560 but when ı use lpc1768 , ı cant read data on canbus. ı tried all frequency (125000,250000 ,500000). also ı did a canbus example lpc1(send data) =>lpc2(receive data).but ı could not make that example. ı dont know what is my wrong or why ı cant read. :/

posted by ibrahim SATOGLU 03 Dec 2016

Emm... now that I take another look at your code, you did include a CAN.h lib. What is it ? You shouldn't need any additional librairie other than mbed.h to communicate via CANbus.

posted by Pierre David 03 Dec 2016

ı have started mbed yet for 2 weeks. ı saw an example so .also ı did .there is not a cause

posted by ibrahim SATOGLU 03 Dec 2016

ı removed "CAN.h" lib. and ı am using uart . still same ,ı cant read data on canbus line.

posted by ibrahim SATOGLU 03 Dec 2016