TWIM 1 Timeslot no interrupt

Hi,

As i2c communication + computation takes 45ms in my timer interrupt that happen each 100ms and gave issue with SD, I decided to set a flag in the interrupt and execute sensors operation in the main loop.

It works but...it was estonishing slow.

Timer is properly called each 100ms. I see on scope my debug pin toggling.

But my second debug pin that should toggle in the main loop if flag is set, toogle only each 490ms ! It means that something is taking the lead in paralelle, is taking a lot of time and is not  allowing me to reach the main each 100ms like I would like.

I guess Soft Device (s113 in my case) take this time. For example, communication that should take 13ms when no sd is running ( on the 45ms in total for my sensors tasks, rest is big float computation) takes 350ms ! 26 times the time it should !

After some search, i discovered Timeslot, that seems to be appropriate for perdiodic reading in real time. It should avoid radio interupt during the 45ms i need to communicate, compute and update my ble caracteristic.

I have implemented the code that blinks the pin each 100ms, it works fine and it is quiet precise even when i'm connected to my app.

Now, i have added my sensors task after the toggling of my debug pin. I have an issue because after the first byte sent via TWIM1, the program is stuck on : 

    while(nrfx_twim_is_busy(&my_twi)){;}

So i guess it is related to TWIM1 interrupt that should be disabled may be.

 So i enable interrupt this way, but i'm still stuck on the same line:

nrf_radio_signal_callback_return_param_t * radio_callback(uint8_t signal_type)
{
ret_code_t err_code;

    switch(signal_type)
    {
        case NRF_RADIO_CALLBACK_SIGNAL_TYPE_START:
            //Start of the timeslot - set up timer interrupt
            signal_callback_return_param.params.request.p_next = NULL;
            signal_callback_return_param.callback_action = NRF_RADIO_SIGNAL_CALLBACK_ACTION_NONE;
            
            NRF_TIMER0->INTENSET = TIMER_INTENSET_COMPARE0_Msk;
            NRF_TIMER0->CC[0] = m_slot_length - 1000;
            NVIC_EnableIRQ(TIMER0_IRQn); 
            
            //I add these lines below:
            NVIC_ClearPendingIRQ(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);
            NRF_TWI1->INTENSET = TWIM_INTENSET_LASTRX_Msk|TWIM_INTENSET_LASTTX_Msk ;
            NVIC_EnableIRQ(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn); 

            nrf_gpio_pin_toggle(DEBUG_PIN2); //flo Toggle DEBUG_PIN

Is there something else to be able to communicate on twim1 ( with dma) during a timeslot please ?

I see on Power Profile kit a big spike to 45mA each 18ms (i'mat +8dBm). I wonder if it is not the source of the delay it occurs on my sensors task executed in the main:

Do you know what it could be? It looks likes a connection packet or something to acknowledge connexion is still alive, but it' s increasing consumption a lot ! I dont't think it is advertising cause i set it to 400ms and i confirm it with nrf Connect mobil app. I'm using the basic ble_peripheral example with S113. I'm peripheral and GATT server.

Thank you!

Parents
  • I tried to set interrupt from 2 to 0 but it is the same, still blocked on the while.

    But i can see all the byte on twim line on my scope so the hardware/twim send fucntion works properly when called in the timeslot).

    It is just the interrupt that seems to be not autorized. 

    i can confirm that by mentionning the soft device specification:

    Then how to proceed to be able to communicate with my i2c sensors during timeslot?

    I tried to replace while ( is busy) that wait for interuption by nrf(delay) even it is dirty, without succes yet. It is not really a solution but ...

  • Hi,

    Olfox said:

    Then how to proceed to be able to communicate with my i2c sensors during timeslot?

    I don't think timeslot is suited for the issue you are trying to solve here.

    As i2c communication + computation takes 45ms in my timer interrupt that happen each 100ms and gave issue with SD

    1) What issue with the SD are you getting? Could you elaborate on that.

    2) Did you try using the scheduler as suggest by Einar Thorsrud in your other post?  Communicate with sensor in timer interrupt occurs issue 

Reply Children
  • Hi Sigurd,

    1) What issue with the SD are you getting? Could you elaborate on that.

    I mean i had issue because the 45ms it should take was also taking too long in the interrupt timer and i'm not able to read caracteristic sometimes, program is stuck

    2) Did you try using the scheduler as suggest by Einar Thorsrud in your other post? 

    To be honnest i look at it, but i was not convinced it would help more than the first proposal Einar did ( jut set a flag into the timer interrupt and check it into main() ). It looks complex compared than just a flag set and clear once done. 

    By studying the link you gave, i don't really see added value to the scheduler ( may be i don't see benefit because a lack of knowledge). So to deeply understand i compared both method but even with that, i don't clearly see how scheduler will avoid SD to take the lead.

    A part of adding the orange time, what is the benefit on timing or how it could help with my issue ?

    3) Also, why timeslot is not the most appropriate solution compared to scheduler for example? I have the feeling to do something really complex, but it is just communicate with a sensor and to be able to get a ble carac updated each max 100ms with my sensor data. Is it a special complex case ? I guess it is a common customer need no ? 

    May be timeslot is overkill in this case. I will be really happy to understand and being convinced that scheduler will help, can you guide me a bit more in detail on how to properly proceed in the big line please . I will start to learn about it on devzone because infocenter documentation is a bit light on this subject.

    Thank a lot Sigurd for your help i hope to have this working really really soon. 

  • Hi Sigurd, 

    I found the Einard tutorial concerning scheduler here:

     nRF5 SDK Scheduler Tutorial 

    It confirms what i understood previouly but doesn't help me to undestand why i will be able to not be interrupted during my 45s sensor task (by SD i guess)

    Even with scheduler, i don't see how it will avoid to increase my sensors task time from 45ms to 490ms.

    A part of timeslot i don't see any other way in fact a the moment. May be   have good argument too :D ?

    Thanks a for your help

Related