Skip to content

Commit fa1ecda

Browse files
committed
stmhal, accel: Increase start-up times to 30ms; add extra 30ms delay.
For accel to start-up reliably, need to wait 30ms between on/off, and 30ms for it to enter active mode. With this fix the accel can be read immediately after initialising it. Addresses issue adafruit#763.
1 parent 3c4db9f commit fa1ecda

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

stmhal/accel.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ STATIC void accel_start(void) {
8383
I2CHandle1.Init.OwnAddress2 = 0xfe; // unused
8484
i2c_init(&I2CHandle1);
8585

86-
// turn off AVDD, wait 20ms, turn on AVDD, wait 20ms again
86+
// turn off AVDD, wait 30ms, turn on AVDD, wait 30ms again
8787
GPIOB->BSRRH = GPIO_PIN_5; // turn off
88-
HAL_Delay(20);
88+
HAL_Delay(30);
8989
GPIOB->BSRRL = GPIO_PIN_5; // turn on
90-
HAL_Delay(20);
90+
HAL_Delay(30);
9191

9292
HAL_StatusTypeDef status;
9393

@@ -100,11 +100,12 @@ STATIC void accel_start(void) {
100100
}
101101
}
102102

103-
//printf("MemWrite\n");
104-
uint8_t data[1];
105-
data[0] = 1; // active mode
103+
// set MMA to active mode
104+
uint8_t data[1] = {1}; // active mode
106105
status = HAL_I2C_Mem_Write(&I2CHandle1, MMA_ADDR, MMA_REG_MODE, I2C_MEMADD_SIZE_8BIT, data, 1, 200);
107-
//printf(" got %d\n", status);
106+
107+
// wait for MMA to become active
108+
HAL_Delay(30);
108109
}
109110

110111
/******************************************************************************/

0 commit comments

Comments
 (0)