Using this code:
ret_code_t error;
nrf_drv_twi_t twi;
twi.reg = {((NRF_TWI_Type *) 0x40003000UL)};
twi.drv_inst_idx = 0;
twi.use_easy_dma = 0;
nrf_drv_twi_config_t twi_config;
twi_config.frequency = NRF_TWI_FREQ_100K;
twi_config.scl = 2;
twi_config.sda = 3;
twi_config.interrupt_priority = 1;
cout << "A" << endl;
error = nrf_drv_twi_init(&twi, &twi_config, twi_handler, NULL);
if (error != NRF_SUCCESS) {
cout << "Error in nrf_drv_twi_init: " << error << endl;
wait_ms(1000);
return 1;
}
cout << "B" << endl;
nrf_drv_twi_enable(&twi);
uint8_t data[2];
data[0] = 2;
data[1] = 0;
cout << "C" << endl;
error = nrf_drv_twi_tx(&twi, HMC5883_ADDRESS_MAG, data, 2, false);
if (error != NRF_SUCCESS) {
cout << "Error in nrf_drv_twi_tx: " << error << endl;
wait_ms(1000);
return 1;
}
wait_ms(5000);
cout << "D" << endl;
data[0] = 1;
data[1] = 0x20;
error = nrf_drv_twi_tx(&twi, HMC5883_ADDRESS_MAG, data, 2, false);
if (error != NRF_SUCCESS) {
cout << "Error in nrf_drv_twi_tx: " << error << endl;
wait_ms(1000);
return 1;
}
cout << "E" << endl;
wait_ms(1000);
I am able to communicate on TWI on some pins, but not others. Specifically we have a NRF51822 based device that to the best of my knowledge has TWI on 26/27. I am not able to get this code working on those pins, but the device works when using mbed talking TWI on those pins. Either I get no response, or I get internal error 3. Do I need to configure pins for using in TWI? Can I check if something else has configured them in an incompatible way?