11 years, 7 months ago.

CAN Hello World Example

Hello Mbed Team,

This is santhosh and im trying to work with the CAN code over here , im using 2 can tranceiver chips mcp 2551 and the bus is terminated with 250 ohm resistor and rs pin of the transceiver grounded but still unable to receive messages from the bus . I have attached the code ,snapshot from hyper terminal and connection schematic . please lemme know whether there's any mistake .

Expecting quick response from your side .

Can Tx code (Running on 1st board)

  1. include "mbed.h"

CAN can2(p30, p29);

char counter=0;

void send() {

if(can2.write(CANMessage(20, &counter, 1))) { printf("wloop()\n"); counter++; printf("\n Message sent: %d", counter); }

} int main() {

printf("main()\n");

while(1) {

send();

} }

CAN RX(Running on second board)

  1. include "mbed.h" CAN can2(p30, p29); int main() { CANMessage msg; while(1) {

if(can2.read(msg)) {

printf("\n Message received:%d", msg.data[0]);

wait(0.2); } }

}

/media/uploads/sanpai/transhyp.jpg /media/uploads/sanpai/canrx.jpg /media/uploads/sanpai/can.jpg

Question relating to:

2 Answers

11 years, 7 months ago.

Check this page for some hints: http://mbed.org/forum/mbed/topic/4229/?page=1#comment-20991

Accepted Answer
11 years, 7 months ago.

Hi Mr Wim,

Sorry for the delay in responding , there was a problem in wiring and it was not reading the message .I rewired the whole circuit and its fixed .

Hi, could you post your updated circuit via upverter or something, would be good to see what was wrong.

posted by Tharshan M 02 Apr 2013

Hello Tharshan,

Its the same circuit , few wires had loose contacts and so couldnt get the o/p .The mistake cost me 5-hrs :) :(

posted by Santhosh Pai 03 Apr 2013