AS5048A connected to STM32 only returning 0 angle

When I connected a AS5048A to an UNO and ran the example program magnetic_sensor_spi_example , it worked perfectly, after changing one line…

MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, 10);

When I swapped the UNO for a STM32 F446RE, the serial monitor only reports zero angle. I tried powering the AS5048A with 5v, 3.3v and 3.3v after connecting the 3.3v pin and 5v pin together on the AS5048A (as the datasheet recommends for 3.3v operation).

I get the same results with and without the SimpleFOC shield. I tried both a AS5048A dev board and a Cubemars GL30 motor.

Any suggestions on how to proceed ? I can dust off my little Saleae logic analyzer that can decode SPI, but am a bit reluctant to get into the weeds of debugging the SPI transfers.


Hi @pleaback the is what works for me when using

///SPI 1 (AS5048A)
#define MOSI_ENC PB15    
#define MISO_ENC PB14    
#define CLK_ENC  PB13    
#define CS_ENC   PB12    

MagneticSensorSPIConfig_s AS5048A_SPI_Config{
    .spi_mode = SPI_MODE1,
    .clock_speed = 10000000,
    .bit_resolution = 14,
    .angle_register = 0x3FFF,
    .data_start_bit = 13,
    .command_rw_bit = 14,
    .command_parity_bit = 15

MagneticSensorSPI sensor = MagneticSensorSPI(AS5048A_SPI_Config, CS_ENC);
SPIClass spiConnectionEncoder(MOSI_ENC, MISO_ENC, CLK_ENC);


1 Like


Thanks for the suggestion.

After some more fiddling, I managed to get some life out of the AS5048A and STM32 combination.

Swapping the line…
MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, 10);
MagneticSensorSPI sensor = MagneticSensorSPI(10, 14, 0x3FFF);
It sprung into life.

It seems to work for all the supply voltage combinations (3.3V on the 5V pin, 3.3V with the 5V and 3.3V pin connected together, and 5V on the 5V pin).

If anyone else is wishing to use a similar Cubemars GL30, I have attached the wire colour mappings.