Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork14
How to write values to the settings 1 register?#45
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
How to write values to the settings 1 register?I received the following question via e-mail:
|
BetaWas this translation helpful?Give feedback.
All reactions
The following code is an example how to write values to the settings 1 register of the AS5047P sensor. This example can be adopted for the settings 2 register by changing the corresponding datatypes.
Please keep in mind that the code may need to be modified to be compatible with the hardware you are using. And please check (with the help of the sensor-datasheet) if the values are valid before writing the values into the Settings 1 register.
/** * @file main.cpp * @author Jonas Merkle [JJM] (jonas@jjm.one) * @brief Write to the settings 1 register of a AS5047P sensor. * @date 2023-06-29 * * @copyright Copyright (c) 2023 Jonas Merkle. This project is released under the GPL-3.0 Licens…
Replies: 1 comment
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
The following code is an example how to write values to the settings 1 register of the AS5047P sensor. This example can be adopted for the settings 2 register by changing the corresponding datatypes. /** * @file main.cpp * @author Jonas Merkle [JJM] (jonas@jjm.one) * @brief Write to the settings 1 register of a AS5047P sensor. * @date 2023-06-29 * * @copyright Copyright (c) 2023 Jonas Merkle. This project is released under the GPL-3.0 License License. * * More Information can be found here: * https://github.com/jonas-merkle/AS5047P*/// include the library for the AS5047P sensor.#include<AS5047P.h>// include the arduino main library (not needed when using the official arduino ide)#include<Arduino.h>// define the chip select port.#defineAS5047P_CHIP_SELECT_PORT9// define the spi bus speed#defineAS5047P_CUSTOM_SPI_BUS_SPEED100000// initialize a new AS5047P sensor object.AS5047Pas5047p(AS5047P_CHIP_SELECT_PORT, AS5047P_CUSTOM_SPI_BUS_SPEED);voidwaitForAnySerialKeyPress() { Serial.read();}// arduino setup routinevoidsetup() {// initialize the serial bus for the communication with your pc. Serial.begin(115200);// wait for serial port to connect. Needed for native USBwhile (!Serial) { ; }// initialize the AS5047P sensor and hold if sensor can't be initialized.while (!as5047p.initSPI()) { Serial.println(F("Can't connect to the AS5047P sensor! Please check the connection..."));delay(5000); }// initialize a new object which represents the settings 1 registerauto settingsToWrite =newAS5047P_Types::SETTINGS1_t();// initialize a new object which represents error informationauto errorInfo =AS5047P_Types::ERROR_t();// set the raw register value settingsToWrite->data.raw =0x0088;// or optional: you can set the individual values of the register entries with the following commands://settingsToWrite->data.values.FactorySetting = 0;//settingsToWrite->data.values.NOISESET = 0;//settingsToWrite->data.values.DIR = 0;//settingsToWrite->data.values.UVW_ABI = 1;//settingsToWrite->data.values.DAECDIS = 0;//settingsToWrite->data.values.ABIBIN = 0;//settingsToWrite->data.values.Dataselect = 0;//settingsToWrite->data.values.PWMon = 1;// (optional) wait for any key to be pressed in the serial terminal to continue Serial.print("Press any key to continue...");while (!Serial.available()) { ; } Serial.println("");// log Serial.print("Wirte settings 1 register to sensor...");// write the settings 1 register to the sensorbool result = as5047p.write_SETTINGS1(settingsToWrite, &errorInfo,true,true);// logif (result) { Serial.println(" Done successful!"); }else { Serial.println(" Failed!");// print potential error information Serial.println(errorInfo.toArduinoString()); }// print all entires from settings 1 register// read the settings 1 register from the sensorauto settingsReadBack = as5047p.read_SETTINGS1();// print the settings 1 register which was read from the sensor Serial.print("SETTINGS1.values.FactorySetting:"); Serial.println(settingsReadBack.data.values.FactorySetting); Serial.print("SETTINGS1.values.NOISESET:"); Serial.println(settingsReadBack.data.values.NOISESET); Serial.print("SETTINGS1.values.DIR:"); Serial.println(settingsReadBack.data.values.DIR); Serial.print("SETTINGS1.values.UVW_ABI:"); Serial.println(settingsReadBack.data.values.UVW_ABI); Serial.print("SETTINGS1.values.DAECDIS:"); Serial.println(settingsReadBack.data.values.DAECDIS); Serial.print("SETTINGS1.values.ABIBIN:"); Serial.println(settingsReadBack.data.values.ABIBIN); Serial.print("SETTINGS1.values.Dataselect:"); Serial.println(settingsReadBack.data.values.Dataselect); Serial.print("SETTINGS1.values.PWMon:"); Serial.println(settingsReadBack.data.values.PWMon); }// arduino loop routinevoidloop() {// nothing to do here} |
BetaWas this translation helpful?Give feedback.