Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: ak7451ctrl.cpp
- Revision:
- 25:76c11ab5060e
- Parent:
- 16:d85be9bafb80
- Child:
- 34:1ea3357c8d9a
--- a/ak7451ctrl.cpp Thu Apr 13 22:50:02 2017 +0000 +++ b/ak7451ctrl.cpp Fri Apr 14 20:13:38 2017 +0000 @@ -24,25 +24,31 @@ 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"); return AkmSensor::ERROR; } MSG("#AK7451 user mode succeed.\r\n"); - - char data[2] = {0x02,0x00}; // set clockwise rotation + + // Set clockwise rotation + char data[2] = {0x02,0x00}; status = ak7451->writeEEPROM(0x07,data); // set clockwise if( status != AK7451::SUCCESS ){ MSG("#AK7451 write EEPROM failed.\r\n"); @@ -50,6 +56,7 @@ } 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");