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.
9 years ago.
lpc1768 with mcp2515 spi can bus
I want to communicate with the mcp2515 can bus with lpc1768 how can i do it?
1 Answer
8 years, 10 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
Seeed Studios CAN https://developer.mbed.org/components/Seeed-Studios-CAN-BUS-Shield/
and
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 )
Note
- Mbed 1768 working on 3.3V and MBP2515 working on 5V. i use 5V- 3.3V bidirectional level sifters. https://www.sparkfun.com/products/12009
/media/uploads/sameera0824/mbed_can.pdf
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};
can.frequency(125000);
CANMessage msg(2002,data,1);
msg.data[0] = 253;
while(1) {
can.write(&msg);
pc.printf("Send:%d\r\n",msg.data[0]);
led1 = !led1;
wait(0.5);
}
}
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