First, the contents of the experiment:
Send a single character through the serial port to nrf51822,nrf51822 after receiving the character, write it to the last page of Flash, then read it out and print out the data through the serial port.
Second, nRF51822 chip internal flash Knowledge:
The EN-NRF51D board uses the NRF51822 chip as the NRF51822-QFAA, as shown in a total of 256kbflash,256 pages with a page size of 1024 bytes.
NRF51822 internal Flash Writing process is as follows:
Third, Code Analysis:
Main
1 intMainvoid)2 {3 ...4 5 initialization of serial port6 7printf"Flashwrite example\r\n");8Patold =0;9Pg_size = nrf_ficr->codepagesize;TenPg_num = Nrf_ficr->codesize-1;//Use last page in Flash One A while(true) - { - //Start Address:addr = (uint32_t *) (pg_size * pg_num);//calculate address and erase a page//Erase page:17 flash_page_erase (addr) ; -i =0; + - Do + { Aprintf"Enter Char to write to flash\r\n"); at - //Read Char from the UART, and write it to Flash:do26 {err_code = App_uart_get (&PATWR); 28}29 while (Err_code = = Nrf_error_not_found);//Get 1byte data from the serial port - if (patold! = PATWR)//writes 1byte to Flash32 {patold = patwr;34 Flash_word_write (++addr, (uint32_t) PATWR); i + = 4;36 printf ("'%c ' is write to flash\r\ n ", PATWR); - //Read pattern from flash and send it back: thePATRD = (uint8_t) *addr; +printf"'%c ' was read from flash\r\n", PATRD); A } the while(I <pg_size); + } -}
@nRF51822 Basic Experiment Series:
[nRF51822] 7, basic experimental Code Analysis Daquan (top ten)
[nRF51822] 8, basic experimental code Analysis Daquan · Experimental 11-ppi
[nRF51822] 9, basic experimental code Analysis Daquan · Experimental 12-ADC
[nRF51822] 10, basic experimental code Analysis Daquan · Experimental 15-RTC
@beautifulzzzz -The Internet of Things & ubiquitous computing practitioners
e-mail: [Email protected]
I-blog:blog.beautifulzzzz.com
[nRF51822] 11, basic experimental Code Analysis Daquan · Lab 16-Internal Flash read/write