Commit 12c61ddd authored by Damien George's avatar Damien George
Browse files

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.
parent b3bc2ee1
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment