Skip to content

[BUG] STM32 MagneticSensorSPI AS5048 configuration structure not initialized #510

@gbThreepwood

Description

@gbThreepwood

Describe the bug

On a Nucleo L476RG initialization of the AS5048 does not work as expected.

The sensor works using:
MagneticSensorSPI as5048 = MagneticSensorSPI(10, 14, 0x3FFF);

But it does not work using:
MagneticSensorSPI as5048 = MagneticSensorSPI(AS5048_SPI, 10);

Inspection with GDB reveals that in the latter case the config struct AS5048_SPI is not properly initialized:

>>> p AS5147_SPI 
$13 = {
  spi_mode = 1,
  clock_speed = 1000000,
  bit_resolution = 14,
  angle_register = 16383,
  data_start_bit = 13,
  command_rw_bit = 14,
  command_parity_bit = 15
}
>>> p AS5048_SPI 
$14 = {
  spi_mode = 0,
  clock_speed = 0,
  bit_resolution = 0,
  angle_register = 0,
  data_start_bit = 0,
  command_rw_bit = 0,
  command_parity_bit = 0
}

I believe the issue to be on line 15 in MagneticSensorSPI.cpp, i.e.:

// AS5048 and AS5047 are the same as AS5147
MagneticSensorSPIConfig_s AS5048_SPI = AS5147_SPI;
MagneticSensorSPIConfig_s AS5047_SPI = AS5147_SPI;

By changing the code to the following (and also update the external declaration in the header) it seams to be working:

// AS5048 and AS5047 are the same as AS5147
MagneticSensorSPIConfig_s &AS5048_SPI = AS5147_SPI;
MagneticSensorSPIConfig_s &AS5047_SPI = AS5147_SPI;

The original assignment seems to be working in Arduino UNO though, although I have not connected GDB to the Arduino and looked into it in detail.

Describe the hardware setup

  • Which motor
    GM3506
  • Which driver
    SimpleFOCShield V3.2
  • Which microcontroller
    STM32L476RG
  • Which position sensor
    AS5048 with SPI communication

IDE you are using

  • Platformio

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions