This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why this example doenst work?

void i2c_config(){
	NRF_TWI0->PSELSCL=I2C_SCL;
	NRF_TWI0->PSELSDA=I2C_SDA;
	NRF_TWI0->ENABLE=5; //Enable
	NRF_TWI0->FREQUENCY=0x01980000;//100kbps
	NRF_TWI0->ADDRESS=SLAVE_ADDR;//0x53
	NRF_TWI0->EVENTS_TXDSENT=0;
	NRF_TWI0->EVENTS_RXDREADY=0;
	NRF_TWI0->INTENCLR = 0xffffffffUL;
	NRF_TWI0->SHORTS = 0;
	NRF_TWI0>INTENSET=1UL<<I2C_TX_FLAG_BIT|1UL<<I2C_RX_FLAG_BIT|1UL<<I2C_ERROR_FLAG_BIT;
}

int main(void)
{
	nrf_gpio_cfg_output(LED_1);
	nrf_gpio_cfg_output(LED_2);
	nrf_gpio_cfg_input(I2C_SDA, NRF_GPIO_PIN_NOPULL);
	nrf_gpio_cfg_input(I2C_SCL, NRF_GPIO_PIN_NOPULL);
	i2c_config();
	NRF_TWI0->TASKS_STARTTX;
	NRF_TWI0->TXD =ADXL345_ID_REG;
	while(NRF_TWI0->EVENTS_TXDSENT!=1);
	
	NRF_TWI0->EVENTS_TXDSENT=0;
	NRF_TWI0->TASKS_STARTRX;
	
	while(NRF_TWI0->EVENTS_RXDREADY!=1);
	NRF_TWI0->EVENTS_RXDREADY=0;
	int number=NRF_TWI0->RXD;
	
	if(number==0xE5)
		NRF_GPIO->OUTSET=(1UL<<LED_1);
		else
		NRF_GPIO->OUTSET=(1UL<<LED_2);
		
		NRF_TWI0->TASKS_STOP;
}

This flag while NRF_TWI0->EVENTS_TXDSENT is never equal 1.

Related