stm32 SPI实验
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "led.h"
#include "beep.h"
#include "key.h"
#include "exti.h"
#include "wdg.h"
#include "timer.h"
#include "tpad.h"
#include "oled.h"
#include "lcd.h"
#include "usmart.h"
#include "rtc.h"
#include "wkup.h"
#include "adc.h"
#include "dac.h"
#include "dma.h"
#include "24cxx.h"
#include "flash.h"
//要写入到W25Q64的字符串数组
const u8 TEXT_Buffer[]={"WarShipSTM32 SPI TEST"}; #define SIZE sizeof(TEXT_Buffer)
int main(void)
{
u8 key;
u16 i=0;
u8 datatemp[SIZE];
u32 FLASH_SIZE;
Stm32_Clock_Init(9); //系统时钟设置
uart_init(72,9600); //串口初始化为9600
delay_init(72); //延时初始化
LED_Init(); //初始化与LED连接的硬件接口
LCD_Init(); //初始化LCD
usmart_dev.init(72); //初始化USMART
KEY_Init(); //按键初始化
SPI_Flash_Init(); //SPI FLASH 初始化
POINT_COLOR=RED;//设置字体为红色
LCD_ShowString(60,50,200,16,16,"WarShip STM32");
LCD_ShowString(60,70,200,16,16,"SPI TEST");
LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(60,110,200,16,16,"2012/9/9");
LCD_ShowString(60,130,200,16,16,"WK_UP:Write KEY1:Read"); //显示提示信息
while(SPI_Flash_ReadID()!=W25Q64)
//检测不到W25Q64
{
LCD_ShowString(60,150,200,16,16,"25Q64 Check Failed!");
delay_ms(500);
LCD_ShowString(60,150,200,16,16,"Please Check! ");
delay_ms(500);
LED0=!LED0;//DS0闪烁
}
LCD_ShowString(60,150,200,16,16,"25Q64 Ready!");
FLASH_SIZE=8*1024*1024; //FLASH 大小为8M字节
POINT_COLOR=BLUE; //设置字体为蓝色
while(1)
{
key=KEY_Scan(0);
if(key==KEY_UP)//KEY_UP按下,写入W25Q64
{
LCD_Fill(0,170,239,319,WHITE);//清除半屏
LCD_ShowString(60,170,200,16,16,"Start Write W25Q64....");
SPI_Flash_Write((u8*)TEXT_Buffer,FLASH_SIZE-100,SIZE);
//从倒数第100个地址处开始,写入SIZE长度的数据
LCD_ShowString(60,170,200,16,16,"W25Q64 Write Finished!"); //提示传送完成
}
if(key==KEY_DOWN)//KEY_DOWN按下,读取字符串并显示
{
LCD_ShowString(60,170,200,16,16,"Start Read W25Q64.... ");
SPI_Flash_Read(datatemp,FLASH_SIZE-100,SIZE);
//从倒数第100个地址处开始,读出SIZE个字节
LCD_ShowString(60,170,200,16,16,"The Data Readed Is: "); //提示传送完成
LCD_ShowString(60,190,200,16,16,datatemp);
//显示读到的字符串
}
i++;
delay_ms(10);
if(i==20)
{
LED0=!LED0;//提示系统正在运行
i=0;
}
}
}