summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-04-29 15:43:15 +0100
committerDamien George <damien.p.george@gmail.com>2016-04-29 15:43:15 +0100
commit12c61dddddb52af0d02f89c5679bfc911ae3df90 (patch)
tree65f669e27762aeefc2dcabb40c44f3224685b08a
parentb3bc2ee1b926d6fd6ba2c3be0f8d2d71298b9a82 (diff)
downloadmicropython-12c61dddddb52af0d02f89c5679bfc911ae3df90.tar.gz
micropython-12c61dddddb52af0d02f89c5679bfc911ae3df90.zip
stmhal/accel: Raise an exception if the accel couldn't be initialised.
On PYBLITEv1.0 there is no accelerometer and in this case the Accel() constructor should not silently succeed.
-rw-r--r--stmhal/accel.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/stmhal/accel.c b/stmhal/accel.c
index 434a92a008..34e9d8e0e1 100644
--- a/stmhal/accel.c
+++ b/stmhal/accel.c
@@ -89,15 +89,17 @@ STATIC void accel_start(void) {
HAL_StatusTypeDef status;
- //printf("IsDeviceReady\n");
for (int i = 0; i < 10; i++) {
status = HAL_I2C_IsDeviceReady(&I2CHandle1, MMA_ADDR, 10, 200);
- //printf(" got %d\n", status);
if (status == HAL_OK) {
break;
}
}
+ if (status != HAL_OK) {
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "accelerometer not found"));
+ }
+
// set MMA to active mode
uint8_t data[1] = {1}; // active mode
status = HAL_I2C_Mem_Write(&I2CHandle1, MMA_ADDR, MMA_REG_MODE, I2C_MEMADD_SIZE_8BIT, data, 1, 200);