This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541

Other Parts Discussed in Thread: Z-STACK

Hi,

I am new to the BLE programming.

I am trying to read some sensor values, through a pressure based sensor. This needs to be done within a given time limit (say 5 s). I tried doing something with "osal_start_timerEx", but this seems to get to the event only after the timer expires. 

Please advice on how this could be done.

  • Can you show me how you do this?
  • I am trying actuate an LED, if the sensors are being tapped within 5 seconds. The sensors have been configured in GPIO with the variables statSensor1, statSensor2, statSensor3, statSensor4.

    This is what I had earlier

    statSensor = ( statSensor1 & statSensor2 & statSensor3 & statSensor4 );                     //Reading if all four sensors are tapped
    if( statSensor == 1)
    {
    osal_start_timerEx( sensor_TaskID, sensor_EventID, 5000 );
    }
    

    However, after doing a bit of reading, below is something I came up with.

    uint32 current_time = osal_GetSystemClock()
    uint32 temp = current_time + 5000;
    while (current_time != temp){
    statSensor = ( statSensor1 & statSensor2 & statSensor3 & statSensor4 ); 
    if (statSensor){
    //this to do if the sensors are tapped within 5 seconds
    break;
    }
    current_time = osal_GetSystemClock()
    }

    The second piece of code seems to be logically correct, but for some reason, the sensor taps are not being detected any more.

  • You put "statSensor = ( statSensor1 & statSensor2 & statSensor3 & statSensor4 )" in a while loop and I don't see you read those value in the while loop. Where do you update value to statSensor1, statSensor2, statSensor3, and statSensor4?
  • Actually the there was a simple mis-connection problem with the sensors. It seems to be working fine now :).
    However, the code on line 9 : current_time = osal_GetSystemClock() does not seem to return the updated timestamp. This causes an infinite loop. Is there any alternative to osal_GetSystemClock?
  • You can use the following code from Z-Stack to count time instead of osal_GetSystemClock. osal_GetSystemClock can not work in while loop.


    /*********************************************************************
    * @fn Onboard_wait
    *
    * @brief Delay wait
    *
    * @param uint16 - time to wait
    *
    * @return none
    *
    *********************************************************************/
    void Onboard_wait( uint16 timeout )
    {
    while (timeout--)
    {
    asm("NOP");
    asm("NOP");
    asm("NOP");
    }
    }
  • Thanks for the reply YK Chen.
    However, please correct me if I am wrong - as far as I can understand, this would create a waiting timeout for 5 seconds. I am not sure how my objectives would be met here.
    I need to actuate the LED only if the sensors are tapped within 5 seconds. If the timer goes beyond 5 seconds, nothing is to be done.
  • Yes osal_start_timerEx( sensor_TaskID, sensor_EventID, 5000 ); will send an event after 5 seconds.

    I don't fully understand what you're trying to do but you may want to use one of the general purpose timer modules. These are describe in the chip user's guide.