Hello,
I am working on an nRF51822 custom board application which is reading data from external sensor through TWI. It is based on the MPU6050 driver available in the SDK and the twi_hw_master.c
bool l3g4200d_init(uint8_t device_address)
{
bool transfer_succeeded = true;
m_device_address = (uint8_t)(device_address << 1);
// Read and verify product ID
transfer_succeeded &= l3g4200d_verify_product_id();
ConfigureGyroscope();
return transfer_succeeded;
}
bool l3g4200d_verify_product_id(void)
{
uint8_t who_am_i;
if (twi_master_init())
{
if (l3g4200d_register_read(ADDRESS_WHO_AM_I, &who_am_i, 1))
{
if (who_am_i != expected_who_am_i)
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
}
When I enter the verification function in transfer_succeeded &= l3g4200d_verify_product_id();
I always get false as a return from l3g4200d_register_read(ADDRESS_WHO_AM_I, &who_am_i, 1) so it never goes to check whether the who am I value is what it is supposed to be.
There is the read function:
bool l3g4200d_register_read(uint8_t register_address, uint8_t * destination, uint8_t number_of_bytes)
{
bool transfer_succeeded;
transfer_succeeded = twi_master_transfer(m_device_address, ®ister_address, 1, TWI_DONT_ISSUE_STOP);
transfer_succeeded &= twi_master_transfer(m_device_address|TWI_READ_BIT, destination, number_of_bytes, TWI_ISSUE_STOP);
return transfer_succeeded;
uint8_t config = 0;
}
If anybody have faced this problem or have an idea why it is happening, I would be grateful. Regards Stanislav