EmbeddedRelated.com
Forums

CAN interfacing with lpc2148 via spi

Started by pavan123 6 years ago3 replieslatest reply 6 years ago184 views

hello all,
I am interfacing mcp2515 can controller with lpc2148 via spi. and for this i need to write the code but i do not know how to write code for this interfacing??
do i need some library file for interfacing mcp2515 with lpc2148? if yes then where from i can get this?
I got some library files but they are for arduino or some other microcontroller which i can not understand.Please help me,i am stuck on this since 3 days.

[ - ]
Reply by mr_banditOctober 21, 2018

Look at https://en.wikipedia.org/wiki/Serial_Peripheral_In...

You are the master. the CAN controller is the slave.

I have not used the LPC2148, but the datasheet says

Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus (400 kbit/s), SPI and SSP with buffering and variable data length capabilities

The two things you need to set on the master are the bit order (MS vs LS bit first) and the clock edge. These are dictated by the slave.

So - read both datasheets - the CAN controller and the micro - at its SPI interface. Set the clock as slow as you can - SPI does not specify how slow the clock can wiggle - it could be once a week.

Do you have a scope?

If the SPI peripheral is too confusing, you can bit-bang the interface. In that case, you can use LEDs on the clock, data and slave select lines to see what is happening, and put in a big delay for the clock (like 1..2 seconds)

The CAN controller is a fairly complex chip. I would suggest getting a very simple SPI chip - look at adafruit or sparkfun for their breakout boards with SPI chips. Tackle one problem at a time.

Keep your spirits up. SPI and I2C are used in many embedded systems. Once you have them down, you can go onto interfacing with more complex stuff.


[ - ]
Reply by pavan123October 21, 2018

hello sir,
I need to interface can controller ! i know little bit about spi but i don't know how to interface can with spi. because i think there has to be some library file which defines the functions for reading and writting can controller.
please help me out with this particular question 

[ - ]
Reply by DilbertoOctober 21, 2018

Hi, pavan123!

As stated by mr_bandit, "... read both datasheets - the CAN controller and the micro" to get used with both chips. And follow his other advices.

Also, as this microcontroller is quite old, it's not included in LPCOpen, as far as I know, but Philips ( the former name of NxP ) has an application note with examples of using I2C, which can be useful. If you think it's worthwhile to give it a try, see at Philips AN10369.

Cheers!