|
AS5047P - Arduino Library 3.0.0
An Arduino library for the AS5047P high-resolution rotary position sensor.
|
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 > | |
| 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. | |
Main class for interacting with the AS5047P sensor.
| AS5047P::AS5047P | ( | uint8_t | chipSelectPinNo = 9, |
| uint32_t | spiSpeed = 100000 ) |
Construct an AS5047P interface.
| chipSelectPinNo | Chip Select (CS) pin number. Default: 9. |
| spiSpeed | SPI clock speed in Hz. (Default as declared below.) |
| 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.
| errorOut | Pointer to an AS5047P_Types::ERROR_t to receive flags (must be non-null). |
Reads ERRFL and updates:
| errorOut | Output accumulator for error flags (must be non-null). |
| 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.
| errorOut | Pointer to an AS5047P_Types::ERROR_t to receive flags (must be non-null). |
Reads DIAAGC and updates:
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.
| errorOut | Output accumulator for error flags (must be non-null). |
| bool AS5047P::checkSPICon | ( | ) |
Test the SPI connection to the AS5047P.
Check that SPI communication works as expected.
Performs a series of reads and a write to verify basic SPI functionality,
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
| withDAEC | true → ANGLECOM (with DAE compensation), false → ANGLEUNC (raw). |
| errorOut | Optional: error accumulator (nullptr disables checks). |
| verifyParity | Verify parity on the read frame (effective when errorOut is set). |
| checkForComError | Poll ERRFL for communication errors (effective when errorOut is set). |
| checkForSensorError | Poll DIAAGC for sensor diagnostics (effective when errorOut is set). |
| withDAEC | true → ANGLECOM (DAEC), false → ANGLEUNC (raw). |
| 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.
| withDAEC | true → ANGLECOM (with DAE compensation), false → ANGLEUNC (raw). |
| errorOut | Optional: error accumulator (nullptr disables checks). |
| verifyParity | Verify parity on the read frame (effective when errorOut is set). |
| checkForComError | Poll ERRFL for communication errors (effective when errorOut is set). |
| checkForSensorError | Poll DIAAGC for sensor diagnostics (effective when errorOut is set). |
| withDAEC | true to read ANGLECOM (DAECANG), false to read ANGLEUNC (CORDICANG). |
| 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).
| errorOut | Optional: error accumulator (nullptr disables checks). |
| verifyParity | Verify parity on the read frame (effective when errorOut is set). |
| checkForComError | Poll ERRFL for communication errors (effective when errorOut is set). |
| checkForSensorError | Poll DIAAGC for sensor diagnostics (effective when errorOut is set). |
| 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.
| T. | |
| T | Register wrapper with REG_ADDRESS and a constructor from raw. |
| errorOut | Optional: error accumulator (nullptr disables checks). |
| verifyParity | Verify parity on the read frame (effective when errorOut is set). |
| checkForComError | Poll ERRFL for communication errors (effective when errorOut is set). |
| checkForSensorError | Poll DIAAGC for sensor diagnostics (effective when errorOut is set). |
| T. | |
| T | and optionally perform parity/diagnostic checks. |
| T | Register wrapper type with REG_ADDRESS and a constructor from raw. |
| errorOut | Optional error accumulator (nullptr to skip). |
| verifyParity | Verify parity on the readback frame. |
| checkForComError | Poll ERRFL to OR-in comms errors. |
| checkForSensorError | Poll DIAAGC to OR-in sensor diagnostics. |
| String AS5047P::readStatusAsArduinoString | ( | ) |
Read status/error information and return it as an Arduino String.
Render a human-readable status dump (Arduino String).
|
inline |
Deprecated alias for verifyWrittenRegF (for backward compatibility).
| 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.
| regAddress | Register address to read. |
| expectedData | Full 16-bit frame expected (bit 15 is the parity bit). |
Performs a read of the 16-bit frame (including parity) and compares it against expectedData. Both parity and content must match.
| regAddress | Register address to verify. |
| expectedData | Expected 16-bit word (including parity bit). |
| 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.
| regData | New content to write. |
| errorOut | Optional: error accumulator (nullptr disables checks). |
| checkForComError | Poll ERRFL for communication errors after write (effective when errorOut is set). |
| verifyWrittenReg | If true, perform a diagnostic pass after write (historical flag name kept). |
| 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.
| regData | New content to write. |
| errorOut | Optional: error accumulator (nullptr disables checks). |
| checkForComError | Poll ERRFL for communication errors after write (effective when errorOut is set). |
| verifyWrittenReg | If true, perform a diagnostic pass after write (historical flag name kept). |
| 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.
| regData | New content to write. |
| errorOut | Optional: error accumulator (nullptr disables checks). |
| checkForComError | Poll ERRFL for communication errors after write (effective when errorOut is set). |
| verifyWrittenReg | If true, perform a diagnostic pass after write (historical flag name kept). |
| 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.
| regData | New content to write. |
| errorOut | Optional: error accumulator (nullptr disables checks). |
| checkForComError | Poll ERRFL for communication errors after write (effective when errorOut is set). |
| verifyWrittenReg | If true, perform a diagnostic pass after write (historical flag name kept). |
| 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.
| regData | New content to write. |
| errorOut | Optional: error accumulator (nullptr disables checks). |
| checkForComError | Poll ERRFL for communication errors after write (effective when errorOut is set). |
| verifyWrittenReg | If true, perform a diagnostic pass after write (historical flag name kept). |
| 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.
| T. | |
| T | Register wrapper with REG_ADDRESS and .data.raw. |
| regData | Pointer to the data to write. |
| errorOut | Optional: error accumulator (nullptr disables checks). |
| checkForComError | Poll ERRFL for communication errors after write (effective when errorOut is set). |
| verifyWrittenReg | If true, perform a diagnostic pass after write (historical flag name kept). |
| T | Register wrapper type with REG_ADDRESS. |
| regData | Data to write (16-bit raw in regData->data.raw). |
| errorOut | Optional error accumulator (nullptr to skip). |
| checkForComError | Poll ERRFL to OR-in comms errors after write. |
| verifyWrittenReg | If true, also polls sensor diagnostics (historical naming kept). |
errorOut shows no errors (or errorOut is nullptr); false otherwise.