Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: ak7451ctrl.cpp
- Revision:
- 34:1ea3357c8d9a
- Parent:
- 30:5a241d9b3262
- Parent:
- 25:76c11ab5060e
- Child:
- 39:3821886c902e
--- a/ak7451ctrl.cpp Fri Apr 28 20:32:31 2017 +0000 +++ b/ak7451ctrl.cpp Wed May 03 18:00:45 2017 +0000 @@ -22,17 +22,22 @@ subId = subid; if(subId == SUB_ID_AK7451){ - SPI* mSpi; - DigitalOut* mCs; + SPI* mSpi; // SPI connection + DigitalOut* mCs; // Chip select pin + + // Initialize SPI connection AK7451::Status status = AK7451::ERROR; mSpi = new SPI(SPI_MOSI, SPI_MISO, SPI_SCK); mSpi->format(8,1); // 8bit, Mode=1 mSpi->frequency(1000000); + + // Initialize chip select pin mCs = new DigitalOut(SPI_CS); ak7451 = new AK7451(); ak7451->begin(mSpi, mCs); sensorName = "AK7451"; + // Set to User Mode status = ak7451->setOperationMode(AK7451::AK7451_USER_MODE); if( status != AK7451::SUCCESS ){ MSG("#AK7451 user mode failed.\r\n"); @@ -46,13 +51,16 @@ // E_ABZ_HYS 0x2 ABZ Hysteresis=1LSB // ABZ_RES 0x0 ABZ phase resolution = 1024ppr char data[2] = {0x02,0xA0}; + status = ak7451->writeEEPROM(0x07,data); // set clockwise if( status != AK7451::SUCCESS ){ MSG("#AK7451 write EEPROM failed.\r\n"); return AkmSensor::ERROR; } MSG("#AK7451 write EEPROM succeed.\r\n"); + /* + // Set to Normal Mode status = ak7451->setOperationMode(AK7451::AK7451_NORMAL_MODE); if( status != AK7451::SUCCESS ){ MSG("#AK7451 normal mode failed.\r\n");