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.

CC2540 Mini Dev Kit (Accelerometers)

Other Parts Discussed in Thread: CC2540

Hi,

 

   Im new to work with CC2540  , last week i brought  Mini Dev Kit. now Im working with the sample code, In that "Emulated Keyboard" application i want to add 

Accelerometers  profile in tat Emulated keyboard project, finally i added  with the help of "Keyfob" application code, but stil  it didt work i dont knw weather my code was right or wrong so plz any one guide me..! 

 

thanks and regards

 

ashok

  • Let me hijack this post to try to help you, since the info you gave us is not very complete.

    I've also been working with the accelerometers, considering the ATT changes in

    http://e2e.ti.com/support/low_power_rf/f/538/p/134385/487693.aspx#487693

    I can write a 02 in 0x0022 (link loss loud alert). I can write a 1 in 0x0047 (keyfob state) and I can read the 0x002C (battery level) when employing the KeyFob application in the keyfob and the HosTestRelease in the dongle. The keypress notifications are received, the alert is risen up when the dongle is disconnected and the battery level can be read.

     

    What I cannot do is to work with the accelerometers, which description is in:

    0x003b = "x-coordinate"

    0x003f = "y-coordinate"

    0x0043 = "z-coordinate"

    I know their enables are, respectively, in 0x003a, 0x003e and 0x0042. I write a "1" on them (success in BTool) and I also write a 1 in 0x0033 "general accelerometer enable". But when I move the dongle around, no notifications are received in BTool. Has anybody a suggestion of what I can be missing? I'm working with the latest BLE.

    I will be waiting for your answers, thanks!

     

     

  • Ashok,

    could you provide us with more information on what you added to the project and what changes you made?

    I am also in the process on adding the accelerometer to the keyboard application and for me the accelerometer seems to work just fine.

    Kazola,

    I just tried and took the exact same steps you did, writing 01:00 to 0x003a, 0x003e and 0x0042 and "1" to 0x0033 and for me it just works with the 1.1 version of the keyfobdemo. Maybe your accelerometer is defective?

    Best regards,

    Gijs

  • Hi,

        thank you for replying.. I will explain in detail..

       Initially  i work with LEDs ,Buzzer and Accelerometer  bcoz , Im in the beginng level

       my 1st code in CC2540 

     

     

     

    #include <ioCC2540.h>

    #include <stdio.h>

    #include "buzzer.h"

    #include "cma3000d.h"

     

    int main( void )

    {

     int8 x,y,z;

      APCFG=0;

      P1DIR |= 0x43;

      P0DIR |= 0x00;

      accInit();

      while(1){            //       for keep reading the  acc val

      accReadAcc(&x, &y, &z);

     

      if(x > y+(y/3)){

         P1_1=0;           //LED1

        P1_0=1;          //LED2

        delay(20000);   

      }

     if(y > x+(x/3))

      {

             P1_1=1;          //LED1

           P1_0=0;        //LED2

           delay(20000); 

      }

      }

     return 0;

    }

     

    This code is my own code for testing the accelerometer  working,,,  it was successfully worked !

     

    after that only i tried some sample application from Ti,  i tried the "Emulated Keyboard" example for keyfob device and USB dongle example for dongle device

    then it works fine for me, when i pressed the left and right key  it drive the key up and down in PC,

    so after that i thought to implement the Accelerometer same my code in the "Emulation Keyboard"  , but  bty the time i had doubt , was the emulated keyboard demo was implemented using OSAL , so i didt get idea to add the Accelerometer profile to that project , even i tried in my way  i know it was wrong but i changed like...

     

    static void emulatedKeyboard_HandleKeys( uint8 shift, uint8 keys )

    {

    int8 x,y,z;                               ///   i added

      static uint8 prevKey1 = 0;

      static uint8 prevKey2 = 0;

      static uint8 prevKey3 = 0;

      static uint8 prevKey4 = 0;

     

      (void)shift;  // Intentionally unreferenced parameter

     

       accReadAcc(&x, &y, &z);     // i added

    if( (x > y+(y/3) )  &&  (prevKey3 ==0)  ){

        uint8 keyData[3];

        keyData[0] = 0x01;  // pressed

        keyData[1] = KEY_RIGHT_ARROW;

        keyData[2] = 0x00;  // no modifiers

        HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );

        prevKey4 = 0;

        prevKey3 = 1;

       }

     if(   (y > x+(x/3) )  &&  ( prevKey4==0 ) )

      {

        uint8 keyData[3];

        keyData[0] = 0x01;  // pressed

        keyData[1] = KEY_LEFT_ARROW;

        keyData[2] = 0x00;  // no modifiers

        HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );

        prevKey4 = 1;

        prevKey3 = 0;

      }

     


      if ( (keys & HAL_KEY_SW_1) && (prevKey1 == 0) )

      {

        uint8 keyData[3];

        keyData[0] = 0x01;  // pressed

        keyData[1] = KEY_UP_ARROW;

        keyData[2] = 0x00;  // no modifiers

        HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );

        prevKey1 = 1;

      }

      else if ( !(keys & HAL_KEY_SW_1) && (prevKey1 == 1) )

      {

        uint8 keyData[3];

        keyData[0] = 0x00;  // released

        keyData[1] = 0x00;  // 

        keyData[2] = 0x00;  // no modifiers

        HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );

        prevKey1 = 0;

      }

     

      if ( (keys & HAL_KEY_SW_2) && (prevKey2 == 0) )

      {

        uint8 keyData[3];

        keyData[0] = 0x01;  // pressed

        keyData[1] = KEY_DOWN_ARROW;

        keyData[2] = 0x00;  // no modifiers

        HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );

        prevKey2 = 1;

      }

      else if ( !(keys & HAL_KEY_SW_2) && (prevKey2 == 1) )

      {

        uint8 keyData[3];

        keyData[0] = 0x00;  // released

        keyData[1] = 0x00;  // 

        keyData[2] = 0x00;  // no modifiers

        HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );

        prevKey2 = 0;

      }

     

     

     

    The above the code some what works but not in proper order..  after that i seen the KeyFob demo project , in that Accelerometer part i copied and pasted in emulated keyboard project , no errors .. but  that code not works , so now  mind is blank where and how to add the Accelerometr  profile into emulated keyboard application,

    my concern is instead of pressing the left and right button , accelerometer input i want to assign

    can you please help me..  what to do for that ..?  

     

     

  • I think my accel is broken :(

    Thanks for answering.

  • Hi Ashok,

    If I am correct the emulatedKeyboard_HandleKeys() function only gets called when a button event occurs. You should create a separate timer function to poll the accelerometer data. I'll see if I can get my code finished today, if I do I'll share it with you.

    BR,

    Gijs

  • Hi, Gijs

        I will try to make , if you finsd your code plz share me  thanks a lot..!

  • Ashok,

     

    As promised here are the pieces you need.

    - To the constants add:

    #define ACCEL_READ_PERIOD             50

    - To the local functions add:

    static void accelRead( void );

    - At the end of the EmulatedKeyboard_Init function add:

      // Initialize accelerometer
      accInit();
      // Setup timer for accelerometer task
      osal_start_timerEx( emulatedKeyboard_TaskID, KFD_ACCEL_READ_EVT, ACCEL_READ_PERIOD );

    - At the end of EmulatedKeyboard_ProcessEvent function add:

      if ( events & KFD_ACCEL_READ_EVT )
      {
        // Restart timer
        if ( ACCEL_READ_PERIOD )
        {
          osal_start_timerEx( emulatedKeyboard_TaskID, KFD_ACCEL_READ_EVT, ACCEL_READ_PERIOD );
        }
        // Read accelerometer data
        accelRead();
        return (events ^ KFD_ACCEL_READ_EVT);
      }

    - Then finally add the function:

    /*********************************************************************
     * @fn      accelRead
     *
     * @brief   Called by the application to read accelerometer data
     *          and put data in HIDkeyboard profile
     *
     * @param   none
     *
     * @return  none
     */
    static void accelRead( void )
    {
      static uint8 prevKey3 = 0;

      static int8 ACCEL_UP_HIGH, ACCEL_UP_LOW, ACCEL_DOWN_HIGH, ACCEL_DOWN_LOW;
      int8 new_x, new_y, new_z;

      // Read data for each axis of the accelerometer

      accReadAcc(&new_x, &new_y, &new_z); 
      ACCEL_UP_HIGH = 0x60;
      ACCEL_UP_LOW = 0x14;
      ACCEL_DOWN_LOW = 0x9F;
      ACCEL_DOWN_HIGH = 0xEB;
     
     
      if( (new_x < ACCEL_DOWN_HIGH) && (new_x > ACCEL_DOWN_LOW) ) 
      {
        //tilt up
        if( prevKey3 == 0 )
        {
          uint8 keyData[1];
          keyData[0] = 0x01;  // pressed
          keyData[1] = KEY_UP_ARROW;
          keyData[2] = 0x00;  // no modifiers
          HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );
          prevKey3 = 1;
        }
      }
      else if( (new_x < ACCEL_UP_HIGH) && (new_x > ACCEL_UP_LOW) )
      {
        //tilt down
        if( prevKey3 == 0 )
        {
          uint8 keyData[3];
          keyData[0] = 0x01;  // pressed
          keyData[1] = KEY_DOWN_ARROW;
          keyData[2] = 0x00;  // no modifiers
          HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );
          prevKey3 = 1;
        }
      }
      else if( (new_y < ACCEL_DOWN_HIGH) && (new_y > ACCEL_DOWN_LOW) )
      {
        //tilt left
        if( prevKey3 == 0 )
        {
          uint8 keyData[1];
          keyData[0] = 0x01;  // pressed
          keyData[1] = KEY_LEFT_ARROW;
          keyData[2] = 0x00;  // no modifiers
          HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );
          prevKey3 = 1;
        }
      }
      else if( (new_y < ACCEL_UP_HIGH) && (new_y > ACCEL_UP_LOW) )
      {
        //tilt right
        if( prevKey3 == 0 )
        {
          uint8 keyData[1];
          keyData[0] = 0x01;  // pressed
          keyData[1] = KEY_RIGHT_ARROW;
          keyData[2] = 0x00;  // no modifiers
          HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );
          prevKey3 = 1;
        }
      }
      else
      {
        if( prevKey3 == 1)
        {
          uint8 keyData[3];
          keyData[0] = 0x00;  // released
          keyData[1] = 0x00;  //
          keyData[2] = 0x00;  // no modifiers
          HidKeyboard_SetParameter( HIDKEYBOARD_DATA, 3, keyData );
          prevKey3 = 0;
        }
      }

    }

     

    I hope this helps you.

    Best regards,

    Gijs

  • Hi Gijs....

       Im so happy with your code..! it working fine  a lot lot lot of thanks to you... :) :)

      have a nice day......

     

    Best regards..

    Ashok 

  • Great work :)

    Do you both think we could start making some kind of wiki in order to post all these functional codes we are getting every day? Perhaps this could be a way to speed up and discard some common questions that are being asked every month, over and over :)

    What is you opinion?

  • Come on, you have the start page here :) You can add an entry like "Useful CC2540 codes that everybody askes once" or something like this and start your own "accelerometer" section.

    http://processors.wiki.ti.com/index.php/Category:BluetoothLE

    Please note Christmas is coming and it is time to share :)

  • good morning

    Im using CC2540 in the remot ,and now i am try to programme the gyroscope for detetection of  the mouvement but my problem that the dongle   missed to processec all data(x,y) so when the cursus move in the screen of pc  there is the palye ,,can you tel me where is the problem please

  • Yes, on line 126.

    Good luck.

    PS: we need better description of the problem.

  • Goog morning

    thank  you for your answer

    i want to change the interval of connection when the connection is established ,so when i send the simple key i want that the ineterval of connection is all  "30ms(max,min)(emmision of packet all 30ms),in order to reduce the consommation, but when i active and i  use the gyroscope ,i want to change these interval to 10 ms in order  to supprime the playe,is it possible to change the parametter when the connection establised and without stopped it .

    thank you