本帖最后由 jinglixixi 于 2021-1-31 01:34 编辑
在AT32F407的开发板上较重要的外设要数W25Q128了,其接口的原理图见图1所示。
图1 存储器接口原理图
通过对W25Q128的读写测试,可以为它的应用打下良好地基础,如来构建字库或图库灯,其测试的连接(将短接子切换到存储器一侧)和效果如图2和图3所示。
图2 切换连接后
图3 测试结果
形成测试的效果的主程序为:
- int main(void)
- {
- UART_Print_Init(115200);
- /* To test ext.flash */
- SPIM_test();
- while(1);
- }
辅助测试的功能函数为:
- void SPIM_test(void)
- {
- u16 i=0;
- /* Configures the ext.flash */
- printf("init SPIM.\r\n");
- FLASH_InitExtFlash();
- /* Fill the content to be writed to ext.flash */
- for(i=0;i<SPIM_PAGE_SIZE;i++)
- {
- WriteBuffer[i]=i%256;
- }
- /* Erases an ext.flash page */
- printf("erase one page.\r\n");
- FLASH_ErasePage(SPIM_TEST_ADDR);
- /* Read an ext.flash page */
- memset(ReadBuffer,0,SPIM_PAGE_SIZE);
- ReadPage(SPIM_TEST_ADDR, SPIM_PAGE_SIZE, ReadBuffer);
- /* Check if the desired page are erased */
- for(i=0;i<SPIM_PAGE_SIZE;i++)
- {
- if(ReadBuffer[i]!=0xff)
- {
- printf("operate SPIM fail.\r\n");
- return;
- }
- }
- /* Program an ext.flash page */
- printf("write one page.\r\n");
- i=0;
- while(i<SPIM_PAGE_SIZE)
- {
- FLASH_ProgramWord (SPIM_TEST_ADDR+i,*(u32 *)(WriteBuffer+i));
- i=i+4;
- }
- /* Read an ext.flash page */
- printf("read one page.\r\n");
- memset(ReadBuffer,0,SPIM_PAGE_SIZE);
- ReadPage(SPIM_TEST_ADDR, SPIM_PAGE_SIZE, ReadBuffer);
- /* Check if reading result and writing content are the same */
- printf("compare the WriteBuffer/ReadBuffer.\r\n");
- for(i=0;i<SPIM_PAGE_SIZE;i++)
- {
- if(ReadBuffer[i]!=WriteBuffer[i])
- {
- /* Print the ext.flash testing result */
- printf("test SPIM fail.\r\n");
- return;
- }
- }
- /* Print the ext.flash testing result */
- printf("test SPIM success!\r\n");
- }
基于该功能的读写测试,我们可以探索着拓展出更多新的应用。
|