TA的每日心情 | 开心 2024-10-25 14:50 |
---|
签到天数: 1071 天 连续签到: 1 天 [LV.10]以坛为家III
|
SPI FLASH 读写测试,向扇区0写入255个字节,然后重读出来,通过串口显示出来。
一、硬件电路
二、程序
2.1、SPI FLASH初始化
- void W25Q32_Init(void)
- {
- //Init_SPI;
- SPI1_Init();
- }
复制代码
2.2、SPI FLASH 读写测试
- void W25Q32_Test(void)
- {
- uint8_t i;
- uint8_t deviceID; //设备ID
- uint8_t returnResult; //返回结果
-
- deviceID = flash_read_deviceid(); //读设备ID
- printf("W25Q32 test: read device ID is 0x%x\n", deviceID);
-
- printf("W25Q32 test: erase flash sector 0 \n");
- returnResult = flash_sector_erase(0); //擦除扇区0
-
- printf("W25Q32 test: write data \n");
-
- for(i=0;i<255;i++)
- {
- WriteBuffer[i]=i;
- printf(" %x", WriteBuffer[i]);
- if((i+1)%20==0)
- {
- printf("\n");
- }
- }
-
- printf("\r\n");
-
- returnResult = flash_write_sector(0, WriteBuffer, 255); //写255个字节数据
-
- printf("W25Q32 test: reda data \n");
- returnResult = flash_read_data(0, ReadBuffer, 255); //读255个字节数据
-
- for(i=0;i<255;i++)
- {
- printf(" %x", ReadBuffer[i]);
- if((i+1)%20==0)
- {
- printf("\n");
- }
- }
- printf("\r\n");
- }
复制代码
2.4、主程序
- void main(void)
- {
- uint8_t i = 0;
- uint8_t j=0;
- uint32_t cnt=0;
- uint16_t adc_val=0;
- //char adc_buf[10];
- float adc_val1=0;
- uint16_t adc_val2=0;
-
- uint8_t u8IRDATxCnt = 0;
-
- volatile uint8_t w25q32_id = 0;
- volatile unsigned char dummy;
- unsigned short uiCount;
-
- Sys_Init();
- EnableInterrupts;
- printf("\n-- S08-LITE FAT BEGINS --\n");
- printf("\n");
-
- MTIM1_Init();
- W25Q32_Init();
- W25Q32_Test();
-
- RTC_Init();
-
- printf("\n-- S08-LITE FAT ENDS --\n");
- //Initialize MTIM0, 625Hz interrupt interval, used for toggle LED
- MTIM0_Init();
- MTIM0_Start();
-
- while (1);
-
- }
复制代码
三、程序执行结果
|
|