10-10-2019 01:39 PM
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++);
}
}
}
10-11-2019 03:48 PM
10-14-2019 08:55 AM
It indeed appears that the resistors on the auxiliary interface are missing. I will check with my colleague how this can be fixed and will report back if the problem is solved.
03-12-2020 12:00 AM - edited 03-12-2020 05:16 PM
Was the missing pull-ups the issue? I'm facing similar symptoms and we also forgot to add them to our board.
EDIT: Adding the pullups fixed our problem.
07-01-2020 02:41 PM
Did someone of you have an example code with a modified driver code including STM32 devices using HAL library?