找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1766|回复: 0
打印 上一主题 下一主题
收起左侧

STM32-SST25VF016B-SPI-mini 程序

[复制链接]
跳转到指定楼层
楼主
转载STM32-SST25VF016B-SPI-mini 程序,需要的下载

单片机源程序如下:
  1. /****************************************************************************
  2. * Copyright (C), 2011 奋斗嵌入式工作室
  3. *
  4. * 本例程在 奋斗版STM32开发板V2,2.1,V3,MINI上调试通过           
  5. *
  6. * 文件名: main.c
  7. * 内容简述:
  8. *       演示将一段字符串写入SST25VF016B的1页中,然后读出并通过USART1传送出去,同时LED1亮。
  9.         字符串:SPI SST25VF016B Example: This is SPI DEMO, 终端上出现这一行字,说明SST25VF016B的读写正常
  10. *
  11. 定义:       
  12.         TXD1----- PA9-US1-TX
  13.         RXD1----- PA10-US1-RX
  14.         速率:115200,n,8,1
  15. * 文件历史:
  16. * 版本号  日期       作者    说明
  17. * v0.2    2011-7-22 sun68  创建该文件
  18. *
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f10x.h"          
  22. #include "stm32f10x_usart.h"  

  23. extern void SPI_Flash_Init(void);
  24. extern unsigned char SST25_buffer[];

  25. /* Private define ------------------------------------------------------------*/
  26. #define TxBufferSize1   (countof(TxBuffer1) - 1)
  27. #define RxBufferSize1   (countof(TxBuffer1) - 1)

  28. /* Private macro -------------------------------------------------------------*/
  29. #define countof(a)   (sizeof(a) / sizeof(*(a)))

  30. /* Private variables ---------------------------------------------------------*/

  31. uint8_t TxBuffer1[] = "SPI SST25VF016B Example: This is SPI DEMO, 终端上出现这一行字,说明SST25VF016B的读写正常";

  32. /* Private function prototypes -----------------------------------------------*/
  33. void RCC_Configuration(void);
  34. void GPIO_Configuration(void);
  35. void NVIC_Configuration(void);

  36. void Delay(__IO uint32_t nCount);
  37. void USART_OUT(USART_TypeDef* USARTx, uint8_t *Data,uint16_t Len);
  38. void Usart1_Init(void);

  39. GPIO_InitTypeDef GPIO_InitStructure;

  40. int16_t USART_FLAG;

  41. extern void SST25_W_BLOCK(uint32_t addr, u8 *readbuff, uint16_t BlockSize);
  42. extern void SST25_R_BLOCK(uint32_t addr, u8 *readbuff, uint16_t BlockSize);
  43. /* Private functions ---------------------------------------------------------*/
  44. /****************************************************************************
  45. * 名    称:int main(void)
  46. * 功    能:主函数
  47. ****************************************************************************/
  48. int main(void)
  49. {
  50.    uint8_t a=0;
  51.    uint16_t i=0;                          
  52.    RCC_Configuration();                                                           //设置系统时钟  
  53.    
  54.    GPIO_Configuration();                                            //IO口设置                 
  55.    Usart1_Init();                               //串口1初始化
  56.    SPI_Flash_Init();                                                    //SPI1 SST25VF016B初始化

  57.    /* 将测试用的数据复制到读写缓存区里 */
  58.    for(i=0; i<TxBufferSize1;i++) SST25_buffer[i]=TxBuffer1[i];  
  59.    SST25_W_BLOCK(0, SST25_buffer,4096);                //将册数数据写入到SST25VF016B的0页里
  60.    Delay(0xffff);
  61.    SST25_R_BLOCK(0, SST25_buffer,4096);                //从SST25VF016B的0页里读出数据
  62.    a=0;
  63.    for(i=0; i<TxBufferSize1;i++){
  64.            if(SST25_buffer[i]==TxBuffer1[i]) a=1;            //读出的数据和测试数据进行比较, 以判别是否读写正常
  65.          else {a=0; i=TxBufferSize1;}
  66.    }
  67.    if(a==1) {
  68.            GPIO_SetBits(GPIOB, GPIO_Pin_5);                     //读写正确LED1 亮
  69.            USART_OUT(USART1,&SST25_buffer[0],TxBufferSize1);         //将读出的数据通过串口输出  
  70.    }
  71.    while (1);
  72. }
  73. /****************************************************************************
  74. * 名    称:void Usart1_Init(void)
  75. * 功    能:串口1初始化函数
  76. ****************************************************************************/
  77. void Usart1_Init(void)
  78. {
  79.   GPIO_InitTypeDef GPIO_InitStructure;
  80.   USART_InitTypeDef USART_InitStructure;

  81.   RCC_APB2PeriphClockCmd( RCC_APB2Periph_USART1 , ENABLE);         //使能串口1时钟

  82.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;                                  //USART1 TX
  83.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  84.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;                     //复用推挽输出
  85.   GPIO_Init(GPIOA, &GPIO_InitStructure);                                     //A端口

  86.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;                          //USART1 RX
  87.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;            //复用开漏输入
  88.   GPIO_Init(GPIOA, &GPIO_InitStructure);                                  //A端口

  89.   USART_InitStructure.USART_BaudRate = 115200;                                                //速率115200bps
  90.   USART_InitStructure.USART_WordLength = USART_WordLength_8b;                //数据位8位
  91.   USART_InitStructure.USART_StopBits = USART_StopBits_1;                        //停止位1位
  92.   USART_InitStructure.USART_Parity = USART_Parity_No;                                //无校验位
  93.   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;   //无硬件流控
  94.   USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;                                        //收发模式

  95.   /* Configure USART1 */
  96.   USART_Init(USART1, &USART_InitStructure);                                                        //配置串口参数函数   
  97.    /* Enable the USART1 */
  98.   USART_Cmd(USART1, ENABLE);       
  99.   
  100. }
  101. /****************************************************************************
  102. * 名    称:void USART_OUT(USART_TypeDef* USARTx, uint8_t *Data,uint16_t Len)
  103. * 功    能:串口输出函数
  104. ****************************************************************************/
  105. void USART_OUT(USART_TypeDef* USARTx, uint8_t *Data,uint16_t Len){
  106.         uint16_t i;
  107.         for(i=0; i<Len; i++){
  108.                 USART_SendData(USARTx, Data[i]);
  109.                 while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET);
  110.         }
  111. }
  112. /****************************************************************************
  113. * 名    称:void Delay(__IO uint32_t nCount)
  114. * 功    能:延时函数
  115. ****************************************************************************/
  116. void Delay(__IO uint32_t nCount)
  117. {
  118.   for(; nCount != 0; nCount--);
  119. }
  120. /****************************************************************************
  121. * 名    称:void RCC_Configuration(void)
  122. * 功    能:系统时钟配置为72MHZ, 外设时钟配置
  123. ****************************************************************************/
  124. void RCC_Configuration(void){

  125.   SystemInit();          
  126.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  127.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC
  128.                                                   | RCC_APB2Periph_GPIOD| RCC_APB2Periph_GPIOE , ENABLE);
  129. }
  130. /****************************************************************************
  131. * 名    称:void GPIO_Configuration(void)
  132. * 功    能:通用IO口配置
  133. ****************************************************************************/  
  134. void GPIO_Configuration(void)
  135. {
  136.   GPIO_InitTypeDef GPIO_InitStructure;
  137.        
  138.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;                                     //状态LED1
  139.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                         //通用推挽输出模式
  140.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                         //输出模式最大速度50MHz
  141.   GPIO_Init(GPIOB, &GPIO_InitStructure);                                   
  142. }
复制代码

所有资料51hei提供下载:
STM32-SST25VF016B-SPI-mini.7z (179.82 KB, 下载次数: 16)


KD`A_0P0PU7[(NN5FQ0GLKS.png (72.79 KB, 下载次数: 44)

文件内具体内容

文件内具体内容
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表