I have a small collection of i2c devices on the bus that can be jumpered in (sda/scl disconnected). I am currently using SDK v10 and Keil v4.
I wrote this code to namely sweep through all addresses and read out the first few registers of each. But I run this code with the twi_scanner example program and I end up getting error codes of 0, and readResults of 0 as well. How should I fix my code to successfully get the registers of the i2c devices?
//==========START example==================
#<included everything needed for this thing to compile>
void twi_init (void){
ret_code_t err_code;
//mma7660 is from the example, won't bother changing variable names.
const nrf_drv_twi_config_t twi_mma_7660_config = {
.scl = 16,
.sda = 15,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH
};
err_code = nrf_drv_twi_init(&m_twi_mma_7660, &twi_mma_7660_config, twi_handler, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&m_twi_mma_7660);
}
int main(void){
uart_config();
twi_init();
uint8_t readResult = 0x00;
ret_code_t rt;
for(int adr = 0; adr< 128; ++adr){
for(int i = 0; i<0xF; ++i){
rt = nrf_drv_twi_rx(&m_twi_mma_7660, adr, &readResult, 1, false);
nrf_delay_ms(100);
printf("%d>>0x%d:%x\t%d\r\n",adr,i,readResult,rt);
}
}
while(true){
printf("done\r\n");
nrf_delay_ms(500);
}
}
//================END of example======================