AP_Periph Battery Cell Monitor not sending AUX CAN messages

Hi All,

I’m building an AP_Periph F303 based battery monitor but am having some trouble getting it to work correctly. My overall setup is an STM32F303 talking over SMBus (I2C) to an Atmel MCU which reads voltages etc and returns the correct values for each when requested.

When I plug my Atmel into a FC directly over i2c and set the BATT_TYPE to 7 (SMBus Generic) everything appears correctly on the ground station. I get overall pack voltage, individual cell voltages, current and temperature. This leads me to believe that the code I have custom written for the Atmel works so that the SMBus library is happy.

However when using an AP_Periph Can node in between the Atmel and the FC I start to get issues. I no longer get individual cell voltages, but the overall voltage is displayed for cell 1. Current and temperature work as expected. When looking at DroneCAN GUI I can see that I am getting “batteryinfo” messages correctly but no “batteryinfoaux” messages which contain the missing data but I just can’t work out why they aren’t sending!

I built a firmware based on the F303-periph which just uses the .inc file in my hwdef and an extra line to include battery support (is this correct or do I need some specific smbus define?)

include …/f303-periph/hwdef.inc
define HAL_PERIPH_ENABLE_BATTERY

I’ve done some digging around the code and added some debug statements, but I only understand the code flow enough to add that to the SMbus library, not into the CAN send library (where is that please?). I found ardupilot/Tools/AP_Periph/can.cpp which looks like it contains lots of constructors for packet types (including the normal batteryinfo) but none for batteryinfoaux.

I can see from the Atmel side that the CAN node is requesting the same hex codes through AP_Periph as a direct FC so I am thinking that I really need to start looking at the CAN sending side. Any advice?

Byte requests from AP_Periph on boot:

hey @radman, did you made your own PCB? did you need to make any changes in the AP_periph to make it work with your board?

Hi,

I did make my own board and there’s details on my wiki wiki.cbunmanned.com

I ended up writing some more code to make the node send the battery aux messages aswell which can be found here (I think). ardupilot/Tools/AP_Periph/battery.cpp at 7f0f85124308e9fc438ee02ebd9c173aa99a68d9 · ArduPilot/ardupilot · GitHub

hey. thanks for the reply i was actually look to make exactly what you have made and also get into PCB designing through this project. do you mind answering few question I am still trying to wrap my mind around CAN and DroneCAN stuff. for my application I need to convert 4-5 i2c based and 2-3 uart based rangefinder into DroneCAN. your designed board should be able to that pretty easily I think looking at the mcu. for the hardware AP_periph firmware is used but how do we change stuff in that like I will be having 4-5 i2c based sensors and all. do you have schematic for the the board ?? i made my schematic using the open source dronecan adapter node but the mcu is STM32F103CBT6 and your design looks interesting!
thank you