Skip to content

Use AS5600 auto increment suppress #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/sensors/MagneticSensorI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ MagneticSensorI2CConfig_s AS5600_I2C = {
.chip_address = 0x36,
.bit_resolution = 12,
.angle_register = 0x0C,
.data_start_bit = 11
.data_start_bit = 11,
.auto_increment_suppress = 1 // chip does not auto increment the angle register
};

/** Typical configuration for the 12bit AMS AS5048 magnetic sensor over I2C interface */
Expand Down Expand Up @@ -53,6 +54,7 @@ MagneticSensorI2C::MagneticSensorI2C(uint8_t _chip_address, int _bit_resolution,

MagneticSensorI2C::MagneticSensorI2C(MagneticSensorI2CConfig_s config){
chip_address = config.chip_address;
auto_increment_suppress = config.auto_increment_suppress;

// angle read register of the magnetic sensor
angle_register_msb = config.angle_register;
Expand All @@ -79,6 +81,14 @@ void MagneticSensorI2C::init(TwoWire* _wire){
wire->begin();

this->Sensor::init(); // call base class init

if(auto_increment_suppress) {
// register address needs to be written only once as subsequent reads
// do not auto increment the register address.
wire->beginTransmission(chip_address);
wire->write(angle_register_msb);
currWireError = wire->endTransmission(false);
}
}

// Shaft angle calculation
Expand All @@ -105,10 +115,13 @@ int MagneticSensorI2C::read(uint8_t angle_reg_msb) {
// read the angle register first MSB then LSB
byte readArray[2];
uint16_t readValue = 0;
// notify the device that is aboout to be read
wire->beginTransmission(chip_address);
wire->write(angle_reg_msb);
currWireError = wire->endTransmission(false);

if(auto_increment_suppress == 0) {
// notify the device that it is aboout to be read
wire->beginTransmission(chip_address);
wire->write(angle_reg_msb);
currWireError = wire->endTransmission(false);
}

// read the data msb and lsb
wire->requestFrom(chip_address, (uint8_t)2);
Expand Down
2 changes: 2 additions & 0 deletions src/sensors/MagneticSensorI2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct MagneticSensorI2CConfig_s {
int bit_resolution;
int angle_register;
int data_start_bit;
int auto_increment_suppress;
};
// some predefined structures
extern MagneticSensorI2CConfig_s AS5600_I2C,AS5048_I2C;
Expand Down Expand Up @@ -63,6 +64,7 @@ class MagneticSensorI2C: public Sensor{
// I2C variables
uint8_t angle_register_msb; //!< I2C angle register to read
uint8_t chip_address; //!< I2C chip select pins
int auto_increment_suppress; //!< I2C auto increment suppress

// I2C functions
/** Read one I2C register value */
Expand Down