This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to write NVM flash?

Hi, I use the nrf24le1 device in my design. I want to stroe data when power is off, so I write data to the NVM flash. But something is wrong in my design, could you help me ? I have two codes, the first code is described as follows: The flash is earsed firstly, and then I write data to flash, the address is set to 0XFB80, then I read the data in flash, the data which is read is correct. After the first code, I program the second code to the device,the second is described as follows: I read the flash directly, and the data which is read is FF. In my opinion, I have writen the data to the NVM flash sucessfully, the data would not miss when power off. In the second code, I don't write the data to flash, I should read out the data which is writen in first code, but the result is failed. what's wrong with my design.

static xdata uint8_t AES_Key[16] = {0xcc,0x77,0x44,0x18,0x87,0x56,0xb3,0x7d,0x99,0x10,0xc7,0xcc,0x13,0x14,0x15,0x16};

uint8_t data1_buf[16]; void main(void) { uint16_t addr; uint8_t i;

mcu_init();

EA = 1; // Global interrupt enable

hal_uart_init(UART_BAUD_38K4);

addr=0xFB80; // set the flash address

while(1)

{

if (!S2) {

//hal_flash_page_erase(33); // In first code

LED=0;

//hal_flash_bytes_write(addr,AES_Key,16); // in first code

hal_flash_bytes_read(addr,&data1_buf, 16); for(i=0;i<16;i++) { hal_uart_putchar(data1_buf[i]); } LED=1; delay_10ms();

}

}

}

Parents
  • @Liu: How did you flash the new program ? There is a chance that the whole chip is erased before you flash the second firmware. This explain why you see 0xFF when you read on the 2nd firmware. If you don't switch firmware, but simply do this:

    • Read the address,
    • If it's 0xFF then write to the address a value, 0x01 for example
    • If it's 0x01 then do something else.

    Then you don't have to switch firmware to test the flash writing.

Reply
  • @Liu: How did you flash the new program ? There is a chance that the whole chip is erased before you flash the second firmware. This explain why you see 0xFF when you read on the 2nd firmware. If you don't switch firmware, but simply do this:

    • Read the address,
    • If it's 0xFF then write to the address a value, 0x01 for example
    • If it's 0x01 then do something else.

    Then you don't have to switch firmware to test the flash writing.

Children
No Data
Related