Arduino-FOC icon indicating copy to clipboard operation
Arduino-FOC copied to clipboard

MagneticSensorSPI & teensy3.2

Open AurelienConil opened this issue 4 years ago • 1 comments

Hi . I found a very weird bug is FOC library with Teensy 3.2. This bug is not present compiling on Arduino Uno, so this is a teensy issue, compiling through Arduino

MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, 10);

void setup() {
  // monitoring port
  Serial.begin(115200);
  Serial.print("SPI MODE ARDUINO = ");
  Serial.println(sensor.spi_mode);

As declaring 'sensor' as a global variable, sensor.spi_mode = SPI_MODE0 while the config for AS5048 expect spi_mode to be SPI_MODE1.

Now, if i declare sensor inside setup()

void setup() {
MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, 10);
  // monitoring port
  Serial.begin(115200);
  Serial.print("SPI MODE ARDUINO = ");
  Serial.println(sensor.spi_mode);

sensor.spi_mode became what it should be = SPI_MODE1

As a result, spi_mode is wrong when sensor is declared as a global variable, that make the magnetic sensor impossible to use with teensy

AurelienConil avatar Jun 25 '21 13:06 AurelienConil

Honestly I do not have any idea why this happens, we will investigate it :D

askuric avatar Jul 20 '21 15:07 askuric