In the previous section, we learned how to read NandFlash page by page. Now let's implement NandFlash page by page. First, let's look at the timing diagram of the NandFlash chip K9F2G08U0A.
According to the signal information of the I/O pin corner, we know that the steps required to implement the NandFlash write operation are as follows:
Finally, implement the function of writing by page:
int NF_WritePage(unsigned long addr, unsigned char* buff)
{
int ret;
int i;
//Select the flash chip
select_chip();
// Clear RnB
clear_RnB();
//Send command 0x80
send_cmd(0x80);
//Send column address
send_addr(0x00);
send_addr(0x00);
//Send row address
send_addr(addr&0xff);
send_addr((addr>>8)&0xff);
send_addr((addr>>16)&0xff);
//Write data
for(i=0;i<2048;i++)
{
NFDATA = buff[i];
}
//Send command 0x10
send_cmd(0x10);
//Wait for RnB
wait_RnB();
//Send command 0x70
send_cmd(0x70);
//Read and write results
ret = NFDATA;
//Uncheck the flash chip
deselect_chip();
return ret;
}
Compile and make. If there is no error, you cannot burn it to the development board yet, because no matter it is norflash or NandFlash, it must be erased before writing. The next step is to implement the erase function:
void NF_Erase(unsigned long addr)
This function has one parameter, which is the page address.
Next, let’s look at the erase information of NandFlash chip K9F2G08U0A:
Please note that when erasing, the data is not erased page by page, but the entire block where the page is located is erased.
According to the above erase timing diagram, the implementation steps of the erase function are:
void NF_Erase(unsigned long addr)
{
int ret;
//Select the flash chip
select_chip();
// Clear RnB
clear_RnB();
//Send command 0x60
send_cmd(0x60);
//Send row address
send_addr(addr&0xff);
send_addr((addr>>8)&0xff);
send_addr((addr>>16)&0xff);
//Send command D0
send_cmd(0xD0);
//Wait for RnB
wait_RnB();
//Send command 0x70
send_cmd(0x70);
//Read the erase result
ret = NFDATA;
//Uncheck the flash chip
deselect_chip();
return ret;
}
Finally, add the test code in main.c:
In the test code above, a page-sized char buffer is first defined. Then a block-sized space is formatted. Then 123 is written to NandFlash, and then the value just written is read out through the NF_PageRead function. Finally, the light is turned on to determine whether the number just written is correct. This verifies whether the write operation to NandFlash is successful: Success means that the operation code of NandFlash is not added, and it is burned to the development board, and the light is on. After adding the above code and burning it to the development board, the light is not on.
Previous article:9. NandFlash driver_read operation 2440
Next article:8. NandFlash principle analysis
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- 22 "Wanli" Raspberry Pi car - mobile phone remote control motor rotation
- [Raspberry Pi 4B Review] Install Libreelec system on Raspberry Pi 4 and install plug-ins to watch IPTV live broadcast
- Industrial Sensor Selection Method
- usb device management
- EEWORLD University Hall----The working principle of high voltage isolation technology
- Today's new product sharing: Design of personalized car LED driver; single-cell lithium battery 3.7V mono audio amplifier IC solution
- Unicleo First Experience
- TI blog post: RS-485 transceivers
- Three Bluetooth architecture implementation solutions (Bluetooth protocol stack solutions)
- "Fully" utilize FPGA resources to realize data reading of DALSA line scan camera