//要写入到W25Q64的字符串数组
const u8 TEXT_Buffer[]={"WarShipSTM32 SPI TEST"}; //定义字符串数组,算上结束符\0,总共22个字节
#define SIZE sizeof(TEXT_Buffer)
int main(void)
{
u8 key;
u16 i=0;
u8 datatemp[SIZE];
u32 FLASH_SIZE;
delay_init(); //延时函数初始化
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(9600); //串口初始化为9600
LED_Init(); //LED端口初始化
LCD_Init();
KEY_Init();
SPI_Flash_Init(); //SPI FLASH 初始化
POINT_COLOR=RED;//设置字体为红色
LCD_ShowString(40,50,200,16,16,"WarShip STM32");
LCD_ShowString(40,70,200,16,16,"SPI TEST");
LCD_ShowString(40,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(40,110,200,16,16,"2012/9/9");
LCD_ShowString(40,130,200,16,16,"WKUP:Write KEY1:Read"); //显示提示信息
while(SPI_Flash_ReadID()!=W25Q64) //检测不到W25Q64
{
LCD_ShowString(40,150,200,16,16,"25Q64 Check Failed!");
delay_ms(500);
LCD_ShowString(40,150,200,16,16,"Please Check! ");
delay_ms(500);
LED0=!LED0;//DS0闪烁
}
LCD_ShowString(40,150,200,16,16,"25Q64 Ready!"); //检测到25Q64,显示
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(40,170,200,16,16,"Start Write W25Q64....");
SPI_Flash_Write((u8*)TEXT_Buffer,FLASH_SIZE-100,SIZE); //从倒数第100个地址处开始,写入SIZE长度的数据
LCD_ShowString(40,170,200,16,16,"W25Q64 Write Finished!"); //提示传送完成
}
if(key==KEY_DOWN)//KEY_DOWN按下,读取字符串并显示
{
LCD_ShowString(40,170,200,16,16,"Start Read W25Q64.... "); //显示"Start Read W25Q64.... "
SPI_Flash_Read(datatemp,FLASH_SIZE-100,SIZE); //从倒数第100个地址处开始,读出SIZE个字节
LCD_ShowString(40,170,200,16,16,"The Data Readed Is: "); //提示传送完成
LCD_ShowString(40,190,200,16,16,datatemp); //显示读到的字符串
}
i++;
delay_ms(10);
if(i==20)
{
LED0=!LED0;//提示系统正在运行
i=0;
}
}
}