diff --git a/README.md b/README.md index e422626..2648649 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ For more information on the MagAlpha sensor family: * [MagAlpha Support Materials](http://www.monolithicpower.com/Design-Support/Position-Sensors-Design-Support) ## Supported sensors -Supports all 3rd generation MagAlpha magnetic angle sensors from [Monolithic Power Systems](https://www.monolithicpower.com/). +Supports all 3rd, 4th, 6th, 7th, 8th generation MagAlpha magnetic angle sensors from [Monolithic Power Systems](https://www.monolithicpower.com/). | Applications | Part Numbers | | ------------| ------------ | | Turning knob applications (potentiometer replacement) | MA800, MA820, MA850 | | Rotary encoders (optical encoder replacement, Servo motors, ...) | MA702, MA704, MA710, MA730 | -| Position controlled motor drivers (FOC, ...) | MA302, MA310 | +| Position controlled motor drivers (FOC, ...) | MA302, MA310, MA600 | | Motor commutation (hall switches replacement) | MA102 | @@ -39,6 +39,7 @@ MIT license, all text above must be included in any redistribution. ### Serial communication All MagAlpha have a SPI communication interface. Some sensors like the MA702 also have an additional SSI (2-wire) interface. +MagAlpha gen8 possess an I2C interface. #### SPI (4-wire interface) | Arduino | MagAlpha | @@ -54,6 +55,12 @@ All MagAlpha have a SPI communication interface. Some sensors like the MA702 als | MISO | SSD | | SCK | SSCK | +### I2C (2-wire interface) +| Arduino | MagAlpha | +| -------- | -------- | +| SCL | SCL | +| SDA | SDA | + #### Arduino SPI pin mapping | Arduino / Genuino Board | MOSI | MISO | SCK | CS | Voltage Level | | ----------------------- | ---- | ---- | ---- | :---: | ------------- | diff --git a/examples/gen3/gen3.ino b/examples/gen3/gen3.ino new file mode 100644 index 0000000..1f5d91f --- /dev/null +++ b/examples/gen3/gen3.ino @@ -0,0 +1,90 @@ +#include + +#include +#include + +#define SPI_CS_PIN (7) +#define SPI_SCLK_FREQUENCY (1000000) + +MagAlphaGen3 magalpha; + +double angle_real; +uint16_t zero, bct, angle_raw; +uint8_t register_value[2]; +bool error; + +void setup() { + + magalpha.begin(SPI_SCLK_FREQUENCY, MagAlphaSPIMode::MODE_0, SPI_CS_PIN, &SPI); + // Other ways of use of begin() that will set default settings to the SPI peripheral + // magalpha.begin(SPI_CS_PIN, &SPI); + + //magalpha.setSpiClockFrequency(SPI_SCLK_FREQUENCY); + //magalpha.setSpiDataMode(MagAlphaSPIMode::MODE0); + //magalpha.setSpiChipSelectPin(SPI_CS_PIN); + Serial.begin(115200); + while(!Serial); +} + +void loop() { + + // Read & Write registers + register_value[0] = magalpha.writeRegister(0, 0xAA); + Serial.println(register_value[0], HEX); + register_value[0] = magalpha.readRegister(0); + Serial.println(register_value[0], HEX); + register_value[0] = magalpha.writeRegister(0, 0x00); + + // Read & Write registers in burst mode + register_value[0] = 0xAA; + register_value[1] = 0x55; + magalpha.writeRegisterBurst(0, register_value, 2); + magalpha.readRegisterBurst(0, register_value, 2); + for(uint8_t i = 0; i < sizeof(register_value); i++) { + Serial.print("Register "); + Serial.print(i); + Serial.print(" = "); + Serial.println(register_value[i], HEX); + } + register_value[0] = 0x00; + register_value[1] = 0x00; + magalpha.writeRegisterBurst(0, register_value, 2); + + // Set & Get zero setting + zero = magalpha.setCurrentAngleAsZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + magalpha.setZero(0x0000); + zero = magalpha.getZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + + // Set & Get BCT setting + magalpha.setBct(0xAA55); + bct = magalpha.getBct(); + Serial.print("BCT = "); + Serial.println(bct, HEX); + magalpha.setBct(0x00); + + // Read angle + angle_raw = magalpha.readAngleRaw8(); + Serial.print("Angle raw (8 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw16(); + Serial.print("Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw(&error); + if(error) { + Serial.println("An error occured during readAngleRaw"); + } else { + Serial.print("readAngleRaw succeded, Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + } + + angle_real = magalpha.readAngle(); + Serial.print("Angle in degree = "); + Serial.println(angle_real, DEC); + + // This delay has been added only for visual purpose of the terminal + delay(25); +} \ No newline at end of file diff --git a/examples/gen4/gen4.ino b/examples/gen4/gen4.ino new file mode 100644 index 0000000..443a59f --- /dev/null +++ b/examples/gen4/gen4.ino @@ -0,0 +1,108 @@ +#include + +#include +#include + +#define SPI_CS_PIN (7) +#define SPI_SCLK_FREQUENCY (1000000) + +MagAlphaGen4 magalpha; + +double angle_real; +uint16_t zero, bct, angle_raw; +uint8_t register_value[2]; +bool error; + +void setup() { + + magalpha.begin(SPI_SCLK_FREQUENCY, MagAlphaSPIMode::MODE_0, SPI_CS_PIN, &SPI); + // Other ways of use of begin() that will set default settings to the SPI peripheral + // magalpha.begin(SPI_CS_PIN, &SPI); + + //magalpha.setSpiClockFrequency(SPI_SCLK_FREQUENCY); + //magalpha.setSpiDataMode(MagAlphaSPIMode::MODE0); + //magalpha.setSpiChipSelectPin(SPI_CS_PIN); + Serial.begin(115200); + while(!Serial); +} + +void loop() { + + // Read & Write registers + register_value[0] = magalpha.writeRegister(0, 0xAA); + Serial.println(register_value[0], HEX); + register_value[0] = magalpha.readRegister(0); + Serial.println(register_value[0], HEX); + register_value[0] = magalpha.writeRegister(0, 0x00); + + // Read & Write registers in burst mode + register_value[0] = 0xAA; + register_value[1] = 0x55; + magalpha.writeRegisterBurst(0, register_value, 2); + magalpha.readRegisterBurst(0, register_value, 2); + for(uint8_t i = 0; i < sizeof(register_value); i++) { + Serial.print("Register "); + Serial.print(i); + Serial.print(" = "); + Serial.println(register_value[i], HEX); + } + register_value[0] = 0x00; + register_value[1] = 0x00; + magalpha.writeRegisterBurst(0, register_value, 2); + + // Set & Get zero setting + zero = magalpha.setCurrentAngleAsZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + magalpha.setZero(0x0000); + zero = magalpha.getZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + + // Set & Get BCT setting + magalpha.setBct(0xAA55); + bct = magalpha.getBct(); + Serial.print("BCT = "); + Serial.println(bct, HEX); + magalpha.setBct(0x00); + + // Memory management + magalpha.writeRegister(0, 0xAA); + magalpha.storeRegister(0); + magalpha.writeRegister(0, 0x00); + magalpha.restoreAllRegisters(); + if(magalpha.readRegister(0) != 0xAA) { + Serial.println("An error occured during restoreAllRegisters"); + } + magalpha.writeRegister(0, 0x00); + magalpha.storeAllRegisters(); + magalpha.restoreAllRegisters(); + if(magalpha.readRegister(0) != 0x00) { + Serial.println("An error occured during storeAllRegisters"); + } + + // Clear error flags + magalpha.clearErrorFlags(); + + // Read angle + angle_raw = magalpha.readAngleRaw8(); + Serial.print("Angle raw (8 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw16(); + Serial.print("Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw(&error); + if(error) { + Serial.println("An error occured during readAngleRaw"); + } else { + Serial.print("readAngleRaw succeded, Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + } + + angle_real = magalpha.readAngle(); + Serial.print("Angle in degree = "); + Serial.println(angle_real, DEC); + + // This delay has been added only for visual purpose of the terminal + delay(25); +} diff --git a/examples/gen6/gen6.ino b/examples/gen6/gen6.ino new file mode 100644 index 0000000..13357d6 --- /dev/null +++ b/examples/gen6/gen6.ino @@ -0,0 +1,113 @@ +#include + +#include +#include + +#define SPI_CS_PIN (7) +#define SPI_SCLK_FREQUENCY (1000000) + +MagAlphaGen6 magalpha; + +double angle_real, speed; +uint16_t zero, bct, angle_raw, turn; +uint8_t register_value[2]; +bool error; + +void setup() { + + magalpha.begin(SPI_SCLK_FREQUENCY, MagAlphaSPIMode::MODE_0, SPI_CS_PIN, &SPI); + // Other ways of use of begin() that will set default settings to the SPI peripheral + // magalpha.begin(SPI_CS_PIN, &SPI); + + //magalpha.setSpiClockFrequency(SPI_SCLK_FREQUENCY); + //magalpha.setSpiDataMode(MagAlphaSPIMode::MODE0); + //magalpha.setSpiChipSelectPin(SPI_CS_PIN); + Serial.begin(115200); + while(!Serial); +} + +void loop() { + + // Read & Write registers + register_value[0] = magalpha.writeRegister(0, 0xAA); + Serial.println(register_value[0], HEX); + register_value[0] = magalpha.readRegister(0); + Serial.println(register_value[0], HEX); + register_value[0] = magalpha.writeRegister(0, 0x00); + + // Read & Write registers in burst mode + register_value[0] = 0xAA; + register_value[1] = 0x55; + magalpha.writeRegisterBurst(0, register_value, 2); + magalpha.readRegisterBurst(0, register_value, 2); + for(uint8_t i = 0; i < sizeof(register_value); i++) { + Serial.print("Register "); + Serial.print(i); + Serial.print(" = "); + Serial.println(register_value[i], HEX); + } + register_value[0] = 0x00; + register_value[1] = 0x00; + magalpha.writeRegisterBurst(0, register_value, 2); + + // Set & Get zero setting + zero = magalpha.setCurrentAngleAsZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + magalpha.setZero(0x0000); + zero = magalpha.getZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + + // Set & Get BCT setting + magalpha.setBct(0xAA55); + bct = magalpha.getBct(); + Serial.print("BCT = "); + Serial.println(bct, HEX); + magalpha.setBct(0x00); + + // Memory management + magalpha.writeRegister(0, 0xAA); + magalpha.storeRegisterBlock(0); + magalpha.writeRegister(0, 0x00); + magalpha.restoreAllRegisters(); + if(magalpha.readRegister(0) != 0xAA) { + Serial.println("An error occured during restoreAllRegisters"); + } + magalpha.writeRegister(0, 0x00); + magalpha.storeAllRegisters(); + magalpha.restoreAllRegisters(); + if(magalpha.readRegister(0) != 0x00) { + Serial.println("An error occured during storeAllRegisters"); + } + + // Clear error flags + magalpha.clearErrorFlags(); + + speed = magalpha.readSpeed(); + Serial.println(speed); + turn = magalpha.readTurn(); + Serial.println(turn); + + // Read angle + angle_raw = magalpha.readAngleRaw8(); + Serial.print("Angle raw (8 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw16(); + Serial.print("Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw(&error); + if(error) { + Serial.println("An error occured during readAngleRaw"); + } else { + Serial.print("readAngleRaw succeded, Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + } + + angle_real = magalpha.readAngle(); + Serial.print("Angle in degree = "); + Serial.println(angle_real, DEC); + + // This delay has been added only for visual purpose of the terminal + delay(25); +} diff --git a/examples/gen7/gen7.ino b/examples/gen7/gen7.ino new file mode 100644 index 0000000..5192d88 --- /dev/null +++ b/examples/gen7/gen7.ino @@ -0,0 +1,121 @@ +#include + +#include +#include + +#define SPI_CS_PIN (7) +#define SPI_SCLK_FREQUENCY (1000000) + +MagAlphaGen7 magalpha; + +double angle_real, speed; +uint16_t zero, angle_raw, turn; +uint8_t register_value[2]; +bool error; + +void setup() { + + magalpha.begin(SPI_SCLK_FREQUENCY, MagAlphaSPIMode::MODE_0, SPI_CS_PIN, &SPI); + // Other ways of use of begin() that will set default settings to the SPI peripheral + // magalpha.begin(SPI_CS_PIN, &SPI); + + //magalpha.setSpiClockFrequency(SPI_SCLK_FREQUENCY); + //magalpha.setSpiDataMode(MagAlphaSPIMode::MODE0); + //magalpha.setSpiChipSelectPin(SPI_CS_PIN); + Serial.begin(115200); + while(!Serial); +} + +void loop() { + + // Read & Write registers + register_value[0] = magalpha.writeRegister(0, 0xAA); + Serial.print("Register 0 = "); + Serial.println(register_value[0], HEX); + register_value[0] = magalpha.readRegister(0); + register_value[0] = magalpha.writeRegister(0, 0x00); + + /* + uint16_t readAngleRaw16(bool *error, bool *inversion, bool isShortRead=false); + uint16_t readAngleCounter(uint16_t *angle, bool *error, bool *inversion); + uint16_t readAngleSpeed(uint16_t *angle, bool *error, bool *inversion); + uint16_t readAngleMultiturn(uint16_t *angle, bool *error, bool *inversion); + uint16_t readAngleTemperature(uint16_t *angle, bool *error, bool *inversion); + uint8_t readRegister(uint8_t address, bool *error, bool *inversion); + uint16_t readRegisterBurst(uint8_t address, uint8_t readbackValueArray[], uint16_t numberOfRegister, bool *error, bool *inversion); + uint8_t writeRegister(uint8_t address, uint8_t value, bool *error, bool *inversion, bool *wrongHandshaking); + void writeRegisterBurst(uint8_t address, uint8_t valueArray[], uint16_t numberOfRegister, bool *error, bool *inversion, bool *wrongHandshaking); + void setCrcCheckSetting(bool enable); + uint16_t appendCrc4(uint16_t data); + void checkCrc4(uint16_t readData, uint16_t *computedCrc, bool *errorDetected, bool *inversionDetected); + */ + + // Read & Write registers in burst mode + register_value[0] = 0x55; + register_value[1] = 0xAA; + magalpha.writeRegisterBurst(0, register_value, 2); + magalpha.readRegisterBurst(0, register_value, 2); + for(uint8_t i = 0; i < sizeof(register_value); i++) { + Serial.print("Register "); + Serial.print(i); + Serial.print(" = "); + Serial.println(register_value[i], HEX); + } + register_value[0] = 0x00; + register_value[1] = 0x00; + magalpha.writeRegisterBurst(0, register_value, 2); + + // Set & Get zero setting + zero = magalpha.setCurrentAngleAsZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + magalpha.setZero(0x0000); + zero = magalpha.getZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + + // Memory management + magalpha.writeRegister(0, 0xAA); + magalpha.storeRegisterBlock(1); + magalpha.writeRegister(0, 0x00); + magalpha.restoreAllRegisters(); + if(magalpha.readRegister(0) != 0xAA) { + Serial.println("An error occured during restoreAllRegisters"); + } + magalpha.writeRegister(0, 0x00); + magalpha.storeAllRegisters(); + magalpha.restoreAllRegisters(); + if(magalpha.readRegister(0) != 0x00) { + Serial.println("An error occured during storeAllRegisters"); + } + + // Clear error flags + magalpha.clearErrorFlags(); + + speed = magalpha.readSpeed(); + Serial.println(speed); + turn = magalpha.readTurn(); + Serial.println(turn); + + // Read angle + angle_raw = magalpha.readAngleRaw8(); + Serial.print("Angle raw (8 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw16(); + Serial.print("Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw(&error); + if(error) { + Serial.println("An error occured during readAngleRaw"); + } else { + Serial.print("readAngleRaw succeded, Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + } + + angle_real = magalpha.readAngle(); + Serial.print("Angle in degree = "); + Serial.println(angle_real, DEC); + + // This delay has been added only for visual purpose of the terminal + delay(1000); +} diff --git a/examples/gen8/gen8.ino b/examples/gen8/gen8.ino new file mode 100644 index 0000000..d799ff9 --- /dev/null +++ b/examples/gen8/gen8.ino @@ -0,0 +1,106 @@ +#include + +#include +#include + +#define SPI_CS_PIN (7) +#define SPI_SCLK_FREQUENCY (1000000) + +MagAlphaGen6 magalpha; + +double angle_real, speed; +uint16_t zero, angle_raw, turn; +uint8_t register_value[2]; +bool error; + +void setup() { + + magalpha.begin(SPI_SCLK_FREQUENCY, MagAlphaSPIMode::MODE_0, SPI_CS_PIN, &SPI); + // Other ways of use of begin() that will set default settings to the SPI peripheral + // magalpha.begin(SPI_CS_PIN, &SPI); + + //magalpha.setSpiClockFrequency(SPI_SCLK_FREQUENCY); + //magalpha.setSpiDataMode(MagAlphaSPIMode::MODE0); + //magalpha.setSpiChipSelectPin(SPI_CS_PIN); + Serial.begin(115200); + while(!Serial); +} + +void loop() { + + // Read & Write registers + register_value[0] = magalpha.writeRegister(0, 0xAA); + Serial.println(register_value[0], HEX); + register_value[0] = magalpha.readRegister(0); + Serial.println(register_value[0], HEX); + register_value[0] = magalpha.writeRegister(0, 0x00); + + // Read & Write registers in burst mode + register_value[0] = 0xAA; + register_value[1] = 0x55; + magalpha.writeRegisterBurst(0, register_value, 2); + magalpha.readRegisterBurst(0, register_value, 2); + for(uint8_t i = 0; i < sizeof(register_value); i++) { + Serial.print("Register "); + Serial.print(i); + Serial.print(" = "); + Serial.println(register_value[i], HEX); + } + register_value[0] = 0x00; + register_value[1] = 0x00; + magalpha.writeRegisterBurst(0, register_value, 2); + + // Set & Get zero setting + zero = magalpha.setCurrentAngleAsZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + magalpha.setZero(0x0000); + zero = magalpha.getZero(); + Serial.print("Zero setting = "); + Serial.println(zero, HEX); + + // Memory management + magalpha.writeRegister(0, 0xAA); + magalpha.storeRegister(0); + magalpha.writeRegister(0, 0x00); + magalpha.restoreAllRegisters(); + if(magalpha.readRegister(0) != 0xAA) { + Serial.println("An error occured during restoreAllRegisters"); + } + magalpha.writeRegister(0, 0x00); + magalpha.storeAllRegisters(); + magalpha.restoreAllRegisters(); + if(magalpha.readRegister(0) != 0x00) { + Serial.println("An error occured during storeAllRegisters"); + } + + // Clear error flags + magalpha.clearErrorFlags(); + + speed = magalpha.readSpeed(); + Serial.println(speed); + turn = magalpha.readTurn(); + Serial.println(turn); + + // Read angle + angle_raw = magalpha.readAngleRaw8(); + Serial.print("Angle raw (8 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw16(); + Serial.print("Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + angle_raw = magalpha.readAngleRaw(&error); + if(error) { + Serial.println("An error occured during readAngleRaw"); + } else { + Serial.print("readAngleRaw succeded, Angle raw (16 bits) = "); + Serial.println(angle_raw, HEX); + } + + angle_real = magalpha.readAngle(); + Serial.print("Angle in degree = "); + Serial.println(angle_real, DEC); + + // This delay has been added only for visual purpose of the terminal + delay(25); +} diff --git a/examples/edit-magalpha-config/edit-magalpha-config.ino b/examples/legacy/edit-magalpha-config/edit-magalpha-config.ino similarity index 100% rename from examples/edit-magalpha-config/edit-magalpha-config.ino rename to examples/legacy/edit-magalpha-config/edit-magalpha-config.ino diff --git a/examples/read-magalpha-angle-and-error/read-magalpha-angle-and-error.ino b/examples/legacy/read-magalpha-angle-and-error/read-magalpha-angle-and-error.ino similarity index 100% rename from examples/read-magalpha-angle-and-error/read-magalpha-angle-and-error.ino rename to examples/legacy/read-magalpha-angle-and-error/read-magalpha-angle-and-error.ino diff --git a/examples/read-magalpha-angle-with-ssi-and-error/read-magalpha-angle-with-ssi-and-error.ino b/examples/legacy/read-magalpha-angle-with-ssi-and-error/read-magalpha-angle-with-ssi-and-error.ino similarity index 97% rename from examples/read-magalpha-angle-with-ssi-and-error/read-magalpha-angle-with-ssi-and-error.ino rename to examples/legacy/read-magalpha-angle-with-ssi-and-error/read-magalpha-angle-with-ssi-and-error.ino index 5836070..f0d0afd 100644 --- a/examples/read-magalpha-angle-with-ssi-and-error/read-magalpha-angle-with-ssi-and-error.ino +++ b/examples/legacy/read-magalpha-angle-with-ssi-and-error/read-magalpha-angle-with-ssi-and-error.ino @@ -1,4 +1,4 @@ -#include +#include //Check https://www.arduino.cc/en/reference/SPI for SPI signals connections //Connect SSI SSCK to SPI SCLK signal diff --git a/examples/read-magalpha-angle-with-ssi/read-magalpha-angle-with-ssi.ino b/examples/legacy/read-magalpha-angle-with-ssi/read-magalpha-angle-with-ssi.ino similarity index 97% rename from examples/read-magalpha-angle-with-ssi/read-magalpha-angle-with-ssi.ino rename to examples/legacy/read-magalpha-angle-with-ssi/read-magalpha-angle-with-ssi.ino index 0a7064f..4ec646f 100644 --- a/examples/read-magalpha-angle-with-ssi/read-magalpha-angle-with-ssi.ino +++ b/examples/legacy/read-magalpha-angle-with-ssi/read-magalpha-angle-with-ssi.ino @@ -1,4 +1,4 @@ -#include +#include //Check https://www.arduino.cc/en/reference/SPI for SPI signals connections //Connect SSI SSCK to SPI SCLK signal diff --git a/examples/read-magalpha-angle/read-magalpha-angle.ino b/examples/legacy/read-magalpha-angle/read-magalpha-angle.ino similarity index 100% rename from examples/read-magalpha-angle/read-magalpha-angle.ino rename to examples/legacy/read-magalpha-angle/read-magalpha-angle.ino diff --git a/keywords.txt b/keywords.txt index f6772da..0293773 100644 --- a/keywords.txt +++ b/keywords.txt @@ -7,7 +7,14 @@ ####################################### MagAlpha KEYWORD1 +MagAlphaSPI KEYWORD1 MagAlphaSSI KEYWORD1 +MagAlphaI2C KEYWORD1 +MagAlphaGen3 KEYWORD1 +MagAlphaGen4 KEYWORD1 +MagAlphaGen6 KEYWORD1 +MagAlphaGen7 KEYWORD1 +MagAlphaGen8 KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) diff --git a/library.properties b/library.properties index 33a6805..9fa0503 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=MagAlpha Angle Sensor Library -version=1.0.2 +version=2.0.0 author=Mathieu Kaelin, Monolithic Power Systems maintainer=Mathieu Kaelin sentence=Arduino library for the MPS MagAlpha magnetic angle sensor. -paragraph=Supports MagAlpha 3rd generation Sensors. MagAlpha sensor detects the absolute angular position of a permanent magnet, typically a diametrically magnetized cylinder on the rotating shaft. +paragraph=Supports MagAlpha 3, 4, 6, 7, 8 sensor generation. MagAlpha sensor detects the absolute angular position of a permanent magnet, typically a diametrically magnetized cylinder on the rotating shaft. category=Sensors url=https://github.com/monolithicpower/MagAlpha-Arduino-Library architectures=* -includes=SPI.h +includes=SPI.h,MagAlpha.h,MagAlphaGen3.h,MagAlphaGen4.h,MagAlphaGen6.h,MagAlphaGen7.h,MagAlphaGen8.h,MagAlphaPartProperties.h diff --git a/src/MagAlpha.cpp b/src/MagAlpha.cpp index 4780a36..5a0ecb4 100644 --- a/src/MagAlpha.cpp +++ b/src/MagAlpha.cpp @@ -8,7 +8,37 @@ MIT license, all text above must be included in any redistribution ****************************************************/ +#include #include "MagAlpha.h" +//MagAlpha Read/Write Register Command +//#define READ_REG_COMMAND (0b010 << 13) +//#define WRITE_REG_COMMAND (0b100 << 13) + +#define SSI_MODE SPI_MODE1 + +/*====================================================================================*/ +/*========================== MagAlphaGen3 Legacy =====================================*/ +/*====================================================================================*/ MagAlpha::MagAlpha(){ } + +void MagAlpha::begin(uint8_t spiChipSelectPin){ + MagAlphaSPI::begin(10000000, MagAlphaSPIMode::MODE_3, spiChipSelectPin, &SPI); +} + +void MagAlpha::begin(int32_t spiSclkFrequency, uint8_t spiMode, uint8_t spiChipSelectPin){ + MagAlphaSPI::begin(spiSclkFrequency, (MagAlphaSPIMode)spiMode, spiChipSelectPin, &SPI); +} + +void MagAlpha::setSpiDataMode(uint8_t spiMode){ + MagAlphaSPI::setSpiDataMode((MagAlphaSPIMode)spiMode); +} + +uint16_t MagAlpha::readAngleRaw() { + return MagAlphaGen3::readAngleRaw16(); +} + +uint16_t MagAlpha::readAngleRaw(bool* error) { + return MagAlphaGen3::readAngleRaw(error); +} \ No newline at end of file diff --git a/src/MagAlpha.h b/src/MagAlpha.h index 9bf958a..2ac74c2 100644 --- a/src/MagAlpha.h +++ b/src/MagAlpha.h @@ -16,16 +16,24 @@ #else #include "WProgram.h" #endif +#include #include "MagAlphaGen3.h" - -//SPI Mode: MagAlpha Gen3 support SPI mode 3 and 0 [SPI_MODE3, SPI_MODE0] +#include "MagAlphaPartProperties.h" + //SPI Mode: MagAlpha Gen3 support SPI mode 3 and 0 [SPI_MODE3, SPI_MODE0] #define MA_SPI_MODE_0 SPI_MODE0 #define MA_SPI_MODE_3 SPI_MODE3 -class MagAlpha: public MagAlphaGen3 { +/*====================================================================================*/ +/*========================== MagAlphaGen3 Legacy =====================================*/ +/*====================================================================================*/ +class MagAlpha : public MagAlphaGen3 { public: - MagAlpha(); + MagAlpha(); + void begin(uint8_t spiChipSelectPin); + void begin(int32_t spiSclkFrequency, uint8_t spiMode, uint8_t spiChipSelectPin); + void setSpiDataMode(uint8_t spiMode); + uint16_t readAngleRaw(); + uint16_t readAngleRaw(bool* error); }; - #endif //MAGALPHA_H diff --git a/src/MagAlphaBase.cpp b/src/MagAlphaBase.cpp index 80b9fdb..efaf6a8 100644 --- a/src/MagAlphaBase.cpp +++ b/src/MagAlphaBase.cpp @@ -89,9 +89,9 @@ void MagAlphaSPI::setSpiChipSelectPin(uint8_t spiChipSelectPin){ uint16_t MagAlphaSPI::readAngleRaw16Quick(){ uint16_t angle; digitalWrite(_spiChipSelectPin, LOW); - // angle = _spi->transfer16(0x0000); //Read 16-bit angle - spi0_hw->dr = 0x0000; - angle = spi0_hw->dr; + angle = _spi->transfer16(0x0000); //Read 16-bit angle + //spi0_hw->dr = 0x0000; + //angle = spi0_hw->dr; digitalWrite(_spiChipSelectPin, HIGH); return angle; } @@ -102,6 +102,22 @@ uint16_t MagAlphaSPI::readAngleRaw16Quick(){ MagAlphaSSI::MagAlphaSSI(){ } +void MagAlphaSSI::begin(){ + _ssi = &SPI; + _clockFrequency = 1000000; + _ssi->begin(); + _ssi->beginTransaction(SPISettings(_clockFrequency, MSBFIRST, MagAlphaSSIMode::MODE_B)); +} + +/* +void MagAlphaSSI::begin(int32_t ssiSsckFrequency){ + _ssi = &SPI; + _clockFrequency = ssiSsckFrequency; + _ssi->begin(); + _ssi->beginTransaction(SPISettings(_clockFrequency, MSBFIRST, MagAlphaSSIMode::MODE_B)); +} +*/ + void MagAlphaSSI::begin(SPIClass *ssi){ begin(1000000, MagAlphaSSIMode::MODE_A, ssi); } @@ -197,7 +213,6 @@ uint8_t MagAlphaSSI::readAngleRaw8(){ return (data & 0x7F80) >> 7; } - /*====================================================================================*/ /*============================== MagAlphaI2C =========================================*/ /*====================================================================================*/ diff --git a/src/MagAlphaBase.h b/src/MagAlphaBase.h index fc7161a..2129685 100644 --- a/src/MagAlphaBase.h +++ b/src/MagAlphaBase.h @@ -74,6 +74,9 @@ class MagAlphaBase { // bool _featureSuppored; }; +/*====================================================================================*/ +/*============================== MagAlphaSPI =========================================*/ +/*====================================================================================*/ class MagAlphaSPI : public MagAlphaBase { public: MagAlphaSPI(); @@ -91,9 +94,14 @@ class MagAlphaSPI : public MagAlphaBase { SPIClass *_spi; }; +/*====================================================================================*/ +/*============================== MagAlphaSSI =========================================*/ +/*====================================================================================*/ class MagAlphaSSI : public MagAlphaBase { public: MagAlphaSSI(); + void begin(); + //void begin(int32_t ssiClkFrequency); void begin(SPIClass *ssi = &SPI); void begin(int32_t ssiSsckFrequency, SPIClass *ssi = &SPI); void begin(int32_t ssiSsckFrequency, MagAlphaSSIMode ssiMode, SPIClass *ssi = &SPI); @@ -111,6 +119,9 @@ class MagAlphaSSI : public MagAlphaBase { SPIClass *_ssi; }; +/*====================================================================================*/ +/*============================== MagAlphaI2C =========================================*/ +/*====================================================================================*/ class MagAlphaI2C : public MagAlphaBase { public: MagAlphaI2C(); @@ -125,4 +136,5 @@ class MagAlphaI2C : public MagAlphaBase { uint32_t _clockFrequency; TwoWire *_i2c; }; + #endif //MAGALPHABASE_H diff --git a/src/MagAlphaGen3.cpp b/src/MagAlphaGen3.cpp index 5b1d5a8..4ee0a62 100644 --- a/src/MagAlphaGen3.cpp +++ b/src/MagAlphaGen3.cpp @@ -136,6 +136,7 @@ void MagAlphaGen3::writeRegisterBurst(uint8_t address, uint8_t valueArray[], uin delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 120ns after register readout } +/* uint16_t MagAlphaGen3::detectSensorGeneration(){ uint16_t chipId; digitalWrite(_spiChipSelectPin, LOW); @@ -148,6 +149,7 @@ uint16_t MagAlphaGen3::detectSensorGeneration(){ delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 750ns after register readout return chipId; } +*/ uint16_t MagAlphaGen3::getZero() { diff --git a/src/MagAlphaGen3.h b/src/MagAlphaGen3.h index 4ea74ae..ea8513a 100644 --- a/src/MagAlphaGen3.h +++ b/src/MagAlphaGen3.h @@ -32,9 +32,9 @@ class MagAlphaGen3: public MagAlphaSPI { uint8_t writeRegister(uint8_t address, uint8_t value) override; void readRegisterBurst(uint8_t address, uint8_t valueArray[], uint16_t numberOfRegister) override; void writeRegisterBurst(uint8_t address, uint8_t valueArray[], uint16_t numberOfRegister) override; - + //Detect the sensor generation - uint16_t detectSensorGeneration() override; + //uint16_t detectSensorGeneration() override; //Set Key Parameters uint16_t getZero() override; diff --git a/src/MagAlphaGen4.cpp b/src/MagAlphaGen4.cpp index 9881e42..96ad239 100644 --- a/src/MagAlphaGen4.cpp +++ b/src/MagAlphaGen4.cpp @@ -139,6 +139,7 @@ void MagAlphaGen4::writeRegisterBurst(uint8_t address, uint8_t valueArray[], uin delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 120ns after register readout } +/* uint16_t MagAlphaGen4::detectSensorGeneration(){ uint16_t chipId; digitalWrite(_spiChipSelectPin, LOW); @@ -151,6 +152,7 @@ uint16_t MagAlphaGen4::detectSensorGeneration(){ delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 120ns after register readout return chipId; } +*/ uint16_t MagAlphaGen4::getZero() { diff --git a/src/MagAlphaGen4.h b/src/MagAlphaGen4.h index 8eedf75..6cf68da 100644 --- a/src/MagAlphaGen4.h +++ b/src/MagAlphaGen4.h @@ -32,7 +32,7 @@ class MagAlphaGen4: public MagAlphaSPI { void writeRegisterBurst(uint8_t address, uint8_t valueArray[], uint16_t numberOfRegister) override; //Detect the sensor generation - uint16_t detectSensorGeneration() override; + //uint16_t detectSensorGeneration() override; //Set Key Parameters uint16_t getZero() override; diff --git a/src/MagAlphaGen6.cpp b/src/MagAlphaGen6.cpp index 464c867..ba1d2e5 100644 --- a/src/MagAlphaGen6.cpp +++ b/src/MagAlphaGen6.cpp @@ -142,6 +142,7 @@ void MagAlphaGen6::writeRegisterBurst(uint8_t address, uint8_t valueArray[], uin delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 120ns after register readout } +/* uint16_t MagAlphaGen6::detectSensorGeneration(){ uint16_t chipId; digitalWrite(_spiChipSelectPin, LOW); @@ -154,6 +155,7 @@ uint16_t MagAlphaGen6::detectSensorGeneration(){ delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 120ns after register readout return chipId; } +*/ uint16_t MagAlphaGen6::getZero() { diff --git a/src/MagAlphaGen6.h b/src/MagAlphaGen6.h index 4ffeb39..73f314d 100644 --- a/src/MagAlphaGen6.h +++ b/src/MagAlphaGen6.h @@ -32,7 +32,7 @@ class MagAlphaGen6: public MagAlphaSPI { void writeRegisterBurst(uint8_t address, uint8_t valueArray[], uint16_t numberOfRegister) override; //Detect the sensor generation - uint16_t detectSensorGeneration() override; + //uint16_t detectSensorGeneration() override; //Set Key Parameters uint16_t getZero() override; diff --git a/src/MagAlphaGen7.cpp b/src/MagAlphaGen7.cpp index 07bcfc3..5da0809 100644 --- a/src/MagAlphaGen7.cpp +++ b/src/MagAlphaGen7.cpp @@ -160,10 +160,12 @@ void MagAlphaGen7::writeRegisterBurst(uint8_t address, uint8_t valueArray[], uin writeRegisterBurst(address, valueArray, numberOfRegister, &error, &inversion, &wrongHandshaking); } +/* uint16_t MagAlphaGen7::detectSensorGeneration(){ bool error, inversion; return readRegister(REG_PID, &error, &inversion) >> 4; } +*/ uint16_t MagAlphaGen7::getZero(){ bool error, inversion; diff --git a/src/MagAlphaGen7.h b/src/MagAlphaGen7.h index bbdfa20..bf6e2b0 100644 --- a/src/MagAlphaGen7.h +++ b/src/MagAlphaGen7.h @@ -33,7 +33,7 @@ class MagAlphaGen7: public MagAlphaSPI { void writeRegisterBurst(uint8_t address, uint8_t valueArray[], uint16_t numberOfRegister) override; //Detect the sensor generation - uint16_t detectSensorGeneration() override; + //uint16_t detectSensorGeneration() override; //Set Key Parameters uint16_t getZero() override; diff --git a/src/MagAlphaGen8.cpp b/src/MagAlphaGen8.cpp index 1b0d218..2c7f8ed 100644 --- a/src/MagAlphaGen8.cpp +++ b/src/MagAlphaGen8.cpp @@ -139,6 +139,7 @@ void MagAlphaGen8::writeRegisterBurst(uint8_t address, uint8_t valueArray[], uin delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 120ns after register readout } +/* uint16_t MagAlphaGen8::detectSensorGeneration(){ uint16_t chipId; digitalWrite(_spiChipSelectPin, LOW); @@ -151,6 +152,7 @@ uint16_t MagAlphaGen8::detectSensorGeneration(){ delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 120ns after register readout return chipId; } +*/ uint16_t MagAlphaGen8::getZero() { diff --git a/src/MagAlphaGen8.h b/src/MagAlphaGen8.h index fcc96a7..fa62c77 100644 --- a/src/MagAlphaGen8.h +++ b/src/MagAlphaGen8.h @@ -31,9 +31,8 @@ class MagAlphaGen8: public MagAlphaSPI { void readRegisterBurst(uint8_t address, uint8_t valueArray[], uint16_t numberOfRegister) override; void writeRegisterBurst(uint8_t address, uint8_t valueArray[], uint16_t numberOfRegister) override; - //Detect the sensor generation - uint16_t detectSensorGeneration() override; + //uint16_t detectSensorGeneration() override; //Set Key Parameters uint16_t getZero() override; diff --git a/src/MagAlphaLegacy.cpp b/src/MagAlphaLegacy.cpp deleted file mode 100644 index 793eaee..0000000 --- a/src/MagAlphaLegacy.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/*************************************************** - Arduino library for the MPS MagAlpha magnetic angle sensor - Supports MagAlpha 3rd generation Sensors. MagAlpha sensor detects the - absolute angular position of a permanent magnet, typically a diametrically - magnetized cylinder on the rotating shaft. - ----> http://www.monolithicpower.com/Products/Position-Sensors/Products-Overview - Written by Mathieu Kaelin for Monolithic Power Systems. - MIT license, all text above must be included in any redistribution -****************************************************/ - -#include "MagAlpha.h" - -//MagAlpha Read/Write Register Command -#define READ_REG_COMMAND (0b010 << 13) -#define WRITE_REG_COMMAND (0b100 << 13) - -#define SSI_MODE SPI_MODE1 - -MagAlpha::MagAlpha(){ -} - -void MagAlpha::begin(uint8_t spiChipSelectPin){ - setSpiChipSelectPin(spiChipSelectPin); - _speedMaximum = 10000000; - _spiMode = MA_SPI_MODE_3; - SPI.begin(); - SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, _spiMode)); -} - -void MagAlpha::begin(int32_t spiSclkFrequency, uint8_t spiMode, uint8_t spiChipSelectPin){ - setSpiChipSelectPin(spiChipSelectPin); - _speedMaximum = spiSclkFrequency; - _spiMode = spiMode; - SPI.begin(); - SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, _spiMode)); -} - -void MagAlpha::end(){ - SPI.endTransaction(); - SPI.end(); -} - -double MagAlpha::readAngle(){ - uint16_t angle; - double angleInDegree; - angle = readAngleRaw16(); - angleInDegree = (angle*360.0)/65536.0; - return angleInDegree; -} - -uint16_t MagAlpha::readAngleRaw(){ - return readAngleRaw16(); -} - -uint16_t MagAlpha::readAngleRaw16(){ - uint16_t angle; - digitalWrite(_spiChipSelectPin, LOW); - angle = SPI.transfer16(0x0000); //Read 16-bit angle - digitalWrite(_spiChipSelectPin, HIGH); - return angle; -} - -uint8_t MagAlpha::readAngleRaw8(){ - uint8_t angle; - digitalWrite(_spiChipSelectPin, LOW); - angle = SPI.transfer(0x00); //Read 8-bit angle - digitalWrite(_spiChipSelectPin, HIGH); - return angle; -} - -uint16_t MagAlpha::readAngleRaw(bool* error){ - uint16_t angle; - uint8_t parity; - uint8_t highStateCount = 0; - - digitalWrite(_spiChipSelectPin, LOW); - angle = SPI.transfer16(0x0000); - parity = SPI.transfer(0x00); - digitalWrite(_spiChipSelectPin, HIGH); - - parity = ((parity & 0x80) >> 7); - //Count the number of 1 in the angle binary value - for (int i=0;i<16;++i){ - if ((angle & (1 << i)) != 0){ - highStateCount++; - } - } - //check if parity bit is correct - if ((highStateCount % 2) == 0){ - if (parity == 0){ - *error = false; - } - else{ - *error = true; - } - } - else{ - if (parity == 1){ - *error = false; - } - else{ - *error = true; - } - } - return angle; -} - -uint8_t MagAlpha::readRegister(uint8_t address){ - uint8_t readbackRegisterValue; - digitalWrite(_spiChipSelectPin, LOW); - SPI.transfer16(READ_REG_COMMAND | ((address & 0x1F) << 8) | 0x00); - digitalWrite(_spiChipSelectPin, HIGH); - delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 750ns before register readout - digitalWrite(_spiChipSelectPin, LOW); - readbackRegisterValue = ((SPI.transfer16(0x0000) & 0xFF00) >> 8); - digitalWrite(_spiChipSelectPin, HIGH); - delayMicroseconds(1); //Wait for 1us (=1000 ns) to respect tIdleReg of 750ns after register readout - return readbackRegisterValue; -} - -uint8_t MagAlpha::writeRegister(uint8_t address, uint8_t value){ - uint8_t readbackRegisterValue; - digitalWrite(_spiChipSelectPin, LOW); - SPI.transfer16(WRITE_REG_COMMAND | ((address & 0x1F) << 8) | value); - digitalWrite(_spiChipSelectPin, HIGH); - delay(20); //Wait for 20ms - digitalWrite(_spiChipSelectPin, LOW); - readbackRegisterValue = ((SPI.transfer16(0x0000) & 0xFF00) >> 8); - digitalWrite(_spiChipSelectPin, HIGH); - //readbackRegisterValue should be equal to the written value - return readbackRegisterValue; -} - -void MagAlpha::setSpiClockFrequency(uint32_t speedMaximum){ - _speedMaximum = speedMaximum; - SPI.endTransaction(); - SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, _spiMode)); -} - -void MagAlpha::setSpiDataMode(uint8_t spiMode){ - _spiMode = spiMode; - SPI.endTransaction(); - SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, _spiMode)); -} - -void MagAlpha::setSpiChipSelectPin(uint8_t spiChipSelectPin){ - _spiChipSelectPin = spiChipSelectPin; - pinMode(_spiChipSelectPin, OUTPUT); - digitalWrite(_spiChipSelectPin, HIGH); -} - -double MagAlpha::convertRawAngleToDegree(uint8_t rawAngleDataBitLength, uint16_t rawAngle){ - double angleInDegree; - angleInDegree = (rawAngle*360.0)/((double)pow(2, rawAngleDataBitLength)); - return angleInDegree; -} - -MagAlphaSSI::MagAlphaSSI(){ -} -void MagAlphaSSI::begin(){ - _speedMaximum = 1000000; - SPI.begin(); - SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, SSI_MODE)); -} - -void MagAlphaSSI::begin(int32_t ssiSsckFrequency){ - _speedMaximum = ssiSsckFrequency; - SPI.begin(); - SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, SSI_MODE)); -} - -void MagAlphaSSI::end(){ - SPI.endTransaction(); - SPI.end(); -} - -double MagAlphaSSI::readAngle(){ - uint16_t angle; - double angleInDegree; - angle = readAngleRaw(); - angleInDegree = (angle*360.0)/65536.0; - return angleInDegree; -} - -uint16_t MagAlphaSSI::readAngleRaw(){ - uint16_t angle; - uint8_t angle0; - uint8_t angle1; - uint8_t angle2; - - angle0 = SPI.transfer(0x00); - angle1 = SPI.transfer(0x00); - angle2 = SPI.transfer(0x00); - - angle = ((angle0 & 0x7F) << 9) | (angle1 << 1) | ((angle2 & 0x80) >> 7); - return angle; -} - -uint16_t MagAlphaSSI::readAngleRaw(bool* error){ - uint16_t angle; - uint8_t parity; - uint8_t highStateCount = 0; - uint8_t angle0; - uint8_t angle1; - uint8_t angle2; - - angle0 = SPI.transfer(0x00); - angle1 = SPI.transfer(0x00); - angle2 = SPI.transfer(0x00); - - angle = ((angle0 & 0x7F) << 9) | (angle1 << 1) | ((angle2 & 0x80) >> 7); - parity = ((angle2 & 0x40) >> 6); - //Count the number of 1 in the angle binary value - for (int i=0;i<16;++i){ - if ((angle & (1 << i)) != 0){ - highStateCount++; - } - } - //check if parity bit is correct - if ((highStateCount % 2) == 0){ - if (parity == 0){ - *error = false; - } - else{ - *error = true; - } - } - else{ - if (parity == 1){ - *error = false; - } - else{ - *error = true; - } - } - return angle; -} - -void MagAlphaSSI::setSsiClockFrequency(uint32_t speedMaximum){ - _speedMaximum = speedMaximum; - SPI.endTransaction(); - SPI.beginTransaction(SPISettings(_speedMaximum, MSBFIRST, SSI_MODE)); -} - -double MagAlphaSSI::convertRawAngleToDegree(uint8_t rawAngleDataBitLength, uint16_t rawAngle){ - double angleInDegree; - angleInDegree = (rawAngle*360.0)/((double)pow(2, rawAngleDataBitLength)); - return angleInDegree; -} diff --git a/src/MagAlphaLegacy.h b/src/MagAlphaLegacy.h deleted file mode 100644 index dcc44ce..0000000 --- a/src/MagAlphaLegacy.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************** - Arduino library for the MPS MagAlpha magnetic angle sensor - Supports MagAlpha 3rd generation Sensors. MagAlpha sensor detects the - absolute angular position of a permanent magnet, typically a diametrically - magnetized cylinder on the rotating shaft. - ----> http://www.monolithicpower.com/Products/Position-Sensors/Products-Overview - Written by Mathieu Kaelin for Monolithic Power Systems. - MIT license, all text above must be included in any redistribution - ****************************************************/ - -#ifndef MAGALPHA_H -#define MAGALPHA_H - -#if (ARDUINO >= 100) - #include "Arduino.h" -#else - #include "WProgram.h" -#endif -#include - - //SPI Mode: MagAlpha Gen3 support SPI mode 3 and 0 [SPI_MODE3, SPI_MODE0] -#define MA_SPI_MODE_0 SPI_MODE0 -#define MA_SPI_MODE_3 SPI_MODE3 - -class MagAlpha { -public: - MagAlpha(); - void begin(uint8_t spiChipSelectPin); - void begin(int32_t spiSclkFrequency, uint8_t spiMode, uint8_t spiChipSelectPin); - void end(); - double readAngle(); - uint16_t readAngleRaw(); - uint16_t readAngleRaw(bool* error); - uint16_t readAngleRaw16(); - uint8_t readAngleRaw8(); - uint8_t readRegister(uint8_t address); - uint8_t writeRegister(uint8_t address, uint8_t value); - void setSpiClockFrequency(uint32_t speedMaximum); - void setSpiDataMode(uint8_t spiMode); - void setSpiChipSelectPin(uint8_t spiChipSelectPin); - double convertRawAngleToDegree(uint8_t rawAngleDataBitLength, uint16_t rawAngle); -private: - uint32_t _speedMaximum; - uint8_t _spiMode; - uint8_t _spiChipSelectPin; -}; - -class MagAlphaSSI { -public: - MagAlphaSSI(); - void begin(); - void begin(int32_t ssiSsckFrequency); - void end(); - double readAngle(); - uint16_t readAngleRaw(); - uint16_t readAngleRaw(bool* error); - void setSsiClockFrequency(uint32_t speedMaximum); - double convertRawAngleToDegree(uint8_t rawAngleDataBitLength, uint16_t rawAngle); -private: - uint32_t _speedMaximum; -}; -#endif //MAGALPHA_H diff --git a/src/MagAlphaPartProperties.h b/src/MagAlphaPartProperties.h index 770d90b..8a65128 100644 --- a/src/MagAlphaPartProperties.h +++ b/src/MagAlphaPartProperties.h @@ -52,7 +52,7 @@ typedef enum MagAlphaPartNumber{ MA750 = 6, //MA_GEN_1 MA700A = 7, //MA_GEN_2 MA102 = 8, //MA_GEN_3 - MA302 = 9, //MA_GEN_3 + MA302 = 9, //MA_GEN_3 MA310 = 10, //MA_GEN_3 MA330 = 11, //MA_GEN_3 MA702 = 12, //MA_GEN_3