When I run nrfx_twi_tx i get the error code 0x01, and I can't find out why. I'm running SDK15.0 on PCA10040, using ses.
My init function looks like this:
void twi_init (uint8_t scl, uint8_t sda)
{
nrfx_err_t err_code;
const nrfx_twi_config_t twi_config = {
.scl = scl,
.sda = sda,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = NRFX_TWI_DEFAULT_CONFIG_IRQ_PRIORITY,
.hold_bus_uninit = NRFX_TWI_DEFAULT_CONFIG_HOLD_BUS_UNINIT
};
err_code = nrfx_twi_init(&g_twi, &twi_config, NULL, NULL);
APP_ERROR_CHECK(err_code);
#ifdef DEBUG
if(err_code != NRFX_SUCCESS){
NRF_LOG_ERROR("ERROR INITIALIZING NRFX_TWI");
}
else{
NRF_LOG_INFO("INITIALIZED NRFX_TWI");
}
NRF_LOG_FLUSH();
#endif
nrfx_twi_enable(&g_twi);
}
The initialization is successful.
Then I try to send some data, and get 0x01 error code. The code:
void ssd1306_send_command(uint8_t command){
nrfx_err_t error = NRFX_SUCCESS;
uint8_t data[2];
data[0] = 0x00; // Co = 0, D/C = 0 CONTROL BYTE
data[1] = command;
error = nrfx_twi_tx(&g_twi, SSD1306_TWI_ADDRESS, data, (sizeof(data)), true);
#ifdef DEBUG
if (error = !NRFX_SUCCESS){
NRF_LOG_ERROR("Error sending command to display. Errorcode: %x", error);
NRF_LOG_FLUSH();
}
else{
NRF_LOG_INFO("Sent 0x%x to display", command);
NRF_LOG_FLUSH();
}
#endif
}
I'm new to using the nrfx drivers, but have used nrf_drv_twi before with success. Any help would be appreciated.