[活动专区] 【AT-START-L021测评】+W25Q16读写及测试

[复制链接]
 楼主| jinglixixi 发表于 2024-11-28 17:32 | 显示全部楼层 |阅读模式
AT-START-L021开发板为了便于用户扩展存储空间,在开发板上特意配备了一个供外挂存储器件的接口J7,其提供的引脚资源如图1所示。
48440674837b574f30.png
1 外挂接口


为了对W25Q系列的存储器件进行测试,便选取了一个W25Q16的存储模块来进行连接,其引脚连接关系为:
CS ---PB12
CLK---PB13
DO ---PB14
DI ---PB15
TX1---PA9

40462674837d2052a7.png
2 实物连接


相应的测试主程序为:
  1. int main(void)
  2. {
  3.   __IO uint32_t index = 0;
  4.   __IO uint32_t flash_id_index = 0;
  5.   system_clock_config();
  6.   at32_board_init();
  7.   tx_data_fill();
  8.   uart_print_init(115200);
  9.   spiflash_init();
  10.   flash_id_index = spiflash_read_id();
  11.   if((flash_id_index != W25Q128)&&(flash_id_index != W25Q80)&&(flash_id_index != W25Q16)&&(flash_id_index != W25Q32)&&(flash_id_index != W25Q64))
  12.   {
  13.     printf("flash id check error!\r\n");
  14.     for(index = 0; index < 50; index++)
  15.     {
  16.       at32_led_toggle(LED2);
  17.       at32_led_toggle(LED3);
  18.       delay_ms(200);
  19.     }
  20.     return 1;
  21.   }
  22.   else
  23.   {
  24.     printf("flash id check success! id: %x\r\n", flash_id_index);
  25.   }
  26.   /* erase sector */
  27.   spiflash_sector_erase(FLASH_TEST_ADDR / SPIF_SECTOR_SIZE);
  28.   /* write data */
  29.   spiflash_write(tx_buffer, FLASH_TEST_ADDR, BUF_SIZE);
  30.   /* read data */
  31.   spiflash_read(rx_buffer, FLASH_TEST_ADDR, BUF_SIZE);
  32.   /* printf read data */
  33.   printf("Read Data: ");
  34.   for(index = 0; index < BUF_SIZE; index++)
  35.   {
  36.     printf("%x ", rx_buffer[index]);
  37.   }
  38.   /* test result:the data check */
  39.   transfer_status = buffer_compare(rx_buffer, tx_buffer, BUF_SIZE);
  40.   /* test result indicate:if SUCCESS ,led2 lights */
  41.   if(transfer_status == SUCCESS)
  42.   {
  43.     printf("\r\nflash data read write success!\r\n");
  44.     at32_led_on(LED2);
  45.   }
  46.   else
  47.   {
  48.     printf("\r\nflash data read write ERROR!\r\n");
  49.     at32_led_off(LED2);
  50.   }
  51.   while(1)
  52.   {
  53.   }
  54. }

经程序的编译与下载,其测试结果如图3所示,说明测试成功。
由测试程序及结果可以看出,其处理过程为:
首先进行spiflash的初始化,随后是读取芯片的ID并显示,再对测试扇区进行擦除。在完成扇区擦除后,先是写入256个字节的数据,再将其读出以供验证,并以LED2和串口给出判别结果,即LED2亮表示成功;LED2灭表示设备。
216116748387848d7a.png
3 测试结果


但说好的256个数据咋输出了怎么多呢?
通过对数据量的计算可知:
256+256=512+86=598
原来编写程序这位老兄错把256写成 0x256,正好0x256=598,通过查看相应的定义也确实是这样,即:#define BUF_SIZE   0x256

进行修改后,其测试结果如图4所示,这才是常规的预期结果。
6603467483895197bc.png
4 测试效果




您需要登录后才可以回帖 登录 | 注册

本版积分规则

518

主题

2933

帖子

39

粉丝
快速回复 在线客服 返回列表 返回顶部