From 12c61dddddb52af0d02f89c5679bfc911ae3df90 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 29 Apr 2016 15:43:15 +0100 Subject: [PATCH] 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. --- stmhal/accel.c | 6 ++++-- 1 file 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);