I debugged the program and found some issues i want to share, hopefully they help us to find a solution. It still seems like that the bhy_driver_init(&bhy1_fw) is working fine. After that i have this code where i can also find an error return from the Sensor. bhy_mapping_matrix_set(PHYSICAL_SENSOR_INDEX_ACC, bhy_mapping_matrix_config);
bhy_mapping_matrix_set(PHYSICAL_SENSOR_INDEX_MAG, mag_mapping_matrix_config);
bhy_mapping_matrix_set(PHYSICAL_SENSOR_INDEX_GYRO, bhy_mapping_matrix_config); After the Matrix was set up, it tries to write the parameter page to the Sensor with the function bhy_write_parameter_page(). Within this function it selects the parameter and reads the acknowledgments. BHY_RETURN_FUNCTION_TYPE bhy_write_parameter_page(uint8_t page, uint8_t parameter, uint8_t *data, uint8_t length)
{
/* variable used for return the status of communication result */
BHY_RETURN_FUNCTION_TYPE com_rslt = BHY_COMM_RES;
uint8_t v_parameter_ack = BHY_INIT_VALUE;
uint8_t v_parameter_ack_check = BHY_INIT_VALUE;
/* write values to the load address*/
if (length > MAX_WRITE_BYTES)
{
length = MAX_WRITE_BYTES;
}
else if (length == 0)
{
return BHY_SUCCESS;
}
com_rslt = bhy_write_reg(BHY_I2C_REG_PARAMETER_WRITE_BUFFER_ZERO, data, length);
/* select the page*/
if (page > MAX_PAGE_NUM)
{
page = MAX_PAGE_NUM;
}
else if (page == 0)
{
return BHY_SUCCESS;
}
page = ((length & 0x07) << 4) | page;
com_rslt += bhy_write_reg(BHY_I2C_REG_PARAMETER_PAGE_SELECT__REG, &page, 1);
/* select the parameter*/
parameter |= 0x80;
com_rslt += bhy_set_parameter_request(parameter);
for (v_parameter_ack_check = BHY_INIT_VALUE;
v_parameter_ack_check < BHY_PARAMETER_ACK_LENGTH;
v_parameter_ack_check++)
{
/* read the acknowledgment*/
com_rslt += bhy_get_parameter_acknowledge(&v_parameter_ack);
if (v_parameter_ack == parameter)
{
com_rslt += BHY_SUCCESS;
break;
}
else if (v_parameter_ack == BHY_PARAMETER_ACK_CHECK)
{
bhy_delay_msec(BHY_PARAMETER_ACK_DELAY);
com_rslt += BHY_ERROR;
}
else
{
/* device not ready yet */
bhy_delay_msec(1);
}
}
return com_rslt;
} But when it reads the acknowledgments it alwas ends up in an error executing this line com_rslt += BHY_ERROR; . This is the same for all three matrix mapping functions. I am facing the same problem with the function bhy_enable_virtual_sensor(). It uses the function bhy_write_parameter_bytes(); which trys to write the parameter bytes to the sensor and check the acknowledgments afterwards. So this Function causes the error which returns -18 for the function bhy_enable_virtual_sensor(). I guess my write/read operation is still not working properly. i tried to implement the read function with the function HAL_I2C_Mem_Read() like this. int8_t sensor_i2c_read(uint8_t slave_address7, uint8_t subaddress, uint8_t *pBuffer, uint16_t ReadNumbr)
{
uint16_t DevAddress = slave_address7 << 1;
HAL_StatusTypeDef status = HAL_OK;
status = HAL_I2C_Mem_Read(&hi2c1, DevAddress, (uint16_t)subaddress, I2C_MEMADD_SIZE_8BIT, pBuffer, ReadNumbr, HAL_MAX_DELAY);
if(status != HAL_OK)
{
HAL_Delay(1);
}
return 0;
} With my logic analyzer i created a capture file of my i2c transactions, hopefully you can see anything in there.
... View more