I use NRF51822qfaa,s110 v8.0, now I use master TWI to drive the TWI bus chip. the TWI bus chip Slave Address is 0x48.please see the below program .
question:
1.The slave_add is 0X24,is OK?if is not ,please tell me the right value.
2.The nrf_drv_twi_rx function is return 3,is not 0,why?please tell me which is wrong?
3.Who can offert an example use twi for init/read/write chip?
#define slave_add 0x24
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(0);
uint8_t reg[10] = {0,0};
void twi_init(void)
{
ret_code_t err_code;
nrf_drv_twi_config_t p_twi_config;
// = NRF_DRV_TWI_DEFAULT_CONFIG(1);
// Set up TWI configuration default values
p_twi_config.frequency=NRF_TWI_FREQ_100K;
p_twi_config.scl=TWI0_CONFIG_SCL;
p_twi_config.sda=TWI0_CONFIG_SDA;
p_twi_config.interrupt_priority=APP_IRQ_PRIORITY_LOW;
err_code = nrf_drv_twi_init(&m_twi, &p_twi_config, 0);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&m_twi);
reg[0]=0x00;
nrf_delay_ms(5);
err_code = nrf_drv_twi_rx(&m_twi, slave_add, reg, 1, false);//true);
nrf_delay_ms(50);
}