热度 18
2010-8-16 08:29
2666 次阅读|
0 个评论
// read Manufacturer /device id, return must be 0xef/0x14 is for winbond/W25Q16BV void w25q16_mdid_cmd(void) { U8 data1, data2; w25q16_busy_delay(); IO0CLR = SPI0CS; spi0_send_U8(MDID_INST); spi0_send_U8(0x00); // dummy spi0_send_U8(0x00); // dummy spi0_send_U8(0x00); data1 = spi0_read_U8(); data2 = spi0_read_U8(); IO0SET = SPI0CS; // show read data for debug uart0_putchar(0xff); uart0_putchar(data1); uart0_putchar(data2); uart0_putchar(0xff); } // read Manufacturer/Memory Type/Capacity, return must be 0xef/0x40/0x15 is for winbond/W25Q16BV void w25q16_jeid_cmd(void) { U8 data1, data2, data3; w25q16_busy_delay(); IO0CLR = SPI0CS; spi0_send_U8(JEID_INST); data1 = spi0_read_U8(); data2 = spi0_read_U8(); data3 = spi0_read_U8(); IO0SET = SPI0CS; // show read data for debug uart0_putchar(0xff); uart0_putchar(data1); uart0_putchar(data2); uart0_putchar(data3); uart0_putchar(0xff); } // Write enable void w25q16_wren_cmd(void) { w25q16_busy_delay(); IO0CLR = SPI0CS; spi0_send_U8(WREN_INST); IO0SET = SPI0CS; } // fast read void w25q16_read(U8* buf, U32 buf_len, U32 address) { w25q16_busy_delay(); IO0CLR = SPI0CS; spi0_send_U8(FTRD_INST); spi0_send_U8((U8)(address16)); spi0_send_U8((U8)(address8)); spi0_send_U8((U8)(address)); spi0_send_U8(0x00); // dummy for(U32 i=0; i buf = spi0_read_U8(); } IO0SET = SPI0CS; } // sector erase for 16 page void w25q16_erase_sector(U32 address) { //datasheet say sector erase's typ time is 30ms, max time is 200/400ms watchdog_soft_hard_feed(); w25q16_wren_cmd(); w25q16_busy_delay(); IO0CLR = SPI0CS; spi0_send_U8(STER_INST); spi0_send_U8((U8)(address16)); spi0_send_U8((U8)(address8)); spi0_send_U8((U8)(address)); IO0SET = SPI0CS; } // page program with fix page size, datasheet say its typ time is 0.7ms, max time is 3ms void w25q16_page_program(U8* buf, U32 address) { w25q16_wren_cmd(); w25q16_busy_delay(); IO0CLR = SPI0CS; spi0_send_U8(PGWR_INST); spi0_send_U8((U8)(address16)); spi0_send_U8((U8)(address8)); spi0_send_U8((U8)(address)); spi0_send_data(buf, REAL_PAGE_SIZE); IO0SET = SPI0CS; } Allen 2010.08.15 OVER W25Q16BV driver sample(I) W25Q16BV driver sample(II)