permanent update to gatt database characteristic

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
SuMa_296631
Level 5
Level 5
50 replies posted 25 replies posted 10 replies posted

Environment: PSOC 6 with PSoC Creator and latest updates on a (virtual) Win 10 64-bit OS.

Background: I am instrumenting some solar-powered spot lights for my garden. I want to measure the voltage on the solar panel and battery as well as turn the light off if necessary. I want to be able to program the PSoC 6 BLE module with the same code for all of the lights and later on connect to each light (which will therefore have the same top level name) and set a characteristic that will be the location in the garden of the light. It is quite possible that the solar panel/battery voltage will fall below the minimum required for the PSoC which will restart when the voltage rises above the minimum.

Problem: How can I write to the GATT database with the variable (i.e. light-specific) name so that the new value is retained across the loss of power restart?

My understanding is that the GATT database is initially set up from the information in the FLASH memory (i.e.what is defined in the BLE component in the PSoC Creator). It is possible to set up a characteristic that lets the client write a new value to it, but that this is only kept in RAM.

I'm wanting to be able to write to a characteristic and have it kept in the FLASH version that is loaded when the PSoC 6 power up.

Is this possible?

If so, what is the magic incantation to make this happen?

Susan

0 Likes
1 Solution
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Susan,

You can store the particular characteristic data that you want to store in the flash using Emulated EEPROM component inside PSoC.

Please go through Emulated EEPROM component code example from the PSoC Creator code examples section of PSoC Creator 4.2 . The project name is "PSoC_EmEEPROM_PSoC601".

Please note that the number of Flash write cycles are limited. So you have to choose wisely when to write the database to the flash. We recommend you to use a voltage detector that will indicate you the power drop. It can be done as follows:

1. Use Low Voltage Detect feature of PSoC which will generate interrupt when the voltage level drops below certain voltage. You can configure this voltage level. Please refer Low Voltage Section in PDL.

2. Once the voltage drop is detected, you can write the present GATT characteristics you want in the Flash and read it on every boot-up.

Thanks

Ganesh

View solution in original post

0 Likes
3 Replies
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Susan,

You can store the particular characteristic data that you want to store in the flash using Emulated EEPROM component inside PSoC.

Please go through Emulated EEPROM component code example from the PSoC Creator code examples section of PSoC Creator 4.2 . The project name is "PSoC_EmEEPROM_PSoC601".

Please note that the number of Flash write cycles are limited. So you have to choose wisely when to write the database to the flash. We recommend you to use a voltage detector that will indicate you the power drop. It can be done as follows:

1. Use Low Voltage Detect feature of PSoC which will generate interrupt when the voltage level drops below certain voltage. You can configure this voltage level. Please refer Low Voltage Section in PDL.

2. Once the voltage drop is detected, you can write the present GATT characteristics you want in the Flash and read it on every boot-up.

Thanks

Ganesh

0 Likes

Hello Ganesh,

That was my 'plan b'.

As for how often the value gets written to the Emulated EEPROM, except for the development process, the number of writes in the normal use context is probably between 1 and 3 - it is really just to write some string that the user determines to distinguish one solar powered light from another.

I take on board your comment about the low battery detection, but the normal use case would be to place the light in the required place in the garden during the day when the solar panel will be providing more than enough power, use an iPhone (or similar) to write the unique location name and then walk away.

I did read somewhere that using BLE and the EEPROM at the same time causes issues as the EEPROM has blocking write functions, stops interrupts and also changes the clock while the write is in progress. I can remember if this relates to the PSoC 6 or not but I guess I'll find out in time!

Susan

0 Likes

I've implemented this now and it works well. I used the emulated EEPROM 'component' and created a small structure that had a 'character count' byte followed by 30 characters and a null character. The stored string will be both counted an null terminated!

The first time (after programming) the EEPROM has nothing in it so I put in dummy text ("No Location Given"). I then read the EEPROM and send the string to the GATT database.

If the user updates the characteristic value,then it is written back to the EEPROM, ready for the next time the MCU powers up (i.e. when the battery is charged up enough after being discharged by the light). As the user can see the battery voltage before they write the new value, it is up to them to check that there is enough power to complete the write cycle (<1Sec of course).

I've not bothered with options such as the wear-levelling in the EEPROM - even on the development MCU, the EEPROM wear (which I've selected as being in FLASH)  is well below the limit in the datasheet.

Susan

0 Likes