CanBus MCP2515 SPI

basically miscellaneous, if it doesn't fit another sub-forum enter it here, we might even promote it to its own sub-forum
Post Reply
kochevnik
Posts: 24
Joined: Sat Jun 15, 2013 3:27 pm

CanBus MCP2515 SPI

Post by kochevnik »

In the end I would like to wire up my entire (future) farm with various items. I have looked at wireless XRF modules, RS232, wifi, extended usb etc. I've kind of put the decision/work off for a long time working on other things, but now my other BChip project is requiring long distance comms ( 100 + yards). In doing some more googling canbus seemed to be the best bet - so I found the MCP canbus chips - work off SPI, so I ordered some and am going to see if I can get them to work. I have to get SPI to work first so I'm going to start asking some basic questions along those lines and then once that's sorted I will move on to the actual canbus chips.

I've searched and read every thread here with SPI in it & the one canbus thread & every thing in the help too but still have some newbie questions.

So first (dumb) question - let's say I just want to hook up two BChips to talk to each other using SPI. SPI is a four wire interface - CSpin, INpin, CLKpin, OUTpin - does it matter which pins I use ? Are the I2C pins (SCL & SDA) good for this, bad idea, what ? Are there any pins that would be better or worse ? Dont want to use the ADC pins if I can help it of course.

Is the internal oscillator going to work ok with this setup ? Or is an external one needed ?

And last dumb question - the slave can never initiate a conversation - does that mean the master has to continually loop thru a SPIIN to see if the slave wants to send something ? In the canbus setup each BChip would be a master and each CAN controller chip (MCP2515) would be the slave - so data comes into the 2515 chip and how is it going to let the BChip know it thru SPI that it has data out there ready for it to read ? I know interrupts are possible, but I dont see how that could work with just the 4 SPI lines.

ETA - I see on the datasheet for the 2515 that there is an interrupt pin (pin12 on data sheet ?)

http://ww1.microchip.com/downloads/en/d ... 21801d.pdf

So RX0BF RX1BF TX0RTS TX1RTS TX2RTS - these are all special interrupt pins ? So I would need to use SPI to configure the 2515 chip so use the interrupts the way I want when it powers up ?

I see the interrupt SUB code in the help - I will mess with that to see if I can get it to work - the help files dont talk about the BChip or 1124 specifically, any things I need to be aware of when using that code on the BChip ?



basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

Re: CanBus MCP2515 SPI

Post by basicchip »

The SPI routines in SPI.bas are bit-banged. This achieves simplicity and flexibility at the expense of performance (it lets you use any 4 pins).

Of all the peripherals in the LPC series, the SPI is actually probably the easiest to use for generating SCLK, MISO and MOSI. Most people end up generating the SSEL using a GPIO, though is some cases the built in version does what you need. Part of this is due to the "standard" of SPI is not really a standard at all, it just means you have some serial protocol with clock, data-out and data-in.

So for high performance masters and especially in any case where you want to be a slave, the hardware SPI is a good way to go.

The LPC1756 has 2 CAN controllers, the LPC1751 has one. So really if you want to do CAN, that is the way to go, all you need is an outside transceiver. It depends on what you are trying to do. If all you want is a high speed link to something 100 meters away, there may be quicker ways to that end (RS-485). Actually one of our current contracts is to add CAN support to a custom board we have designed for a client. It is probably a few months away from being a priority (other interfaces ahead of it), but we may end up porting some DeviceNet or similar protocol to an LPC4078 (same CAN hardware). This work is being done in BASIC, as the target customer wants to allow simple in the field application changes.

Post Reply