I'm trying to use an MMA8652FC accelerometer with the nRF52832. When I call the function nrf_drv_twi_tx() the board hard faults, stopping in <SDK>\components\libraries\util\app_error_weak.c line 100. I'm not sure what is happening and I don't get any output from the debugger.
Code:
uint8_t read_mma8652fc_reg(uint16_t addr) // TODO: Fix
{
ret_code_t err_code;
const uint8_t* caddr = (uint8_t*)&addr;
uint8_t value;
err_code = nrf_drv_twi_tx(&m_twi, MMA8652FC_ADDR, caddr, sizeof *caddr, true); // <-- Crash in this function
APP_ERROR_CHECK(err_code);
if (err_code == NRF_SUCCESS)
{
err_code = nrf_drv_twi_rx(&m_twi, MMA8652FC_ADDR, (uint8_t*)&value, 1);
APP_ERROR_CHECK(err_code);
}
return value;
}
void init_twi(void)
{
ret_code_t err_code;
const nrf_drv_twi_config_t twi_MMA8652FC_config = {
.scl = ACCELEROMETER_SCL_PIN,
.sda = ACCELEROMETER_SDA_PIN,
.frequency = NRF_DRV_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};
err_code = nrf_drv_twi_init(&m_twi, &twi_MMA8652FC_config, twi_handler, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&m_twi);
}