Skip to content

Commit f3824df

Browse files
committed
Fix SPI class after Magnetometer logic addition
1 parent cb2e346 commit f3824df

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/ICM_20948.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ ICM_20948_Status_e ICM_20948::startupDefault ( void ){
290290
// Should try testing I2C master functionality on a bare ICM chip w/o TXS0108 level shifter...
291291

292292
_has_magnetometer = false;
293+
retval = ICM_20948_Stat_Ok; // reset the retval because we handled it in this cases
293294
}
294295

295296
status = retval;
@@ -505,6 +506,11 @@ ICM_20948_Status_e ICM_20948_SPI::begin( uint8_t csPin, SPIClass &spiPort){
505506

506507
// _spi->begin(); // Moved into user's sketch
507508

509+
// 'Kickstart' the SPI hardware.
510+
_spi->beginTransaction(_spisettings);
511+
_spi->transfer(0x00);
512+
_spi->endTransaction();
513+
508514
// Set up the serif
509515
_serif.write = ICM_20948_write_SPI;
510516
_serif.read = ICM_20948_read_SPI;
@@ -513,6 +519,14 @@ ICM_20948_Status_e ICM_20948_SPI::begin( uint8_t csPin, SPIClass &spiPort){
513519
// Link the serif
514520
_device._serif = &_serif;
515521

522+
// Perform default startup
523+
status = startupDefault();
524+
if( status != ICM_20948_Stat_Ok ){
525+
return status;
526+
}
527+
528+
// todo: disable I2C interface to prevent accidents
529+
516530
return ICM_20948_Stat_Ok;
517531
}
518532

@@ -602,6 +616,11 @@ ICM_20948_Status_e ICM_20948_write_SPI(uint8_t reg, uint8_t* data, uint32_t len,
602616
SPISettings spisettings = ((ICM_20948_SPI*)user)->_spisettings;
603617
if(_spi == NULL){ return ICM_20948_Stat_ParamErr; }
604618

619+
// 'Kickstart' the SPI hardware. This is a fairly high amount of overhead, but it guarantees that the lines will start in the correct states even when sharing the SPI bus with devices that use other modes
620+
_spi->beginTransaction(spisettings);
621+
_spi->transfer(0x00);
622+
_spi->endTransaction();
623+
605624
digitalWrite(cs, LOW);
606625
// delayMicroseconds(5);
607626
_spi->beginTransaction(spisettings);
@@ -624,6 +643,11 @@ ICM_20948_Status_e ICM_20948_read_SPI(uint8_t reg, uint8_t* buff, uint32_t len,
624643
SPISettings spisettings = ((ICM_20948_SPI*)user)->_spisettings;
625644
if(_spi == NULL){ return ICM_20948_Stat_ParamErr; }
626645

646+
// 'Kickstart' the SPI hardware. This is a fairly high amount of overhead, but it guarantees that the lines will start in the correct states
647+
_spi->beginTransaction(spisettings);
648+
_spi->transfer(0x00);
649+
_spi->endTransaction();
650+
627651
digitalWrite(cs, LOW);
628652
// delayMicroseconds(5);
629653
_spi->beginTransaction(spisettings);

0 commit comments

Comments
 (0)