@@ -134,7 +134,7 @@ bool QwDevKX13X::softwareReset()
134
134
cntl2.all = 0 ;
135
135
cntl2.bits .srst = 1 ; // This is a long winded, but definitive way of setting the software reset bit
136
136
137
- retVal = writeRegisterByte (SFE_KX13X_CNTL2, cntl2.all ); // Do the reset
137
+ writeRegisterByte (SFE_KX13X_CNTL2, cntl2.all ); // Do the reset
138
138
139
139
uint8_t loopCount = 0 ;
140
140
while (loopCount < 10 ) // Reset takes about 2ms. Timeout after 10ms
@@ -1351,23 +1351,34 @@ bool QwDevKX13X::runCommandTest()
1351
1351
cntl2.bits .cotc = 1 ; // This is a long winded, but definitive way of setting the COTC bit
1352
1352
tempVal = cntl2.all ;
1353
1353
1354
- // Going to assume that communication is working at this point.
1355
- writeRegisterByte (SFE_KX13X_CNTL2, tempVal);
1354
+ retVal = writeRegisterByte (SFE_KX13X_CNTL2, tempVal); // Start the test
1356
1355
1357
- readRegisterRegion (SFE_KX13X_COTR, &tempVal, 1 );
1356
+ if (retVal != 0 )
1357
+ return false ;
1358
+
1359
+ retVal = readRegisterRegion (SFE_KX13X_COTR, &tempVal, 1 ); // Check COTR is 0xAA
1360
+
1361
+ if (retVal != 0 )
1362
+ return false ;
1358
1363
1359
1364
if (tempVal != 0xAA )
1360
1365
return false ;
1361
1366
1362
- readRegisterRegion (SFE_KX13X_CNTL2, &tempVal, 1 );
1367
+ retVal = readRegisterRegion (SFE_KX13X_CNTL2, &tempVal, 1 );
1368
+
1369
+ if (retVal != 0 )
1370
+ return false ;
1363
1371
1364
1372
cntl2.all = tempVal;
1365
- if (cntl2.bits .cotc != 0 )
1373
+ if (cntl2.bits .cotc != 0 ) // Check the COTC bit has been cleared
1366
1374
return false ;
1367
1375
1368
- readRegisterRegion (SFE_KX13X_COTR, &tempVal, 1 );
1376
+ retVal = readRegisterRegion (SFE_KX13X_COTR, &tempVal, 1 );
1377
+
1378
+ if (retVal != 0 )
1379
+ return false ;
1369
1380
1370
- if (tempVal != 0x55 )
1381
+ if (tempVal != 0x55 ) // Check COTR is 0x55
1371
1382
return false ;
1372
1383
1373
1384
return true ;
0 commit comments