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 and i2c in sleep mode

Hello Everyone!

I have created task for reading data from i2c sensor. 

uint16 UvSensor_ProcessEvent( uint8 task_id, uint16 events )
{
   VOID task_id; // OSAL required parameter that isn't used in this function
  
    /*
   * Read event. Read data from UV sensor
   */
   if ( events & EVENT_TASK_READ )
   {
      UvLevel = SI1445_readUV();
     
      LedRedBlink(); // only for debug
      osal_start_timerEx(UvSensorTaskId,EVENT_TASK_READ, 5000 );
      
     // Clear event and return.
       return ( events ^ EVENT_TASK_READ);
   }
}

LedRedBlink() - led blink function for indication; 


when I deleted (disable sleep mode)

POWER_SAVING

from Defined symbols (Preprocessor)  everything works fine. 

when sleep mode is working  - led isn't blinking and system not answer. 

How can I disable sleep mode only for i2c ?

Thanks for help.

  • When you enable power savings, the OSAL should handle bring the device in and out of PM2 in between events. This means OSAL will bring the device out of PM2 every 5 sec for your TASK_READ event. If you are the I2C master then you don't have to worry about I2C activity when you are asleep because the only activity on the bus will occur during SI1445_readUV().

    This makes me think that maybe OSAL is dropping you into PM3 which means the device will only awake on an external interrupt. If you have no pending events, OSAL will put the device in PM3 and depending on how you have written your application you may not have any pending events keeping the device only in PM2 before you start your periodic sensor reads.

    Can you tell if the device is still doing other operations? If it is doing anything else then my guess is off. Otherwise, try to call the osal_start_timerEx() for the TASK_READ event in the START_DEVICE_EVT similar to what is done with the PERIODIC_EVT in the simpleBLEPeripheral project and see if that makes a difference. That would prevent the device from entering PM3.

    -Matt

  • I'm using "Thermometer" - example. Device reads data from sensor (via i2c) and sends to smartphone.

    in OSAL_thermometer.c I've added  two lines:

    UvSensor_ProcessEvent
    
    UvSensor_Init( taskID );

    // The order in this table must be identical to the task initialization calls below in osalInitTask.
    const pTaskEventHandlerFn tasksArr[] =
    {
      LL_ProcessEvent,
      Hal_ProcessEvent,
      HCI_ProcessEvent,
    #if defined ( OSAL_CBTIMER_NUM_TASKS )
      OSAL_CBTIMER_PROCESS_EVENT( osal_CbTimerProcessEvent ),
    #endif
      L2CAP_ProcessEvent,
      GAP_ProcessEvent,
      GATT_ProcessEvent,
      SM_ProcessEvent,
      GAPRole_ProcessEvent,
      GAPBondMgr_ProcessEvent,
      GATTServApp_ProcessEvent,
      Thermometer_ProcessEvent,
      UvSensor_ProcessEvent
    };

    void osalInitTasks( void )
    {
    uint8 taskID = 0;

    tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);
    osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));

    /* LL Task */
    LL_Init( taskID++ );

    /* Hal Task */
    Hal_Init( taskID++ );

    /* HCI Task */
    HCI_Init( taskID++ );

    #if defined ( OSAL_CBTIMER_NUM_TASKS )
    /* Callback Timer Tasks */
    osal_CbTimerInit( taskID );
    taskID += OSAL_CBTIMER_NUM_TASKS;
    #endif

    /* L2CAP Task */
    L2CAP_Init( taskID++ );

    /* GAP Task */
    GAP_Init( taskID++ );

    /* GATT Task */
    GATT_Init( taskID++ );

    /* SM Task */
    SM_Init( taskID++ );

    /* Profiles */
    GAPRole_Init( taskID++ );
    GAPBondMgr_Init( taskID++ );

    GATTServApp_Init( taskID++ );

    /* Application */
    Thermometer_Init( taskID++);
    UvSensor_Init( taskID );
    }

    inside 

    void UvSensor_Init( uint8 task_id )
    {
       UvSensorTaskId = task_id;
        
       SI1145_init();
    
       osal_set_event( UvSensorTaskId, EVENT_TASK_READ);  
    }
    uint16 UvSensor_ProcessEvent( uint8 task_id, uint16 events )
    {
       VOID task_id; // OSAL required parameter that isn't used in this function
       
        /*
       * Read event. Read data from UV sensor
       */
       if ( events & EVENT_TASK_READ )
       {
       
         UvLevel = SI1445_readUV();
         
          LedRedBlink(); // only for debug
    
          osal_start_timerEx(UvSensorTaskId,EVENT_TASK_READ, 5000 );
          
         // Clear event and return.
           return ( events ^ EVENT_TASK_READ);
       }
    }

    I've changed program  program according to  your advice :

    "Otherwise, try to call the osal_start_timerEx() for the TASK_READ event in the START_DEVICE_EVT similar to what is done with the PERIODIC_EVT in the simpleBLEPeripheral project and see if that makes a difference. That would prevent the device from entering PM3. "

    void UvSensor_Init( uint8 task_id )
    {
       UvSensorTaskId = task_id;
        
       SI1145_init();
    
       UvLevel = SI1445_readUV();
          
       osal_set_event( UvSensorTaskId, EVENT_TASK_START );
    }
    
    uint16 UvSensor_ProcessEvent( uint8 task_id, uint16 events )
    {
       VOID task_id; 
    
       /*
       * Start event. 
       */
       if ( events & EVENT_TASK_START )
       {  
          osal_start_timerEx(UvSensorTaskId,EVENT_TASK_READ, 5000 );
          
    
         // Clear event and return.
           return ( events ^ EVENT_TASK_START);
       }
    
       /*
       * Read event. Read data from UV sensor
       */
       if ( events & EVENT_TASK_READ )
       {
          // Restart timer
          osal_start_timerEx(UvSensorTaskId,EVENT_TASK_READ, 5000 );
         
          UvLevel = SI1445_readUV();
         
          LedRedBlink(); // only for debug
          
          // Clear event and return.
           return ( events ^ EVENT_TASK_READ);
       }
    
    }

    unfortunately nothing has changed. Device doesn't work in  sleep mode( "POWER_SAVING" enabled)

     

     

  • What specifically do you mean when you say "doesn't work"? Have you looked at the I2C lines and seen no traffic or are you only looking at the LED to see if it toggles? Can you enable advertisements  

    What HW are you using? Does it have a 32kHz crystal?

  • "What specifically do you mean when you say "doesn't work"?" - led is turned on always (when  sleep is turned off  led is blinking),  no any traffic on i2c bus, smartphone can't see  device.

    "What HW are you using? "  - PAN1721 

    "Does it have a 32kHz crystal?" yes, 32.768kHz

  • Hey Vasyl,

    Now I'm out of guesses. My first two steps would be to see if I could run the  code on one of the chip evms like the sensor tag or keyfob to see if it's an issue with the module.

    I would also try to run some stock project like simpleBLEperipheral on the PAN module and enable sleep to see if that has any issues.

    After running those it should give us a good indication of whether it's a hardware issue or something wrong with the code.

    I've seen one other post about the module and the i2c system but I don't know how related it is: http://e2e.ti.com/support/wireless_connectivity/f/538/p/299145/1108330.aspx

    -Matt