SPI to CAN bus mcu? - Page 1
Forum section: electronics / general

author: WaldPinkler
author_rank: Contributor
timestamp: September 25, 2021, 08:49:25 am
content: I've been enjoying a new found electronics hobby. I wanted to make a current sense device that communicates over CAN bus.I need an mcu for that. I spent many hours looking at them and downloading IDEs etc. It feels so overwhelming now. I have played with arduinos and esp32s but wanted to try something lower level. Have programming experience.I've made a PCB for an ina229 current sense ic that fits on a shunt. SPI communication. I was hoping to connect the MCU and CAN transceiver pcb with some u-shaped header pins.Any recommendations on an MCU? Preferably something that can be hand soldered. Living on a boat so 700W for a hot air gun burns up my batteries.My first pcb, so any critique there is welcome.

author: jpanhalt
author_rank: Super Contributor
timestamp: September 25, 2021, 10:08:17 am
content: Microchip has CAN bus controllers that are SPI (e.g., MCP25625 and MCP2515). Other vendors (e.g., Maxim) do too.So, keeping it really simple, all you probably need is an 8-bit MCU with hardware SPI. Of course you can go up from there.

author: WaldPinkler
author_rank: Contributor
timestamp: September 25, 2021, 10:41:05 am
content: I looked at STM8S, PIC, AVR, ATTiny, MSP430. Just pick one? I go around in circles. I was trying to find one that was easy to get started without having to get much extra hardware, easy to solder, then the software side being accessable.

author: jpanhalt
author_rank: Super Contributor
timestamp: September 25, 2021, 11:18:26 am
content: Any of them will work. It's a competitive market. It all depends on what you have ("tool chain") and are familiar with programming. I started with Microchip PIC's. The 8-bit units are easy to program in Assembly, and you can pick ones with fewer peripherals to make starting simple. The 12F1840 is an 8-pin device. 16F1xxx are also simple (almost identical in some cases) and have more ports/pins. Most are still available in DIP or SOIC packages, which are easy to solder and can even be used with economical sockets or on a breadboard.If you stay with one brand, going to more complex chips is a little easier for setup. You don't have to use all of the capabilities of any chip. In the PIC series, I stay with the 1xF1xxx (14-bit core) and pick one with enough ports/pins for what I need. My tool chain (MPLAB 8.92) is limited. There are even newer ones that are not compatible with that tool. I would stay away from the really old ones with a 12-bit core, as they do not have interrupts and have a more limited instruction set.

author: sicco
author_rank: Regular Contributor
timestamp: September 25, 2021, 09:07:20 pm
content: Can can be done with many many microcontrollers. Last year I would have picked a Microchip PIC and MPLAB, but now, if i were you, I’d get a Teensy module. Or something else Arduino ish. Especially if hand soldering is a given…Probably wise for you to opt for galvanic isolation between your CAN host and the INA229. Consider isolated CAN transceiver ic’s. If you can get your hands on them, because they’re sold out globally like any chip….

author: IDEngineer
author_rank: Super Contributor
timestamp: September 27, 2021, 08:03:51 am
content: Many PIC's have an integrated CAN controller right on the die, eliminating the need to use SPI and giving you much easier and faster communication with all the registers. Very highly recommended. Then you just need a CAN PHY chip, which are available from numerous sources with a huge array of features such as isolation if you wish.

author: Scrts
author_rank: Frequent Contributor
timestamp: September 27, 2021, 07:05:16 pm
content: Personally, I would go with a microcontroller that has the most examples and tutorials about the task I want to accomplish.So you can check STM32:There are also plenty of examples with STM32 SPI Master, i.e.:

author: WaldPinkler
author_rank: Contributor
timestamp: September 28, 2021, 09:31:07 pm
content: I was thinking stm32 is overkill for configuring INA229 sensor then reading registers by SPI and sending them by CAN.Yes it could be easy. I could just hook it up to my esp32 board or arduino board but I also wanted to get everything under the cover of the shunt approx 30x40mm.

author: fchk
author_rank: Frequent Contributor
timestamp: September 29, 2021, 10:50:39 am
content: Quote from: WaldPinkler on September 25, 2021, 08:49:25 amhttps://www.microchip.com/en-us/product/dsPIC33CK256MP502Has CAN-FD, only 28 pins (SSOP), and -most important: Digikey has 2080 pieces ready to ship. (DSPIC33CK256MP502T-I/SSCT-ND)You will need a CAN-FD transceiver. E.g.: TJR1443AT/0Z. Digikey has 2121 pieces ready to ship. (568-TJR1443AT/0ZCT-ND).fchk

author: JPortici
author_rank: Super Contributor
timestamp: September 29, 2021, 11:03:18 am
content: Quote from: fchk on September 29, 2021, 10:50:39 amI would not recommend that part for beginners in microcontrollers and can controllers. That can controller require more effort than usual to set up and to interface with.. I'd rather suggest one of the older dsPICs (33EV which is 5V, or 33EP MU series which has also USB) or the PIC18F K83 series, or the PIC32MX 530 series since they all use an older, simpler peripheral (same as the MCP2515)... which is more or less the same across all devices so it's easier to port the code

author: fchk
author_rank: Frequent Contributor
timestamp: September 29, 2021, 11:37:51 am
content: Quote from: JPortici on September 29, 2021, 11:03:18 amMaybe. Problem is availability. My suggestions are actually buyable, and that's what counts when you start a project in these days.fchk

author: JPortici
author_rank: Super Contributor
timestamp: September 29, 2021, 03:15:55 pm
content: Meh, stopped worrying about that for now. Our numbers mean that we can actually find stuff from distributors (every few days a reel or two of parts appear, we buy what we need plus some to set aside for the following order n months from now)Then there's the fact that what you propose could already be gone by the time he decides to use it, though we are not seeing that recently (it used to be that we had to instant buy, components would disappear in an hour or less)Availability is also not a problem for single, small quantity hobby project (which from what i understand is the case here)Bonus: microchip IS less affected than other manufacturers, one of the perks of having their own fabs. Prototype quantities ("samples") are still available AFAIK and their lead times have already started shortening

author: IDEngineer
author_rank: Super Contributor
timestamp: September 29, 2021, 03:47:23 pm
content: Quote from: fchk on September 29, 2021, 11:37:51 amTrue, but a quick search at (just) DigiKey reveals 24 versions of the PIC18 family in stock that have throughhole packages and contain a CAN peripheral. They start at $2.41 in quantity one for a 28DIP package. Refinement of the search is left as an exercise for the OP, but the parts ARE out there in conveniently breadboardable packages.