AS5048A SPI - Magnetic rotary encoder library

SPI Daisy Chaining

To use multiple AS5048 sensors in a daisy chain on a single SPI-bus:

  • Connect the MOSI of the first sensor to the MOSI (pin 5) of the mBed;
  • Connect the MISO of the first sensor to the MOSI of the second sensor;
  • Connect the MISO of the second sensor to the MISO (pin 6) of the mBed.
  • Set nDevices to 2 in the constructor of As5048Spi
  • The read methods of As5048Spi will now return two bytes per read operation, one for each sensor.

Example code for daisy chaining to sensors

#include "mbed.h"
#include <as5048spi.h>

// Two sensors are connected to pins 5-8
As5048Spi sensor(p5, p6, p7, p8, 2);
Serial pc(USBTX, USBRX); // tx, rx

int main() {
    while(1) {
        // 
        const int* angles = sensor.read_angle();
        int angle1 = As5048Spi::degrees(angles[0]);
        int angle2 = As5048Spi::degrees(angles[1]);
        
        pc.printf("Angle 1: %i degrees\r\n", angle1 );
        pc.printf("Angle 2: %i degrees\r\n", angle2 );
            
        wait_ms(500);
    }
}

All wikipages