10.NandFlash driver_write operation

Publisher:yunhuiLatest update time:2024-11-04 Source: cnblogsKeywords:NandFlash Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Keywords:NandFlash Reference address:10.NandFlash driver_write operation

Previous article:9. NandFlash driver_read operation 2440
Next article:8. NandFlash principle analysis

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号