SPI to CAN converter with ability to control SPI devices

Thread Starter

mahmudsalamati

Joined May 7, 2017
6
Hello

I'm doing a project in which voltage and current measurements are needed to be converted to CAN 2. I'm searching for a microcontroller that do this task in the simplest possible scheme. voltage measurement board is a special chip and requires to be controlled by some specific set of commands. So, I cannot use options like MCP2515 and need to choose a suitable microcontroller. Do you guys have any suggestion? If yes please let me know as I need to make a decision very fast.

Thanks,
Mahmoud
 

JohnInTX

Joined Jun 26, 2012
4,787
I have used the PIC18F4685 in several CAN bridge applications. Add a driver chip and of course the firmware and you are ready to go. I did not use any libraries and wrote it in assembler but the XC8 compiler would be a good choice,too. It sounds like the firmware basically gets data from the SPI, decodes it and sends it to the proper CAN node?

Here is Microchip's CAN page with all of their CAN processors and development boards etc.
http://www.microchip.com/design-centers/can

A block diagram would be most helpful to further understand what you are needing to do.

Depending on your experience level you might also take a look at MikroC for PIC for their extensive libraries and ease of use or something in the Arduino class of ready made boards.

Welcome to AAC and good luck.
 
Last edited:

atferrari

Joined Jan 6, 2004
4,770
I have used the PIC18F4685 in several CAN bridge applications. Add a driver chip and of course the firmware and you are ready to go. I did not use any libraries and wrote it in assembler but the XC8 compiler would be a good choice,too. It sounds like the firmware basically gets data from the SPI, decodes it and sends it to the proper CAN node?
Hola John,

What did you use for the ADC? How many samples per (half?) period?
 

JohnInTX

Joined Jun 26, 2012
4,787
What did you use for the ADC? How many samples per (half?) period?
It used internal ADC for things like board temperature. The main function was to support legacy CAN based industrial controls from newer nonCAN hosts. Mostly a big data shuffler although it had enough power left to do lots more including an interactive terminal.
 

Thread Starter

mahmudsalamati

Joined May 7, 2017
6
Hola John,

What did you use for the ADC? How many samples per (half?) period?
Hello

For my case, Analog voltage values are converted to SPI by a battery demonstration chip (LTC6804-1). It has 16 bits resolution and I need to monitor voltages every 10 ms. So, do you have any specific advice for me?

Thanks
 

Papabravo

Joined Feb 24, 2006
21,225
Hello

For my case, Analog voltage values are converted to SPI by a battery demonstration chip (LTC6804-1). It has 16 bits resolution and I need to monitor voltages every 10 ms. So, do you have any specific advice for me?

Thanks
Pretty much any device you come across will have very little trouble meeting those requirements. 10 msec is more than enough time to do an SPI transaction and send it out over the CAN bus.
 

Thread Starter

mahmudsalamati

Joined May 7, 2017
6
Hello John

Thanks for your complete response. I have attached my diagram for my circuit to this post. So, one thing that I don't understand is that, when microcontrollers like PIC18F4685 support CAN and SPI, then why many demonstration boards by microchip use MCP2515 and PIC18F4685. Any explanation would be appreciated.
SPI_CAN.jpg
 

JohnInTX

Joined Jun 26, 2012
4,787
So, one thing that I don't understand is that, when microcontrollers like PIC18F4685 support CAN and SPI, then why many demonstration boards by microchip use MCP2515 and PIC18F4685. Any explanation would be appreciated.
View attachment 126224
The 18F4685 is a PIC with an EnhancedCAN controller built in. You send/receive messages over CAN by loading internal Special Function Registers like you would write to any internal RAM or SFR. When you load the CAN message and set 'send', the internal ECAN controller does the rest according to the CAN protocol. You don't need the MCP2525 with the 18F4685.

The MCP2515 is a complete CAN controller in a stand-alone chip that can be used with any microcontroller. Since it is external to the chip, SPI is used as the mechanism to read/write the 2515's registers.

I expect that the reason the CAN demo boards have both chips is so that you can experiment with an internal CAN controller (4685) and an external one (MCP2515). Note that in any given family and package size, the PIC pinouts are very similar if not identical. That means you could try the MCP2515 with something like a PIC18F4520 which is a pin-compatible PIC to the 4685 but without the internal CAN controller. More bang for your demo buck.

Either approach would work for your application. Personally, I would lean towards the internal CAN controller. You already have action on your SPI bus. If you put the CAN controller on the SPI bus that is just more stuff to sort out and find time to do. You have to learn the CAN register set anyway, why add the hassle of getting to it via SPI? Just my .02

Note that either CAN controller still requires a driver chip like the MCP2551. Those handle the actual bit driving with arbitration etc. on the CAN bus, provide fault protection, slew rate control etc etc.

Hope that answers your question. FWIW, your diagram is pretty much what I had in mind, too.
 
Last edited:

atferrari

Joined Jan 6, 2004
4,770
It used internal ADC for things like board temperature. The main function was to support legacy CAN based industrial controls from newer nonCAN hosts. Mostly a big data shuffler although it had enough power left to do lots more including an interactive terminal.
Clear enough. I supposed OP was dealing with AC, thus my question about "samples per (half?) period".

Hello

For my case, Analog voltage values are converted to SPI by a battery demonstration chip (LTC6804-1). It has 16 bits resolution and I need to monitor voltages every 10 ms. So, do you have any specific advice for me?

Thanks
I implemented a basic 3-nodes network using 18F4585 micros, in pure assembler. Of course I needed to use (MCP 2551 like) transceivers.

I would go the simpler way as John explained and, no matter what micro, get used used to check all erratas. That will save hair pulling and testing time.
 

Thread Starter

mahmudsalamati

Joined May 7, 2017
6
Clear enough. I supposed OP was dealing with AC, thus my question about "samples per (half?) period".



I implemented a basic 3-nodes network using 18F4585 micros, in pure assembler. Of course I needed to use (MCP 2551 like) transceivers.

I would go the simpler way as John explained and, no matter what micro, get used used to check all erratas. That will save hair pulling and testing time.

Thanks for your answer. So, if I want to make save in time do you know any specific evaluation board with a microcontroller capable of implementing control area networks?

Kind Regards
 

Thread Starter

mahmudsalamati

Joined May 7, 2017
6
The 18F4685 is a PIC with an EnhancedCAN controller built in. You send/receive messages over CAN by loading internal Special Function Registers like you would write to any internal RAM or SFR. When you load the CAN message and set 'send', the internal ECAN controller does the rest according to the CAN protocol. You don't need the MCP2525 with the 18F4685.

The MCP2515 is a complete CAN controller in a stand-alone chip that can be used with any microcontroller. Since it is external to the chip, SPI is used as the mechanism to read/write the 2515's registers.

I expect that the reason the CAN demo boards have both chips is so that you can experiment with an internal CAN controller (4685) and an external one (MCP2515). Note that in any given family and package size, the PIC pinouts are very similar if not identical. That means you could try the MCP2515 with something like a PIC18F4520 which is a pin-compatible PIC to the 4685 but without the internal CAN controller. More bang for your demo buck.

Either approach would work for your application. Personally, I would lean towards the internal CAN controller. You already have action on your SPI bus. If you put the CAN controller on the SPI bus that is just more stuff to sort out and find time to do. You have to learn the CAN register set anyway, why add the hassle of getting to it via SPI? Just my .02

Note that either CAN controller still requires a driver chip like the MCP2551. Those handle the actual bit driving with arbitration etc. on the CAN bus, provide fault protection, slew rate control etc etc.

Hope that answers your question. FWIW, your diagram is pretty much what I had in mind, too.
Your answer helped me much to find a much better understanding about requirements. Thanks man!
I didn't find any evaluation board for PIC18f4685...other choices seem to use PICs not supporting CAN and using MCP2515 to handle CAN...Do you know any evaluation board which removes circuit development time and works for my scheme?
 

JohnInTX

Joined Jun 26, 2012
4,787
Your answer helped me much to find a much better understanding about requirements. Thanks man!
I didn't find any evaluation board for PIC18f4685...other choices seem to use PICs not supporting CAN and using MCP2515 to handle CAN...Do you know any evaluation board which removes circuit development time and works for my scheme?
You are welcome. Re: development boards, I used CAN-LIN 2 boards that ran 40pin DIPs. Nice to have 2 on the board. Explorer 16 has a CAN PICtail board but that's for 24F, dsPIC and PIC32. You could really use any PICDEM board that took a 28/40 pin DIP that fit a CAN PIC pinout, scab on the transceiver and have at it. CAN-LIN 2 software had/has? a rudimentary bus analyzer that was OK for simple stuff. You might be better just wiring up a breadboard and spending the money on a decent analyzer.

Good luck!
 

atferrari

Joined Jan 6, 2004
4,770
Thanks for your answer. So, if I want to make save in time do you know any specific evaluation board with a microcontroller capable of implementing control area networks?

Kind Regards
Sorry but never used one. Just breadboard and progressive debugging to minimize ghost-chasing. Anyway, John is the one who knows here.

Buena suerte.
 

Thread Starter

mahmudsalamati

Joined May 7, 2017
6
You are welcome. Re: development boards, I used CAN-LIN 2 boards that ran 40pin DIPs. Nice to have 2 on the board. Explorer 16 has a CAN PICtail board but that's for 24F, dsPIC and PIC32. You could really use any PICDEM board that took a 28/40 pin DIP that fit a CAN PIC pinout, scab on the transceiver and have at it. CAN-LIN 2 software had/has? a rudimentary bus analyzer that was OK for simple stuff. You might be better just wiring up a breadboard and spending the money on a decent analyzer.

Good luck!
I understand that it seems easier (and cheaper) to use breadboard to do all wirings; but, for my employee, time matters much more than money! I did a lot of search and finally, I'm going to choose between these two options:
1- DVK90CAN1 (development Kit for AT90CAN128)
2- Arduino CAN shield and Arduino board itself.

Does it seem good enough?
 

JohnInTX

Joined Jun 26, 2012
4,787
I understand that it seems easier (and cheaper) to use breadboard to do all wirings; but, for my employee, time matters much more than money! I did a lot of search and finally, I'm going to choose between these two options:
1- DVK90CAN1 (development Kit for AT90CAN128)
2- Arduino CAN shield and Arduino board itself.

Does it seem good enough?
The Atmel board looks pretty good. Pretty much everything you'd need to do it on one board plus extras like RS232 etc. You would need to get up on the development system (IDE, compiler, debugger, etc.). Take a look at the software and see if it has decent library support for at least the CAN system. I am not really familiar with Atmel debugging but the manual for the board indicates that you can use their JTAG or ICE50. Check on the costs of those. Call me lazy (or experienced) but I wouldn't get into anything without at least some hardware debugging support.

I can't really advise you much on the Arduino option. The nice thing about them is that the functionality just snaps together and it has a good programming environment. It probably has extensive CAN and SPI libraries. Like before, I would try look at some sample code using those modules and see how it looks.

For either, you would want the library code to allow for buffering at least, interrupt-driven comms into buffers both ways for both CAN and SPI would be best. You'd have to drill down into the documentation/code examples to see.

Maybe some of our Arduino / Atmel guys will have more specific info.

Good luck!
 
Top