4 years, 9 months ago.

lpc1768 with mcp2515 spi can bus

I want to communicate with the mcp2515 can bus with lpc1768 how can i do it?

The LPC1768 has built in CAN interface. Why don't you use that? https://developer.mbed.org/handbook/CAN

posted by Mark Peter Vargha 28 Jan 2017

1 Answer

4 years, 8 months ago.

My English language skill is poor. sorry for that....!

I am also bothering last two weeks with med1768 and mcp2515 to connect each others. in this i tried out two CAN libraries

/media/uploads/sameera0824/download.jpg /media/uploads/sameera0824/mcp2515.jpg

Seeed Studios CAN https://developer.mbed.org/components/Seeed-Studios-CAN-BUS-Shield/


Jason Engelman's mcp2515 CAN library https://developer.mbed.org/users/tecnosys/code/mcp2515/

MBED1768 have two SPI ports to communicate. but both of this libraries are not supporting to second SPI port (mosi=p11, miso=p12, sck=p13). Both of this support only SPI port one (mosi=p5, miso=p6, sck=p7).

in seed CAN you should edit library

  • open seed_can.h
  • go to 82 line (SEEED_CAN(PinName ncs=p9, PinName irq=p10, PinName mosi=p11, PinName miso=p12, PinName clk=p13, int spiBitrate=1000000);)
  • change it to SPI one port (SEEED_CAN(PinName ncs=p9, PinName irq=p10, PinName mosi=p5, PinName miso=p6, PinName clk=p7, int spiBitrate=1000000);)


in Jason Engelman's mcp2515 CAN library

  • you should use spi one port (SPI spi(p5,p6,p7); mosi, miso, sclk)
  • you can use can3 as usual (CAN3 can(spi,p9,p11); spi, ncs, itr )




working tested code

include the mbed library with this snippet

#include "mbed.h"
#include "CAN3.h"
//SPI spi(p11,p12,p13);// mosi, miso, sclk
SPI spi(p5,p6,p7);// mosi, miso, sclk
CAN3 can(spi,p9,p11); //spi, ncs, itr
DigitalOut led2(LED2);
DigitalOut led1(LED1);
Serial pc(USBTX, USBRX);

 int main() {
    char data[1] = {0};
    CANMessage msg(2002,data,1);
    msg.data[0] = 253;
    while(1) {
        led1 = !led1;