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

Interrupt Priority for I2C, BLE and Timer

Hi All ,

I am using NRF52 , S132 softdevice ............

I need to read a data every 5s (In Timer1 interrupt handler) from I2C slave and sent it via BLE.

But what happen if this I2C read/write is enabled am not able to connect and receive data through BLE. What I think is I2C(has priority high) blocks BLE events. When I try to low the priority to LOW, It is not working with timer (Priority Low), I also tried lowest for I2C but that doesnot work ,,,

What priority I can set for these so that my app work as I expected?? Can I increase the priority for sofdevice events??

Updated 26/4/2016:-

Following is the code I use,

void timer_interrupt(int time_in_sec)
{
    NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
    NRF_TIMER1->TASKS_CLEAR = 1;
    NRF_TIMER1->PRESCALER = 9;
    NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_32Bit;
    NRF_TIMER1->CC[0] = 31250;
    NRF_TIMER1->CC[1] = (31250*time_in_sec);
    NRF_TIMER1->INTENSET = ((TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos)
                         | (TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos)) ;
    NRF_TIMER1->SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
	  NVIC_SetPriority(TIMER1_IRQn, APP_IRQ_PRIORITY_LOWEST);
    NVIC_EnableIRQ(TIMER1_IRQn);
    NRF_TIMER1->TASKS_START = 1;
}

void TIMER1_IRQHandler(void)
{  
		
    if ((NRF_TIMER1->EVENTS_COMPARE[1] != 0))
    {
        NRF_TIMER1->EVENTS_COMPARE[1] = 0;           //Clear compare register 0 event 
				int err_code=0;
				err_code=read_motion_sensor(); // This do I2C read
				if(err_code != NRF_SUCCESS){
				printf("Reading the data failed \r\n");
				}		  
    }
}

main() {
        ret_code_t err_code;

	const nrf_drv_twi_config_t i2c_config = {
		.scl                = I2C_SCL_PIN,
		.sda                = I2C_SDA_PIN,
		.frequency          = NRF_TWI_FREQ_100K,
		.interrupt_priority = APP_IRQ_PRIORITY_HIGH
	};

	err_code = nrf_drv_twi_init(&i2c_instance, &i2c_config,NULL, NULL);
	APP_ERROR_CHECK(err_code);
       /************** BLE Initialisation *****************/
       timer_interrupt(5);------------------------------------------------>interrupt every 5s,
      /***************** Start Advertisement **************/
       /*************** WFE ****************************/

}

Updated 27/4/2016

uint32_t ble_send_data(uint8_t *data,uint8_t length,uint8_t msgtype)
    {
    	uint32_t err_code;
    	static uint8_t msg_buff[BLE_NUS_MAX_DATA_LEN];
    	memset(msg_buff,'\0',BLE_NUS_MAX_DATA_LEN);
    	msg_buff[HEADER_FIELD]= HEADER;
    	msg_buff[SEQUENCE_NUMBER_FIELD] = sequence_number;
    	msg_buff[TYPE_FIELD] = msgtype;
    	msg_buff[PACKET_SIZE_FIELD]=length;
    	msg_buff[NUM_PACKET_FIELD]=1;
    	memcpy(&msg_buff[VALUABLE_INFO_FIELD],data,length);
    	msg_buff[CRC_FIELD]=CRC8(data,length,7);
    	err_code=ble_nus_string_send(&m_nus, msg_buff,BLE_NUS_MAX_DATA_LEN);
    #if ENABLE_BLE_DEBUG
    	print_string("Err_Code");
    	print_hex(err_code,4);
    	print_string("\r\n");
    #endif
    	sequence_number++; //TODO need to Keep this outside this function
    	return err_code;
    }

Thanks a lot in Advance!!

Thangaraj.

Parents Reply Children
No Data
Related