Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to write values to the settings 1 register?#45

Answeredbyjonas-merkle
jonas-merkle asked this question inQ&A
Discussion options

How to write values to the settings 1 register?

I received the following question via e-mail:

I have a question about the function “write_SETTING1” , I can’t understand how to use it. I write 0x0088 into the SETTING1 register , then refer to your example ”PrintAllSettings” to print the SETTING1 register Values for check if I write 0x0088 into the register  success or not.

You must be logged in to vote

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

Comment options

jonas-merkle
Jun 29, 2023
Maintainer Author

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 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}
You must be logged in to vote
0 replies
Answer selected byjonas-merkle
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
documentationImprovements or additions to documentationquestionFurther information is requested
1 participant
@jonas-merkle

[8]ページ先頭

©2009-2025 Movatter.jp