AS5047P - Arduino Library 3.0.0
An Arduino library for the AS5047P high-resolution rotary position sensor.
Loading...
Searching...
No Matches
AS5047P Class Reference

Main class for interacting with the AS5047P sensor. More...

#include <AS5047P.h>

Public Member Functions

 AS5047P (uint8_t chipSelectPinNo=9, uint32_t spiSpeed=100000)
 Construct an AS5047P interface.
 
bool checkSPICon ()
 Test the SPI connection to the AS5047P.
 
bool initSPI ()
 Initialize the sensor and verify the connection. Call this once before using the sensor object.
 
bool checkForComErrorF (AS5047P_Types::ERROR_t *errorOut)
 Check the sensor’s error flags for communication issues and OR them into errorOut.
 
bool checkForSensorErrorF (AS5047P_Types::ERROR_t *errorOut)
 Check the sensor’s diagnostics for sensor-related issues and OR them into errorOut.
 
bool verifyWrittenRegF (uint16_t regAddress, uint16_t expectedData)
 Verify that a register contains the expected 16-bit frame (including parity).
 
bool verifyWittenRegF (uint16_t regAddress, uint16_t expectedData)
 Deprecated alias for verifyWrittenRegF (for backward compatibility).
 
String readStatusAsArduinoString ()
 Read status/error information and return it as an Arduino String.
 
uint16_t readMagnitude (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false)
 Read the current CORDIC magnitude.
 
uint16_t readAngleRaw (bool withDAEC=true, AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false)
 Read the 14-bit raw angle.
 
float readAngleDegree (bool withDAEC=true, AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false)
 Read the angle in degrees.
 
template<class T >
readReg (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false)
 Read a register of type.
 
template<class T >
bool writeReg (const T *regData, AS5047P_Types::ERROR_t *errorOut=nullptr, bool checkForComError=false, bool verifyWrittenReg=false)
 Write a register of type.
 
auto read_ERRFL (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::ERRFL_t
 Read the ERRFL register.
 
auto read_PROG (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::PROG_t
 Read the PROG register.
 
auto read_DIAAGC (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::DIAAGC_t
 Read the DIAAGC register.
 
auto read_MAG (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::MAG_t
 Read the MAG register.
 
auto read_ANGLEUNC (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::ANGLEUNC_t
 Read the ANGLEUNC register.
 
auto read_ANGLECOM (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::ANGLECOM_t
 Read the ANGLECOM register.
 
bool write_PROG (const AS5047P_Types::PROG_t *regData, AS5047P_Types::ERROR_t *errorOut=nullptr, bool checkForComError=false, bool verifyWrittenReg=false)
 Write to the PROG register.
 
auto read_ZPOSM (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::ZPOSM_t
 Read the ZPOSM register.
 
auto read_ZPOSL (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::ZPOSL_t
 Read the ZPOSL register.
 
auto read_SETTINGS1 (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::SETTINGS1_t
 Read the SETTINGS1 register.
 
auto read_SETTINGS2 (AS5047P_Types::ERROR_t *errorOut=nullptr, bool verifyParity=false, bool checkForComError=false, bool checkForSensorError=false) -> AS5047P_Types::SETTINGS2_t
 Read the SETTINGS2 register.
 
bool write_ZPOSM (const AS5047P_Types::ZPOSM_t *regData, AS5047P_Types::ERROR_t *errorOut=nullptr, bool checkForComError=false, bool verifyWrittenReg=false)
 Write to the ZPOSM register.
 
bool write_ZPOSL (const AS5047P_Types::ZPOSL_t *regData, AS5047P_Types::ERROR_t *errorOut=nullptr, bool checkForComError=false, bool verifyWrittenReg=false)
 Write to the ZPOSL register.
 
bool write_SETTINGS1 (const AS5047P_Types::SETTINGS1_t *regData, AS5047P_Types::ERROR_t *errorOut=nullptr, bool checkForComError=false, bool verifyWrittenReg=false)
 Write to the SETTINGS1 register.
 
bool write_SETTINGS2 (const AS5047P_Types::SETTINGS2_t *regData, AS5047P_Types::ERROR_t *errorOut=nullptr, bool checkForComError=false, bool verifyWrittenReg=false)
 Write to the SETTINGS2 register.
 

Detailed Description

Main class for interacting with the AS5047P sensor.

Constructor & Destructor Documentation

◆ AS5047P()

AS5047P::AS5047P ( uint8_t chipSelectPinNo = 9,
uint32_t spiSpeed = 100000 )

Construct an AS5047P interface.

Parameters
chipSelectPinNoChip Select (CS) pin number. Default: 9.
spiSpeedSPI clock speed in Hz. (Default as declared below.)

Member Function Documentation

◆ checkForComErrorF()

bool AS5047P::checkForComErrorF ( AS5047P_Types::ERROR_t * errorOut)

Check the sensor’s error flags for communication issues and OR them into errorOut.

Check for communication-related errors and OR them into errorOut.

Parameters
errorOutPointer to an AS5047P_Types::ERROR_t to receive flags (must be non-null).
Returns
true if no communication errors are present; false otherwise.

Reads ERRFL and updates:

  • controller-side parity error (from the current transaction),
  • sensor-side FRERR / INVCOMM / PARERR bits (OR-assigned).
Parameters
errorOutOutput accumulator for error flags (must be non-null).
Returns
true if no errors are present after the check; false otherwise.

◆ checkForSensorErrorF()

bool AS5047P::checkForSensorErrorF ( AS5047P_Types::ERROR_t * errorOut)

Check the sensor’s diagnostics for sensor-related issues and OR them into errorOut.

Check sensor diagnostics and OR them into errorOut.

Parameters
errorOutPointer to an AS5047P_Types::ERROR_t to receive flags (must be non-null).
Returns
true if no sensor errors are present; false otherwise.

Reads DIAAGC and updates:

  • controller-side parity error (from the current transaction),
  • sensor-side COF / LF (inverted for error) / MAGH / MAGL bits (OR-assigned).

Note on LF: LF==1 indicates the internal offset loop is finished (OK), LF==0 indicates "not finished" (treated as an error). We therefore OR in !LF.

Parameters
errorOutOutput accumulator for error flags (must be non-null).
Returns
true if no sensor-related errors are present; false otherwise.

◆ checkSPICon()

bool AS5047P::checkSPICon ( )

Test the SPI connection to the AS5047P.

Check that SPI communication works as expected.

Returns
true if the connection behaves as expected; false otherwise.

Performs a series of reads and a write to verify basic SPI functionality,

Returns
true if the check passes and parity error is detected, false otherwise.

◆ initSPI()

bool AS5047P::initSPI ( )

Initialize the sensor and verify the connection. Call this once before using the sensor object.

Initialize the SPI backend and verify connectivity.

Returns
true if initialization and connectivity check succeed; false otherwise.

◆ read_ANGLECOM()

auto AS5047P::read_ANGLECOM ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::ANGLECOM_t

Read the ANGLECOM register.

Returns
Decoded ANGLECOM register.

◆ read_ANGLEUNC()

auto AS5047P::read_ANGLEUNC ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::ANGLEUNC_t

Read the ANGLEUNC register.

Returns
Decoded ANGLEUNC register.

◆ read_DIAAGC()

auto AS5047P::read_DIAAGC ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::DIAAGC_t

Read the DIAAGC register.

Returns
Decoded DIAAGC register.

◆ read_ERRFL()

auto AS5047P::read_ERRFL ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::ERRFL_t

Read the ERRFL register.

Returns
Decoded ERRFL register.

◆ read_MAG()

auto AS5047P::read_MAG ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::MAG_t

Read the MAG register.

Returns
Decoded MAG register.

◆ read_PROG()

auto AS5047P::read_PROG ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::PROG_t

Read the PROG register.

Returns
Decoded PROG register.

◆ read_SETTINGS1()

auto AS5047P::read_SETTINGS1 ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::SETTINGS1_t

Read the SETTINGS1 register.

Returns
Decoded SETTINGS1 register.

◆ read_SETTINGS2()

auto AS5047P::read_SETTINGS2 ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::SETTINGS2_t

Read the SETTINGS2 register.

Returns
Decoded SETTINGS2 register.

◆ read_ZPOSL()

auto AS5047P::read_ZPOSL ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::ZPOSL_t

Read the ZPOSL register.

Returns
Decoded ZPOSL register.

◆ read_ZPOSM()

auto AS5047P::read_ZPOSM ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false ) -> AS5047P_Types::ZPOSM_t

Read the ZPOSM register.

Returns
Decoded ZPOSM register.

◆ readAngleDegree()

float AS5047P::readAngleDegree ( bool withDAEC = true,
AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false )

Read the angle in degrees.

Read angle in degrees, optionally with DAE compensation.

Parameters
withDAECtrue → ANGLECOM (with DAE compensation), false → ANGLEUNC (raw).
errorOutOptional: error accumulator (nullptr disables checks).
verifyParityVerify parity on the read frame (effective when errorOut is set).
checkForComErrorPoll ERRFL for communication errors (effective when errorOut is set).
checkForSensorErrorPoll DIAAGC for sensor diagnostics (effective when errorOut is set).
Returns
Angle in degrees in [0, 360).
Parameters
withDAECtrue → ANGLECOM (DAEC), false → ANGLEUNC (raw).
Returns
Angle in degrees in [0, 360).

◆ readAngleRaw()

uint16_t AS5047P::readAngleRaw ( bool withDAEC = true,
AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false )

Read the 14-bit raw angle.

Read raw angle (14-bit), optionally with DAE compensation.

Parameters
withDAECtrue → ANGLECOM (with DAE compensation), false → ANGLEUNC (raw).
errorOutOptional: error accumulator (nullptr disables checks).
verifyParityVerify parity on the read frame (effective when errorOut is set).
checkForComErrorPoll ERRFL for communication errors (effective when errorOut is set).
checkForSensorErrorPoll DIAAGC for sensor diagnostics (effective when errorOut is set).
Returns
14-bit angle value.
Parameters
withDAECtrue to read ANGLECOM (DAECANG), false to read ANGLEUNC (CORDICANG).

◆ readMagnitude()

uint16_t AS5047P::readMagnitude ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false )

Read the current CORDIC magnitude.

Read CORDIC magnitude (CMAG).

Parameters
errorOutOptional: error accumulator (nullptr disables checks).
verifyParityVerify parity on the read frame (effective when errorOut is set).
checkForComErrorPoll ERRFL for communication errors (effective when errorOut is set).
checkForSensorErrorPoll DIAAGC for sensor diagnostics (effective when errorOut is set).
Returns
14-bit magnitude value.
14-bit magnitude value.

◆ readReg()

template<class T >
T AS5047P::readReg ( AS5047P_Types::ERROR_t * errorOut = nullptr,
bool verifyParity = false,
bool checkForComError = false,
bool checkForSensorError = false )

Read a register of type.

Read a register type.

Template Parameters
T.
TRegister wrapper with REG_ADDRESS and a constructor from raw.
Parameters
errorOutOptional: error accumulator (nullptr disables checks).
verifyParityVerify parity on the read frame (effective when errorOut is set).
checkForComErrorPoll ERRFL for communication errors (effective when errorOut is set).
checkForSensorErrorPoll DIAAGC for sensor diagnostics (effective when errorOut is set).
Returns
The register content decoded as
Template Parameters
T.
Tand optionally perform parity/diagnostic checks.
TRegister wrapper type with REG_ADDRESS and a constructor from raw.
Parameters
errorOutOptional error accumulator (nullptr to skip).
verifyParityVerify parity on the readback frame.
checkForComErrorPoll ERRFL to OR-in comms errors.
checkForSensorErrorPoll DIAAGC to OR-in sensor diagnostics.
Returns
T Decoded register wrapper.

◆ readStatusAsArduinoString()

String AS5047P::readStatusAsArduinoString ( )

Read status/error information and return it as an Arduino String.

Render a human-readable status dump (Arduino String).

Returns
String with formatted status and diagnostic information.

◆ verifyWittenRegF()

bool AS5047P::verifyWittenRegF ( uint16_t regAddress,
uint16_t expectedData )
inline

Deprecated alias for verifyWrittenRegF (for backward compatibility).

Deprecated
Use verifyWrittenRegF instead.

◆ verifyWrittenRegF()

bool AS5047P::verifyWrittenRegF ( uint16_t regAddress,
uint16_t expectedData )

Verify that a register contains the expected 16-bit frame (including parity).

Verify that a register contains the expected raw 16-bit word.

Parameters
regAddressRegister address to read.
expectedDataFull 16-bit frame expected (bit 15 is the parity bit).
Returns
true if parity is valid and the frame matches; false otherwise.

Performs a read of the 16-bit frame (including parity) and compares it against expectedData. Both parity and content must match.

Parameters
regAddressRegister address to verify.
expectedDataExpected 16-bit word (including parity bit).
Returns
true if parity is valid and the frame matches; false otherwise.

◆ write_PROG()

bool AS5047P::write_PROG ( const AS5047P_Types::PROG_t * regData,
AS5047P_Types::ERROR_t * errorOut = nullptr,
bool checkForComError = false,
bool verifyWrittenReg = false )

Write to the PROG register.

Parameters
regDataNew content to write.
errorOutOptional: error accumulator (nullptr disables checks).
checkForComErrorPoll ERRFL for communication errors after write (effective when errorOut is set).
verifyWrittenRegIf true, perform a diagnostic pass after write (historical flag name kept).
Returns
true if no errors were accumulated (or errorOut is nullptr); false otherwise.

◆ write_SETTINGS1()

bool AS5047P::write_SETTINGS1 ( const AS5047P_Types::SETTINGS1_t * regData,
AS5047P_Types::ERROR_t * errorOut = nullptr,
bool checkForComError = false,
bool verifyWrittenReg = false )

Write to the SETTINGS1 register.

Parameters
regDataNew content to write.
errorOutOptional: error accumulator (nullptr disables checks).
checkForComErrorPoll ERRFL for communication errors after write (effective when errorOut is set).
verifyWrittenRegIf true, perform a diagnostic pass after write (historical flag name kept).
Returns
true if no errors were accumulated (or errorOut is nullptr); false otherwise.

◆ write_SETTINGS2()

bool AS5047P::write_SETTINGS2 ( const AS5047P_Types::SETTINGS2_t * regData,
AS5047P_Types::ERROR_t * errorOut = nullptr,
bool checkForComError = false,
bool verifyWrittenReg = false )

Write to the SETTINGS2 register.

Parameters
regDataNew content to write.
errorOutOptional: error accumulator (nullptr disables checks).
checkForComErrorPoll ERRFL for communication errors after write (effective when errorOut is set).
verifyWrittenRegIf true, perform a diagnostic pass after write (historical flag name kept).
Returns
true if no errors were accumulated (or errorOut is nullptr); false otherwise.

◆ write_ZPOSL()

bool AS5047P::write_ZPOSL ( const AS5047P_Types::ZPOSL_t * regData,
AS5047P_Types::ERROR_t * errorOut = nullptr,
bool checkForComError = false,
bool verifyWrittenReg = false )

Write to the ZPOSL register.

Parameters
regDataNew content to write.
errorOutOptional: error accumulator (nullptr disables checks).
checkForComErrorPoll ERRFL for communication errors after write (effective when errorOut is set).
verifyWrittenRegIf true, perform a diagnostic pass after write (historical flag name kept).
Returns
true if no errors were accumulated (or errorOut is nullptr); false otherwise.

◆ write_ZPOSM()

bool AS5047P::write_ZPOSM ( const AS5047P_Types::ZPOSM_t * regData,
AS5047P_Types::ERROR_t * errorOut = nullptr,
bool checkForComError = false,
bool verifyWrittenReg = false )

Write to the ZPOSM register.

Parameters
regDataNew content to write.
errorOutOptional: error accumulator (nullptr disables checks).
checkForComErrorPoll ERRFL for communication errors after write (effective when errorOut is set).
verifyWrittenRegIf true, perform a diagnostic pass after write (historical flag name kept).
Returns
true if no errors were accumulated (or errorOut is nullptr); false otherwise.

◆ writeReg()

template<class T >
bool AS5047P::writeReg ( const T * regData,
AS5047P_Types::ERROR_t * errorOut = nullptr,
bool checkForComError = false,
bool verifyWrittenReg = false )

Write a register of type.

Write a register and optionally poll for errors / verify.

Template Parameters
T.
TRegister wrapper with REG_ADDRESS and .data.raw.
Parameters
regDataPointer to the data to write.
errorOutOptional: error accumulator (nullptr disables checks).
checkForComErrorPoll ERRFL for communication errors after write (effective when errorOut is set).
verifyWrittenRegIf true, perform a diagnostic pass after write (historical flag name kept).
Returns
true if no errors were accumulated (or errorOut is nullptr); false otherwise.
Template Parameters
TRegister wrapper type with REG_ADDRESS.
Parameters
regDataData to write (16-bit raw in regData->data.raw).
errorOutOptional error accumulator (nullptr to skip).
checkForComErrorPoll ERRFL to OR-in comms errors after write.
verifyWrittenRegIf true, also polls sensor diagnostics (historical naming kept).
Returns
true if errorOut shows no errors (or errorOut is nullptr); false otherwise.

The documentation for this class was generated from the following files: