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 osal_snv_read/write strange behavior



Dear all,

I had some trouble in the use of osal_snv_read/write. Since it looks like I cannot write attributes longer than 18 bytes, I had to modify the myProfile_WriteAttrCB functon in order to use the ATT_WritePrepareReq and the ATT_ExecuteWriteReq commands. I wanted to write my attribute (36 byte long) into the NV memory. Here is my code:

 

case MY_ATTRIBUTE_UUID:

        // Validate the value

        if ( (offset + len) > MY_LENGTH )

        {

          status = ATT_ERR_INVALID_VALUE_SIZE;

        }

                         

        // Write the value

        if ( status == SUCCESS )

        {                  

          int8 *pCurValue = (int8 *)pAttr->pValue;          

          

          for (uint8 i = 0; i < len; i++)          

          {

            pCurValue[i + offset] = pValue[i];

          }  

                   

          VOID osal_snv_write(BLE_NVID_MY_PROFILE + offset, len, pValue);

                            

          notify = MY_PROFILE;          

        }  

      break;

 

As I told you before, MY_LENGTH  is 36. 

The strange thing is that if I want to read my 36 bytes in one shot I have some garbage (the first 18 bytes are correct, then I have 6 bytes of garbage and than I have the other bytes I wrote, for example if I wrote 36,35,34,....,1 I get 36,35,...18,X,X,X,X,X,X,17,...7). If I read first the first 18 bytes and then the second 18 byte I get the correct attribute. Here is the code:

CORRECT:

 

if (osal_snv_read( BLE_NVID_MY_PROFILE , 18*sizeof(int8), &myVector) == SUCCESS)

    {

      if (osal_snv_read( BLE_NVID_MY_PROFILE + 18, 18*sizeof(int8), &myVector[18] ) == SUCCESS)

      {

        MyProfile_SetParameter(MY_ATTRIBUTE, MY_LENGTH*sizeof(int8), &myVector);

      }

    }

 

 

WRONG:

 

if (osal_snv_read( BLE_NVID_MY_PROFILE , MY_LENGTH*sizeof(int8), &myVector) == SUCCESS)

 {

    MyProfile_SetParameter(MY_ATTRIBUTE, MY_LENGTH*sizeof(int8), &myVector);

 }

 

Can anyone tell me why?