2024-07-17 02:17 PM - edited 2024-07-17 11:11 PM
Hello,
I am using the P-NUCLEO-IHM03 motor control kit together with a CubeMars GL40 KV70 motor with integrated AS5048A magnetic position encoder. I want to use the AS5048A position encoder in my project, instead of the position estimator implemented by ST. To do that, I need to configure and implement SPI communication.
My issue is that when I initiate SPI communication through the function HAL_SPI_TransmitReceive_IT, a driver protection fault is triggered and the motor won't start when I press the Start (blue) button. The following line of code triggers the fault:
statusHalSpi = HAL_SPI_TransmitReceive_IT(&hspi1,spiTransmitBuffer,spiReceiveBuffer,3);
When I remove this line of code, everything works fine, the motor will simply start up and run.
The encoder uses SPI comm. in packages of 16 bits, thus I configured SPI in CubeMX with 16 bits datasize. Baud rate is 1.33 Mbits/s, CPOL is low, CPHA is 2 Edge. There is no issue with the SPI communication, I measured it with an oscilloscope and it seems to work fine. I'm attaching the file "encoder_as5048a_speed_pos_fdbk.c", which contains the code for the SPI comm. The function in this file, ENC_AS5048A_CalcAngle, is called in the high frequency task TSK_HighFrequencyTask, which only gets called when the Start (blue) button is pressed. As soon as I press the button, the fault is triggered, and the motor doesn't start.
I did some debugging, and what I figured out is that the driver protection fault is triggered by Break 2 of TIM1, which has as source pin PA11 (M1_DP), which is connected to pin EN\FAULT of the STSPIN830 motor driver chip. I measured the voltage on this pin and indeed the voltage drops from 3.3 V to 0 V for a very short time and the red D1 fault led goes ON briefly. By looking into the documentation of STSPIN830, it looks to me that an overcurrent or short circuit device protection kicks in, which forces the EN\FAULT input pin to low and disables the power stage. I measured the current on the motor lines and there seems to be no overcurrent, the current stays on 0 A. Also, there is no way of getting the information about which driver protection fault kicks in from the STSPIN830 chip (nothing mentioned in the datasheet).
I'm having a hard time understanding what is going on, and how is it possible that HAL SPI can influence the motor driver. Please help. 🙂