Ocassional 0 output from AS5047_SPI

Hi,

I am working on getting an AS5047 sensor working and I have gotten it to work somewhat, but ocassionally the sensor.getAngle() returns the value of zero. I am connecting the sensor over SPI to my STM32F103C8T6 bluepill board.

My code:

MagneticSensorSPI sensor = MagneticSensorSPI(AS5047_SPI, PA4);


sensor.init();


  sensor.update();
  if(millis() - lastTime > 100)
  {
    lastTime = millis();
    Serial3.println(degrees(sensor.getSensorAngle()));
  }

Serial output:
image

The angle does change whenever I rotate the motor, but the zeroes stay.

My Platformio.ini:

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = arduino
lib_deps = askuric/Simple FOC@^2.2.2
lib_archive=false
build_flags =
    -D SIMPLEFOC_STM32_DEBUG

Have you tried any other communications like i2c or even pwm/analog?

I changed the vcc to 3v3 instead of 5v and it solved the issue. :slight_smile:

2 Likes