3 Replies Latest reply on Aug 16, 2017 10:02 AM by risc_1592346

    Saving/Recalling Device Address

      I set the device address in the GUI, setting the top three bytes as company ID and the bottom three come from the die location.




      When I use CyBle_GetDeviceAddress I get a completely different six bytes, why?




      I try to read the address from sflash using this but it reads all zeros:


              sflashPtr = (uint32_t *)USER_SFLASH_BASE_ADDRESS; /* User SFlash read is direct memory read using pointers */


              readData[0] = *sflashPtr++;
              readData[1] = *sflashPtr;


              macValue = readData[0];
              macValue |= (readData[1] << 32);




      Ideas why?




      Do BLE devices have MAC addresses?  Is it the same thing as a "device address"?  If not then what is the difference between a MAC address and a device address?







        • 1. Re: Saving/Recalling Device Address

          Cyble_GetDeviceAddress()  gives  the BDAddress of the device, which is configured in the BLE  component. This could be either company assigned or silicon generated. You need to pass the right parameter to this function (0 for public and 1 for random address). 


          For the silicon generated BDaddress, you are not reading the right SFLASH location.  Post#3 in the following thread shows how to read the BDaddress from SFLASH.



          • 2. Re: Saving/Recalling Device Address

            Thank you for the help.  I am still struggling to understand this.  There is a silicon generated address, as set in the GUI.  I can read this with Cyble_GetDeviceAddress().  I now pass a type of 0, thank you.


            Looking at the code in the other post:


            // read the value from the registers
                    cyBle_deviceAddress.bdAddr[0] = CYBLE_SFLASH_DIE_X_REG;
                    cyBle_deviceAddress.bdAddr[1] = CYBLE_SFLASH_DIE_Y_REG;
                    // cyBle_deviceAddress.bdAddr[2] = CYBLE_SFLASH_DIE_WAFER_REG;


                    // convert the values to ascii and store in the device name field.
                    DeviceName[7] = ((cyBle_deviceAddress.bdAddr[1] & 0xF0) >> 4) + 48 ;
                    DeviceName[8] = (cyBle_deviceAddress.bdAddr[1] & 0x0F) + 48 ;
                    DeviceName[9] = ((cyBle_deviceAddress.bdAddr[0] & 0xF0) >> 4) + 48 ;
                    DeviceName[10] = (cyBle_deviceAddress.bdAddr[0] & 0x0F) + 48 ;




            I tried this code, when I get to the first line:


            cyBle_deviceAddress.bdAddr[0] = CYBLE_SFLASH_DIE_X_REG;


            cyBle_deviceAddress.bdAddr is already loaded with the six byte address, why are we writing a constant to it? (CYBLE_SFLASH_DIE_X_REG)




            It looks like this code only deals with two bytes of the address, correct?




            Our application requires that the device address be written during production. (The point of all this) Here is the function I use to do this, writing the address to row 0 of sflash:


            uint64 setDeviceAddress(uint64 address)
                uint32 dataIndex;
                uint32 fdata[USER_SFLASH_ROW_SIZE];
                uint32_t *sflashPtr, interruptStatus;
                volatile uint64_t readData[2];
                volatile uint64 retValue = 0;
                retValue = address;
               /// CyBle_Stop();
                /* Disable global interrupts */
                interruptStatus = CyEnterCriticalSection();
                fdata[0] = (uint32)(address & 0x00000000FFFFFFFF);
                fdata[1] = (uint32)((address & 0xFFFFFFFF00000000)>>32);
                        fdata[dataIndex] = 0;


                WriteUserSFlashRow(0, &fdata[0]);
                sflashPtr = (uint32_t *)USER_SFLASH_BASE_ADDRESS; /* User SFlash read is direct memory read using pointers */


                        readData[0] = *sflashPtr++;
                        readData[1] = *sflashPtr;


                        retValue = readData[0];
                        retValue |= (readData[1] << 32);


              ///  InitializeSystem();






            It is assumed, since this is the location of the stored address, that the new address will become the "active" address.


            Is this the correct way to handle this?









            • 3. Re: Saving/Recalling Device Address

              I am having good luck now with the following:


              Write address using the sflash write code above.  I start and stop BLE to have it take effect.


              I can read the address back properly using CyBle_GetDeviceAddress.




              Thanks again.