AS5048A SPI issues on SAMD21

Hi All!
I am attempting to use Simple FOC through an Arduino Nano 33 IOT.
But, using the same wiring and code of an Arduino UNO I can’t retrieve any data from an AS5048A connected through SPI.
I saw in the hardware examples that there are some custom parameters for the SAMD21 based boards, but I didn’t find anything in the documentation or in the forum regarding the changes that needs to be done to make the SPI work correctly on these boards (probably I am missing something obvious).
This is the example code that I am testing with:

#include <SimpleFOC.h>

// MagneticSensorSPI(MagneticSensorSPIConfig_s config, int cs)
//  config  - SPI config
//  cs      - SPI chip select pin 
// magnetic sensor instance - SPI
MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, 10);
// alternative constructor (chipselsect, bit_resolution, angle_read_register, )
// MagneticSensorSPI sensor = MagneticSensorSPI(10, 14, 0x3FFF);

void setup() {
  // monitoring port

  // initialise magnetic sensor hardware

  Serial.println("Sensor ready");

void loop() {
  // iterative function updating the sensor internal variables
  // it is usually called in motor.loopFOC()
  // this function reads the sensor hardware and 
  // has to be called before getAngle nad getVelocity
  // display the angle and the angular velocity to the terminal

Connecting the sensor through the same pins, on the Arduino UNO it prints the correct values and on the Arduino Nano 33 IOT it always prints 0.0 (both angle and velocity).
What am I doing wrong? Thanks for your help!

Ok I found the solution, It was pretty easy but I couldn’t find which part of the documentation talks about this.
In my code just remove this line:

MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, 10);

And place this instead:

MagneticSensorSPI sensor = MagneticSensorSPI(10, 14, 0x3FFF);

As you can read in the code comments (I feel absolutely dumb).
But I really can’t understand why the previous initialization works fine on Arduino UNO, but not on Nano 33 IOT, is this a bug?
I leave this gotcha here, for dumb people like me in the future!

1 Like