Hello, I am trying to get a BHI160 working with a STM32 microcontroller. My code is based on the sample code in the GitHub repository. I have attached my code at the bottom of this post. Communicating with the chip seems to work fine. bhy_driver_init() returns 0. However, the INT pin never changes, so my code is stuck in the loops that wait for an edge on INT. If I remove the loops and start reading FIFO data right away, no data is received. I expect an initialization meta message and the sensor data from the accelerometer, but data_read is always 0. int ret;
uint8_t fifo[100];
uint8_t *fifoptr = NULL;
uint8_t bytes_left_in_fifo = 0;
uint16_t bytes_remaining = 0;
uint16_t bytes_read = 0;
bhy_data_generic_t fifo_packet;
bhy_data_type_t packet_type;
if(bhy_driver_init(bhy1_fw)) {
return EB_ERROR;
}
while(HAL_GPIO_ReadPin(INT_BHI_GPIO_Port, INT_BHI_Pin) == GPIO_PIN_SET) ;
while(HAL_GPIO_ReadPin(INT_BHI_GPIO_Port, INT_BHI_Pin) == GPIO_PIN_RESET) ;
ret = bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, 10, 0, VS_FLUSH_NONE, 0, 0);
while(1) {
ret = bhy_read_fifo(fifo + bytes_left_in_fifo, 100 - bytes_left_in_fifo, &bytes_read, &bytes_remaining);
bytes_read += bytes_left_in_fifo;
fifoptr = fifo;
packet_type = BHY_DATA_TYPE_PADDING;
do {
/* this function will call callbacks that are registered */
ret = bhy_parse_next_fifo_packet(&fifoptr, &bytes_read, &fifo_packet, &packet_type);
/* the logic here is that if doing a partial parsing of the fifo, then we should not parse */
/* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */
/* packet */
} while ((ret == BHY_SUCCESS) && (bytes_read > (bytes_remaining ? 18 : 0)));
bytes_left_in_fifo = 0;
if (bytes_remaining) {
/* shifts the remaining bytes to the beginning of the buffer */
while (bytes_left_in_fifo < bytes_read) {
fifo[bytes_left_in_fifo++] = *(fifoptr++);
}
}
}
... View more