I am writing a program for an nRF52 based board using the Redbear Arduino Library. Effectively treating my board as a BLE Nano 2.
I have a timer that ticks every x milliseconds, for example 50ms.
Inside that timer I would like to read data from an I2C sensor and add the reading to a buffer.
I am aware that by default, when inside the timer ISR, interrupts are disabled. I would like to know how to briefly re-enable the I2C interrupt, and get the sensor reading, then disable the interrupts again.
The interval between sensor readings is critical, and I don't just want to set a flag in the timer ISR as I don't know how long it will be before that flag is checked.
Please can someone instruct me on how to breifly enable the I2C interrupts from within a timer ISR?
I have experimented with:
__disable_irq();
__enable_irq();
NVIC_EnableIRQ(SPI0_TWI0_IRQn);
NRF_TWI0->INTENSET = 1;
No joy with any of these, I understand that some of them only work from certain locations in software, so were not functioning correctly within an ISR.
void setup() {
// put your setup code here, to run once
NVIC_SetPriority (TIMER0_IRQn, 2);
NVIC_SetPriority (TIMER1_IRQn, 2);
NVIC_SetPriority (TIMER2_IRQn, 2);
NVIC_SetPriority (SPI0_TWI0_IRQn, 3);
NVIC_SetPriority (SPI1_TWI1_IRQn, 3);
Serial.begin(9600);
Serial.println("Start ");
Serial.print("Priority of TWI0: ");
Serial.println(NVIC_GetPriority (SPI0_TWI0_IRQn));
Serial.println(NVIC_GetPriority (SPI1_TWI1_IRQn));
Serial.print("Priority of Ticker: ");
Serial.println(NVIC_GetPriority (TIMER0_IRQn));
Serial.println(NVIC_GetPriority (TIMER1_IRQn));
Serial.println(NVIC_GetPriority (TIMER2_IRQn));
Wire.begin();
__disable_irq();
__enable_irq();
ticker1s.attach(task_handle, 1);
Wire.requestFrom(0x02,6);
}
void task_handle(void) {
__enable_irq();
Serial.println("Task handle ");
Serial.println("-IRQ enable status: ");
Serial.println(NVIC_GetEnableIRQ(SPI0_TWI0_IRQn));
Serial.println(NVIC_GetEnableIRQ(SPI1_TWI1_IRQn));
NVIC_EnableIRQ(SPI0_TWI0_IRQn);
NRF_TWI0->INTENSET = 1;
NVIC_EnableIRQ(SPI1_TWI1_IRQn);
NRF_TWI1->INTENSET = 1;
Serial.println("-IRQ enable status: ");
Serial.println(NVIC_GetEnableIRQ (SPI0_TWI0_IRQn));
Serial.println(NVIC_GetEnableIRQ (SPI1_TWI1_IRQn));
delay(1000);
Wire.requestFrom(0x02,6);
}