Hi
I discovered I strange behaviour using twi. I am using sdk-14.2.0, and Segger Studio. I started with the twi_scanner projected that I found in examples/peripherals. I have shortened it to demonstrate the problem I discovered.
The example as shown below works fine. It communicate with my digital potmeter at address 0x2f. When I look at the logic-analyzer I can see that the sda and scl lines works fine.
However, if I uncomment NRF_LOG_DEFAULT_BACKENDS_INIT(), the twi interface don't drive the SDA line any more.
Do you have any explanation of this unexpected behaviour?
Regards Arne
#define TWI_INSTANCE_ID 0
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
void twi_init (void)
{
ret_code_t err_code;
const nrf_drv_twi_config_t twi_config = {
.scl = 7,
.sda = 6,
.frequency = NRF_TWI_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false,
.hold_bus_uninit = false
};
err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&m_twi);
}
int main(void)
{
ret_code_t err_code;
uint8_t address;
uint8_t sample_data;
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
//NRF_LOG_DEFAULT_BACKENDS_INIT();
twi_init();
address=0x2f; // Potmeter
err_code = nrf_drv_twi_rx(&m_twi, address, &sample_data, sizeof(sample_data));
if (err_code == NRF_SUCCESS)
{
NRF_LOG_INFO("TWI device detected at address 0x%x.", address);
}
NRF_LOG_FLUSH()
}