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

TWI and COMP simultaneous work

Hello!

I move my device from nRF52811 to nRF52820 (QDAA-C00) and I have a problem when using a comparator and TWI

If I configure TWI0 or TWI1 and use it with external ADC, all work perfect.

If I configure Comparator COMP, it work good too.

But if I enable Comparator while work TWI, TWI stopped imideately.

This is what happens to the TWI bus:

For TWI I use P0.00 (SCL), and P0.01 (SDA).

For COMP I use analog inputs AIN0, AIN1, AIN3 (P0.02, P0.03, P0.05 respectively).

Here is initialisation of TWI:

void I2CInit(void)
{
	NRF_TWIM1->INTENSET = 0x40202; // STOPPED ERROR SUSPENDED

	NRF_TWIM1->ENABLE = 6;
	NRF_TWIM1->PSEL.SCL = 0x0;
	NRF_TWIM1->PSEL.SDA = 0x1;
	
	NRF_TWIM1->FREQUENCY = 0x06400000;

	NRF_TWIM1->SHORTS = 0x0;

	NRF_TWIM1->EVENTS_LASTRX = 1;
	NRF_TWIM1->EVENTS_LASTTX = 1;

	NRF_TWIM1->TXD.LIST = 0;
	NRF_TWIM1->RXD.LIST = 0;
	
	sd_nvic_ClearPendingIRQ(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);
	sd_nvic_SetPriority(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, 2);
	sd_nvic_EnableIRQ(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);
}

void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler(void)
{
	if(NRF_TWIM1-> EVENTS_STOPPED != 0)
	{
		EventsCounters.AdcTwiInt++;
		NRF_TWIM1->EVENTS_STOPPED = 0;
		ADC_TWI_Interrupt();
	}
	if(NRF_TWIM1-> EVENTS_SUSPENDED != 0)
	{
		NRF_TWIM1->EVENTS_SUSPENDED = 0;
	}
	if(NRF_TWIM1->EVENTS_ERROR != 0)
	{
		NRF_TWIM1->EVENTS_ERROR = 0;
		AdcInterfaceError();
	}
}

Here is initialisation of COMP:

e_err ComparatorHandlerInit(void)
{
	NRF_COMP->PSEL = 2;
	NRF_COMP->MODE = 1;
	NRF_COMP->REFSEL = 2; // 2.4V
	
	NRF_COMP->ENABLE = 2;
	
	MeasureVccVoltage();
}

I've tried enable and disable COMP interrupts and It didn't change anything.

When I write 2 to NRF_COMP->ENABLE, TWI stops working. And if I write NRF_COMP->ENABLE to zero, TWI continue working.

What I doing wrong?

Parents Reply Children
Related