Skip to main content
Visitor II
May 28, 2021
Solved

Hi,Working with stm8l15 with lora.When storing more than one 32 bit variable in eeprom memory continuously, downlink is not receiving and it gets queueing. What will be the reason.

  • May 28, 2021
  • 2 replies
  • 1422 views

How to store more than one 32 bit variable in eeprom memory in while loop and also to receive downlink?

Here,I have attached the code too.

    This topic has been closed for replies.
    Best answer by Cristian Gyorgy

    I could not open the code you posted, but take in count that a programming takes 6 ms if not writing on already erased location.

    If you need shorter write times: prepare the locations in advance by erasing them and write your data in blocks (64 bytes). A block write is just as fast as a byte/word write.

    2 replies

    Visitor II
    May 28, 2021

    I could not open the code you posted, but take in count that a programming takes 6 ms if not writing on already erased location.

    If you need shorter write times: prepare the locations in advance by erasing them and write your data in blocks (64 bytes). A block write is just as fast as a byte/word write.

    Gswam.1Author
    Visitor II
    May 28, 2021

    Hi Cristian Gyorgy,

    This is the main code

    int main( void )

    {

      LoRaMacPrimitives_t LoRaMacPrimitives;

      LoRaMacCallback_t LoRaMacCallbacks;

      MibRequestConfirm_t mibReq;

      BoardInitMcu( );

      BoardInitPeriph( );

    Flash_setup();

      DeviceState = DEVICE_STATE_INIT;

      printf("ClassA app start\r\n");

    count = FLASH_ReadByte(0x1002);

     count <<= 8;

     count |= FLASH_ReadByte(0x1003);

     count <<= 8;

     count |= FLASH_ReadByte(0x1004);

     count <<= 8;

     count |= FLASH_ReadByte(0x1005);

    count1 = FLASH_ReadByte(0x1006);

     count1 <<= 8;

     count1 |= FLASH_ReadByte(0x1007);

     count1 <<= 8;

     count1 |= FLASH_ReadByte(0x1008);

     count1 <<= 8;

     count1 |= FLASH_ReadByte(0x1009);

    Count_Read = count;

    Count1_Read = count1;

    printf("Count_Read:%lu\n",Count_Read);

    printf("Count1_Read:%lu\n",Count1_Read);

      while( 1 )

      {

    if(joined_finish==1)

     { 

      count++;

    count1++;

     

    FLASH_Unlock(FLASH_MemType_Data);

        FLASH_ProgramByte(0x1002, count>>24);

        FLASH_ProgramByte(0x1003, count>>16);

       FLASH_ProgramByte(0x1004, count>>8);

       FLASH_ProgramByte(0x1005, count);

    FLASH_ProgramByte(0x1006, count1>>24);

        FLASH_ProgramByte(0x1007, count1>>16);

       FLASH_ProgramByte(0x1008, count1>>8);

       FLASH_ProgramByte(0x1009, count1);

       FLASH_Lock(FLASH_MemType_Data);

     } 

    // here it comes switch case statement

       }

    Visitor II
    May 28, 2021
    FLASH_ProgramByte(0x1002, count>>24);
    FLASH_ProgramByte(0x1003, count>>16);
    FLASH_ProgramByte(0x1004, count>>8);
    FLASH_ProgramByte(0x1005, count);
    FLASH_ProgramByte(0x1006, count1>>24);
    FLASH_ProgramByte(0x1007, count1>>16);
    FLASH_ProgramByte(0x1008, count1>>8);
    FLASH_ProgramByte(0x1009, count1);

    Every line in the code above will take 6 ms: 8x6=48 ms programming time.

    Instead you could do only 2 writes, by writing only 2 4-byte words (at a word aligned address!): 2x6=12 ms,

    Or, read first the block where you want to do the write into SRAM, fill in the 8 bytes and than write the 64/128 bytes block back in only 6ms.

    I don't know your compiler, what function has defined for the word/block programming, but for sure it has one.

    Gswam.1Author
    Visitor II
    May 28, 2021

    Ya. Thank you. It is worked by using word. Downlink is also working and storing also happening.