ESP32/STM32/Raspberry PI – all in one dev kit

Starting at left is a ESP32 Breakout board, then one of my own STM32F405RG breakout boards, a 5″ HDMI, Wireless keyboard and Raspberry PI 3 with my 5 port Hat – and your right it’s a different Hat with screw terminals, so I do have 2 x 5 port Hat’s working.

 What I will do here is to wire up SPI between ESP32 & STM32 for testing, and I can add CAN breakout boards etc getting the boards to communicate. The only drawback here is that I can only use one SWD at the time, but I will get around that.

Raspberry PI Wiring

This shows a Raspberry PI 3 with a Communication Hat, Display and mini keyboard. This is basically all the hardware I need for a very advanced CAN Adapter & Analyzer. The main reasons I am skeptical is the wiring needed on this solution. Using a HDMI display is very powerfully, but you need a large project box for this. The total size and cost of the adapter adds up. I seriously which someone would create a more box-able display solution for Raspberry PI – one that take into account the Hat option.

Raspberry PI – 3 x RS485 & 2 x CAN Hat

This is a 5 port communication Hat mounted on a Raspberry PI 3. It contains 3 x RS485 and 2 x CAN ports. The design is not new for readers of this blog, but it is actually the first time I assemble rev 1.1 – just before I am about to order rev 1.2.

The colorfully display is because I am using 1206 led’s and saving old parts – all components on this was re-used from rev 1.0 boards. What amused me a bit is that as I mounted the MCU and switched Power on the old test program still worked. I have yet not broken a STM32 by soldering it on/off boards – quite impressive actually.

Functionally this Hat is ok, but mechanically I ordered a few Hat’s before I checked the drilling holes exactly, so rev 1.2 will correct this. I will also replace 0804 and 1206 with 0603 components + 2 leds per port is a bit overkill. I think if I reduce to 1 per port and mount them on the side that is better. Also cleaning up the line driver and replacing the 3P connector with a 4P for RS-X 12V + differential signal. I might have to make this a 2+2 port for that purpose.

 I also want to do an experiment. Both CAN and RS485 are differential signaling, so I wonder if I can get RS485 to work with a CAN Tranceiver and what quality it would have? The issue is that if I can do this I can more or less make the 2 CAN ports switchable between CAN & RS485. It is worth a try!

RS485 & CAN Line Interface

I am just assembling one of my first Raspberry PI Hat’s With a 3 x RS485 and 2 x CAN for testing. The circuits below is what I used at the time. Rev 1.2 will use 3.3V only and remove the components crossed in Red.

It is a common error to add protection towards ground, but what you actually do is to force ground to be part of the signal. RS485 and CAN are both differential signals that should not need ground. If you need protection use the galvanic Versions! Even worse, the “protection” will disturb your signal quality at higher speeds.

Another issue here is that RE and DE is connected – this works, but it prevents some options – etc reading as you send to detect conflicts and disabling both sending and receiving etc.

The rev 1.1 also used some 1206 Components and a mix of 3.3V and 5V, as well as a XC6206 3.3V regulator in SO23 package. This will all be replaced with AMS1117, 0603 packages and 3.3V Components. Rev 1.1 also had the mistake that I implemented ground plane on both sides – it is not realy a mistake as such, but it makes it harder to assemble prototypes by hand.

Galvanic RS485/CAN

Since we talk about galvanic RS485 & CAN Adapter’s I guess it is time to visit this project as well. The universal adapter below was something I started last time I needed CAN. This adds W5500 and ESP12-E + NRF in addition to CAN & RS485.

I never made a revision of this Board, but it served a purpose to test CH340G, STM32F405RG and ADM2582E together. The Board above with the added coil was after my struggle to get STM32 ticking at 168Mhz.

I never tested ADM3053, so that is what I will do next. I see no point sending for a new PCB including parts of this design before I have completed this test.

As for the adapter above – this has in many ways been a big success because I have corrected and re-used a lot of the design I did here, but I will not finish this adapter as such. ESP32 is so much better than the ESP12 or ESP8266 based options. I do however have things left to test on this Board.

Why not Raspberry PI as CAN Adapter?

This is the rev 1.2 of my 5 port Hat with 3 x RS485 and 2 x CAN. I never ordered this PCB because it is only mechanical changes from Rev 1.1. But, using this or a galvanic version with Raspberry PI is an option for my CAN Adaptor plans.

The advantages with this is that Raspberry PI have an excellent HMI option. It would also enable a PLC style adapter where you add on what you need – but it would be a much larger solution as well.

The size difference from a packed, single board solution is not dramatic and it offer other options as you get a proper display, keyboard and a full Linix computer to back it up.

Not so mini CAN Adapter

This is the same drawing as the previous post, but I added the TF Card option. Basically this is a small mini-computer Complete With display, keyboard (in the display), Wifi, Storage etc. Just for the record it actually got more “disk” and RAM than my first IBM Compatible PC.

I have never done a TF-card Interface, but I have some breakout boards laying around. As mention you can actually buy this on the NET known as “CAN32” for ca 39.-USD. It comes as a specialized breakout Board for ESP32. But, the good things is that I can easily assemble this on a vero Board to get started – and since someone else have made firmware for this we can use their project and modify it as a starting point.

What I want to achieve here is a CAN Tesrter, Analyzer & Adapter – all in one. I need CAN connectivity and I need to see what happens on several CAN Networks simultaneously. As mentioned earlier I will use a STM32 to deal with CAN and make this galvanically isolated later, but this is something I can wire up and start with while waiting for PCB’s.

Assuming the TF Board Works out I should also add this to the larger Board. I also think I want to Mount the display on ESP32 and if I have Space add the 16 analogue IO lines from STM32 as a separate port.

This design start to make a bit sence because we now use ESP32 for Wifi, HMI, Storage, while we leave CAN and IO to STM32.

The last part of this project is boxing it. In fact, we could use Bluetooth to connect to our phones/tablets as HMI rather than adding a UART based HMI as well. With Wifi I can obviously connect my laptop as HMI, but the reason I explore other options is because my laptop usually is occupied otherwise and I need the extra screen. Fiddling around swapping screens and turning Smart Phones orTablets on/off is not always the most convenient choice, so having a physical display on the adapter is a priority IMO.

It’s only one flaw here – I am making all this for CAN while I myself am a heavy user of RS485/RS-X. The STM32 I use here have 5(6) UART’s, and if I commit on using STM32F405RG I have 2 x 10Mbps RS485 capable ports that will be very handy for sniffing on my PLC system later. The only thing is that I can’t use galvanic isolation at that speed, but I can live with that.  Woops – wrong! Checking the datasheet of ADM2582E it supports data rate to 16Mbps!

Puh – I better stop writing before I add more into this – my only concern here is what speed I can get between ESP32 and STM32 on UART or SPI. I am hoping on 40ich Mbps on SPI, but that is yet a unknown that I need to investigate. I think ESP32 is capable of this, but it’s more if I am capable of using it – lets see.

CAN32/CANMini

It exist a project that simply add a CAN Tranceiver to a special ESP32 dev Board – called CAN32. This uses the CAN on ESP32 and provide a Wifi based CAN Interface. I have a few CAN breakout Boards and Nextion displays so I want to assemble one of these. The main drawbacks With this is (1) I am unsure about the quality of CAN on ESP32, and (2) it don’t uses a galvanic isolation.

Galvanic isolation complicate things a bit. You don’t really need it for Wifi usage, but you seriously should have it if you connect the USB to your PC With industrial equipment on the other side.

CAN Adapter with Wifi

I need a CAN adapter for a special job and decided to build my own. I use ESP32 to get Wifi, Bluetooth and USB Connectivity, but I decided on adding a STM32 to get dual CAN Connectivity. ESP32 do have an undocumented CAN port as well, but I assume ExpressIF have their reasons for hiding it. The display is because I also want to use this as an Analyzer sniffing. And as a adapter of this type will be connecting to industrial equipment I also want the galvanic issolation.

This will cost me around 20.- USD in components + display and boxing, but to buy something like this I would probably have to pay 500.- to 1000.- USD if I could find one.

I have listed both UART and SPI for communication between ESP32 and STM32 because I am unsure about both on ESP32. I know they exist, but have no experience with them so I can as well just Connect both . I also added a battery option on the PSU.

New DRV8313 BLDC Controller

My previous DRV8313 design used the larger 64 pin F105/F405 MCU and a more complicated sensor design. What I could do is to use the smaller F303 that is 48 pin and fokus on hall sensor driven motors to get size down. The issue is that current sensing is very difficult/unreliable for small motors on low speeds, so ignoring these sensors will simplify the design – reduce size.  The challenge here is that I am not very good at compromizing – I don’t want this BLDC for a project, I want it because I want to experiment with the design and coding – so I want “everything” on it like a spoiled child …

This last draft is the same as before, but I replace F405/F105 with F303 so I can take advantage of it’s programmable Op-Amps to scale current sensing to the motor. I am considering a version where I cut DC Rail, current Sensors and BEMF Sensors as well, but for now I can just design them in and avoid assembling them.

The issue with current sensors is that it’s a huge difference between 2.5A and 50mA. If you dimension the sensor for 2.5A and 500mV you will typically read 10mV on 50mA. The signal get so weak that it risk drowing in noise. So to compensate for this I need to add filters and amplifiers. This also makes it more challenging to control motors on low speeds, while current sensing is excellent on high speeds where you get strong current signals. STM32F303 can compensate for this by using 3  programmable, built in op-amps that amplify the signal. To be honest it is actually far more complicated to make a small BLDC Controller than making a large one.

While I like the STM32F030F4 due to their size they make no sence in this case. I need a 48pin package so I get all 3-phase motor pins and I need the programmable op-amp build into STM32F303.