Skip to content

Commit 7d4fd45

Browse files
committed
Add SPI frequency override in begin()
1 parent 9adcd7f commit 7d4fd45

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

examples/Arduino/Example2_Advanced/Example2_Advanced.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define SERIAL_PORT Serial
1818

1919
#define SPI_PORT SPI // Your desired SPI port. Used only when "USE_SPI" is defined
20+
#define SPI_FREQ 10000000// You can override the default SPI frequency
2021
#define CS_PIN 2 // Which pin you connect CS to. Used only when "USE_SPI" is defined
2122

2223
#define WIRE_PORT Wire // Your desired Wire port. Used when "USE_SPI" is not defined
@@ -47,7 +48,7 @@ void setup() {
4748
while( !initialized ){
4849

4950
#ifdef USE_SPI
50-
myICM.begin( CS_PIN, SPI_PORT );
51+
myICM.begin( CS_PIN, SPI_PORT, SPI_FREQ ); // Here we are using the user-defined SPI_FREQ as the clock speed of the SPI bus
5152
#else
5253
myICM.begin( WIRE_PORT, AD0_VAL );
5354
#endif

src/ICM_20948.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,16 +485,17 @@ ICM_20948_Status_e ICM_20948_I2C::writeMag( uint8_t reg, uint8_t* pdata, uint8_t
485485

486486

487487
// SPI
488-
SPISettings ICM_20948_SPI_DEFAULT_SETTINGS(ICM_20948_SPI_DEFAULT_FREQ, ICM_20948_SPI_DEFAULT_ORDER, ICM_20948_SPI_DEFAULT_MODE);
488+
489+
// SPISettings ICM_20948_SPI_DEFAULT_SETTINGS(ICM_20948_SPI_DEFAULT_FREQ, ICM_20948_SPI_DEFAULT_ORDER, ICM_20948_SPI_DEFAULT_MODE);
489490

490491
ICM_20948_SPI::ICM_20948_SPI(){
491492

492493
}
493494

494-
ICM_20948_Status_e ICM_20948_SPI::begin( uint8_t csPin, SPIClass &spiPort){
495+
ICM_20948_Status_e ICM_20948_SPI::begin( uint8_t csPin, SPIClass &spiPort, uint32_t SPIFreq ){
495496
// Associate
496497
_spi = &spiPort;
497-
_spisettings = ICM_20948_SPI_DEFAULT_SETTINGS;
498+
_spisettings = SPISettings(SPIFreq, ICM_20948_SPI_DEFAULT_ORDER, ICM_20948_SPI_DEFAULT_MODE);
498499
_cs = csPin;
499500

500501

src/ICM_20948.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class ICM_20948_SPI : public ICM_20948 {
144144

145145
ICM_20948_SPI(); // Constructor
146146

147-
ICM_20948_Status_e begin( uint8_t csPin, SPIClass &spiPort = SPI );
147+
ICM_20948_Status_e begin( uint8_t csPin, SPIClass &spiPort = SPI, uint32_t SPIFreq = ICM_20948_SPI_DEFAULT_FREQ );
148148
};
149149

150150

0 commit comments

Comments
 (0)