This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C interrupt while softdevice enabled

Hello,

i'm sorry for asking again, but i read nearly all threads about I2C and didn't get any answer yet.

I want to use the interrupt to control the I2C sequences and safe energy (instead of using while loops)

I replaced the NRF_TWI1->INTENSET.... with sd_app function below... If i start a transmition it never goes into the handler or generates an event. can anybody tell me why?

Is the NVIC_ENABLEIRQ right to use? in the end i have the usual handler.

	void init_TWI1()
{
	//I2C Init start
uint32_t err_code;
NVIC_EnableIRQ(SPI1_TWI1_IRQn);
NRF_GPIO->PIN_CNF[1] = 0x60C;
NRF_TWI1->PSELSCL = 0;	//P0 als SCL
NRF_TWI1->PSELSDA = 1;	//P1 als SDA      
NRF_TWI1->FREQUENCY = 0x06680000;	//Frequenz = 400kHz

err_code = sd_ppi_channel_assign(0,
																		&(NRF_TWI1->EVENTS_BB),
                                 &(NRF_TWI1->EVENTS_TXDSENT));

	
	
		
//I2C init end
}



	void SPI1_TWI1_IRQHandler(void) 
{
	if(NRF_TWI1->EVENTS_RXDREADY != 0)
	{
		NRF_TWI1->EVENTS_RXDREADY = 0;
	}
		if(NRF_TWI1->EVENTS_TXDSENT != 0)
	{
		NRF_TWI1->EVENTS_TXDSENT = 0;
	}
		if(NRF_TWI1->EVENTS_BB != 0)
	{
		sd_app_evt_wait();
		NRF_TWI1->EVENTS_BB = 0;
	}

}
Parents
  • If NRF_TWI1->INTENSET=... is removed then you have disabled peripheral interrupt and it will never go to nvic. There are two stages of interrupt control: in the peripheral using INTENSET/INTENCLR you enable particular peripheral events as interrupts and then in NVIC you control general interrupt from this peripheral.

    It is recommended to access nvic using softdevice API. As TWI is not used by softdevice you can access TWI registers directly.

    As mnhs mentioned, it is vital to set proper interrupt priority (1 or 3, you can also use app_irq_priority_t from app_util_platform.h in SDK)

Reply
  • If NRF_TWI1->INTENSET=... is removed then you have disabled peripheral interrupt and it will never go to nvic. There are two stages of interrupt control: in the peripheral using INTENSET/INTENCLR you enable particular peripheral events as interrupts and then in NVIC you control general interrupt from this peripheral.

    It is recommended to access nvic using softdevice API. As TWI is not used by softdevice you can access TWI registers directly.

    As mnhs mentioned, it is vital to set proper interrupt priority (1 or 3, you can also use app_irq_priority_t from app_util_platform.h in SDK)

Children
No Data
Related