This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf24le1, memory code space read write failed

hi, i build a test project to test IAP(in system program) function of nrf24le1. the project just did follow things:
1. setup uart;
2. erase page 30
3. write data "0xaa,0x55" to memory code space 0x3c00(page 30);
4. read out data from address 0x3c00, and print it through uart;
some other setting as follows:
1. NUPP=FPCR=0XFF: no page is protecded;
2. when read/write/erase memory code space, pmw is set, otherwise pmw is unset;
3. the project only occupy about 1k memory code space, so 0x03c00 should be able to read/write;
the result is unsatisfied. function involves memory code space will cause the project crash.

pls help. my code as follows:


void Init()

while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M){}	// wait until xosc ready
// 32K clock init
hal_clklf_set_source(HAL_CLKLF_RCOSC32K);
while(!(hal_clklf_ready())){}		 // wait until rc32k is ready
IRCON = 0;
disable_interrupt();

void HexToAscii(unsigned char original,unsigned char *tempdata)

const unsigned char asctable[17] = "0123456789abcdef";
*tempdata = asctable[original>>4];
*(tempdata+1) = asctable[original & 0x0f];


void main(void)

unsigned char i=0;
uint8_t tempprintfdata[2];
uint8_t testdata[3];
//void (*JumpToApp)() = 0x086E;
// clock interupt
Init();
P0DIR &= 0xf7;		// p0.3, uart_txd,output
hal_uart_init(UART_BAUD_57K6);
delay_ms(1000);
delay_ms(1000);
EA=1;	
hal_uart_putstring("FPCR=");
HexToAscii(FPCR,tempprintfdata);
hal_uart_putchar(tempprintfdata[0]);
hal_uart_putchar(tempprintfdata[1]);
hal_uart_putstring("\r\n"); 
hal_uart_putstring("PCON=");
HexToAscii(PCON,tempprintfdata);
hal_uart_putchar(tempprintfdata[0]);
hal_uart_putchar(tempprintfdata[1]);
hal_uart_putstring("\r\n");		
PCON |= PMW;
hal_flash_page_erase(30);
hal_flash_byte_write(0x3c00,0x55);
hal_flash_byte_write(0x3c01,0xaa);
hal_flash_bytes_read(0x3c00,testdata,3);
PCON &= ~PMW;	
hal_uart_putstring("0x3c00=");
HexToAscii(testdata[0],tempprintfdata);
hal_uart_putchar(tempprintfdata[0]);
hal_uart_putchar(tempprintfdata[1]);
HexToAscii(testdata[1],tempprintfdata);
hal_uart_putchar(tempprintfdata[0]);
hal_uart_putchar(tempprintfdata[1]);
HexToAscii(testdata[2],tempprintfdata);
hal_uart_putchar(tempprintfdata[0]);
hal_uart_putchar(tempprintfdata[1]);	
hal_uart_putstring("\r\n");
while(1);

Parents
  • @shaun: I don't see any problem with the code. Could you try to simplify the code and test first with only flash reading, then if it works, try to erase and so on ? At which step would the issue occur ?

    Here is our test code and it worked fine:

    #include <reg24le1.h>
    
    #include "hal_flash.h"
    void main()
    {
    	uint8_t flash_data;
    	P0DIR = 0x00; // configure P0 as output
    	
    	PCON |= 0x10; // setting program memory write mode to access flash
    	flash_data=hal_flash_byte_read(0x3E00); // read data at address 0x3E00
    	if(flash_data == 0xff) // if it is 0xFF => first time running => write init data 0x06
      {
    		flash_data =0x06;	
    		hal_flash_byte_write(0x3E00,flash_data);
    	//	Flash_ByteWrite(0x3E00,&flash_data,1);  
        }
      else // if it is not 0xFF => init data already written, do an increment and update. 
     	{
    		hal_flash_page_erase(31); // erase page 31 (0x3E00 / 512 )
    		flash_data++;
    		hal_flash_byte_write(0x3E00,flash_data);
    	}
    	PCON &= ~0x10; // set the program mermory write modt to access RAM
    	P0=flash_data; // output the data 
    	while (1)
    	{
    		
    
    	}
    }
    
Reply
  • @shaun: I don't see any problem with the code. Could you try to simplify the code and test first with only flash reading, then if it works, try to erase and so on ? At which step would the issue occur ?

    Here is our test code and it worked fine:

    #include <reg24le1.h>
    
    #include "hal_flash.h"
    void main()
    {
    	uint8_t flash_data;
    	P0DIR = 0x00; // configure P0 as output
    	
    	PCON |= 0x10; // setting program memory write mode to access flash
    	flash_data=hal_flash_byte_read(0x3E00); // read data at address 0x3E00
    	if(flash_data == 0xff) // if it is 0xFF => first time running => write init data 0x06
      {
    		flash_data =0x06;	
    		hal_flash_byte_write(0x3E00,flash_data);
    	//	Flash_ByteWrite(0x3E00,&flash_data,1);  
        }
      else // if it is not 0xFF => init data already written, do an increment and update. 
     	{
    		hal_flash_page_erase(31); // erase page 31 (0x3E00 / 512 )
    		flash_data++;
    		hal_flash_byte_write(0x3E00,flash_data);
    	}
    	PCON &= ~0x10; // set the program mermory write modt to access RAM
    	P0=flash_data; // output the data 
    	while (1)
    	{
    		
    
    	}
    }
    
Children
No Data
Related