久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標(biāo)題: stm32讀取SD卡信息程序,通過(guò)SPI的方式 [打印本頁(yè)]

作者: LCIOT    時(shí)間: 2017-8-6 19:00
標(biāo)題: stm32讀取SD卡信息程序,通過(guò)SPI的方式
這是一個(gè)讀取SD卡信息的程序
所有資料51hei提供下載:
SD程序.rar (2.53 MB, 下載次數(shù): 223)


stm32單片機(jī)源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    USART/Printf/main.c
  4.   * @author  MCD Application Team
  5.   * @version V3.3.0
  6.   * @date    04/16/10
  7.   * @brief   Main program body
  8.   ******************************************************************************
  9.   * @copy
  10.   *
  11.   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12.   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13.   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14.   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15.   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16.   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17.   *
  18.   * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
  19.   */

  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f10x.h"
  22. #include "delay.h"
  23. #include <stdio.h>
  24. #include <stdlib.h>

  25. #include "sd.h"
  26. #include "usart.h"

  27. /* Private macro -------------------------------------------------------------*/
  28. /* Private variables ---------------------------------------------------------*/
  29. USART_InitTypeDef USART_InitStructure;
  30. GPIO_InitTypeDef GPIO_InitStructure;

  31. /* Private function prototypes -----------------------------------------------*/

  32. #ifdef __GNUC__
  33.   /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
  34.      set to 'Yes') calls __io_putchar() */
  35.   #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  36. #else
  37.   #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  38. #endif /* __GNUC__ */
  39.   

  40. /**
  41.   * @brief  Main program
  42.   * @param  None
  43.   * @retval None
  44.   */
  45. u8 SD_Buffer[512];//SD卡數(shù)據(jù)緩存區(qū)
  46. int main(void)
  47. {
  48.   u8 tmp;
  49.   u16 mm,nn;
  50.   u32 nummber,nummber_bak;

  51.   //設(shè)置優(yōu)先級(jí)分組:搶占優(yōu)先級(jí)和響應(yīng)優(yōu)先級(jí)各2位
  52.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  53.   //設(shè)置向量表的位置和偏移:在FLASH中偏移為0
  54.   NVIC_SetVectorTable(NVIC_VectTab_FLASH,0);

  55.   //USART1初始化
  56.   USART1_Init();


  57.   //檢測(cè)當(dāng)前系統(tǒng)時(shí)鐘SystemCoreClock
  58.   SystemCoreClockUpdate ();



  59.   //檢測(cè)SD卡,失敗則2秒后繼續(xù)檢測(cè)
  60.   while(SD_Init()!=0)
  61.   {
  62.      printf("\r\n未檢測(cè)到SD卡!");
  63.      delay_ms(SystemCoreClock,1000);
  64.      delay_ms(SystemCoreClock,1000);
  65.   }

  66.   printf("\r\n初始化SD卡成功!\r\n");

  67.   //邏輯0扇區(qū)的物理扇區(qū)號(hào)
  68.   nummber_bak=SD_GetLogic0();

  69.   while(1)
  70.   {
  71.     RxCounter1=0;
  72.     printf("\r\n請(qǐng)發(fā)送要讀取的邏輯扇區(qū)號(hào)\r\n");

  73.         do
  74.         {  //等待接收停止100mS
  75.           tmp = RxCounter1;
  76.           delay_ms(SystemCoreClock,100);
  77.     }while(RxCounter1==0 || tmp!=RxCounter1);

  78.         
  79.         //將接收到的字符串轉(zhuǎn)換成數(shù)值
  80.     RxBuffer1[RxCounter1]='\0';
  81.     nummber=atol((const char *)RxBuffer1);

  82.     if(SD_ReadBlock(SD_Buffer,nummber_bak+nummber,512)==0)//讀指定扇區(qū)
  83.                
  84.     printf("\r\n第%d邏輯扇區(qū)數(shù)據(jù):",nummber);

  85.     for(mm=0;mm<32;mm++)
  86.     {
  87.       printf("\r\n%03xH  ",mm<<4);
  88.                
  89.       for(nn=0;nn<16;nn++)
  90.             printf("%02x ",SD_Buffer[(mm<<3)+nn]);
  91.         }
  92.     printf("\r\n");
  93.   }





  94. //  while (1)
  95. //  {
  96. //          delay_ms(SystemCoreClock,1000);
  97. //        printf("\r\n串口1測(cè)試程序");           
  98. //  }
  99. }

  100. /**
  101.   * @brief  Retargets the C library printf function to the USART.
  102.   * @param  None
  103.   * @retval None
  104.   */
  105. PUTCHAR_PROTOTYPE
  106. {
  107.   /* Place your implementation of fputc here */
  108.   /* e.g. write a character to the USART */
  109.   USART_SendData(USART1, (uint8_t) ch); /*發(fā)送一個(gè)字符函數(shù)*/

  110.   /* Loop until the end of transmission */
  111.   while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)/*等待發(fā)送完成*/
  112.   {
  113.   
  114.   }
  115.   return ch;
  116. }

  117. #ifdef  USE_FULL_ASSERT

  118. /**
  119.   * @brief  Reports the name of the source file and the source line number
  120.   *         where the assert_param error has occurred.
  121.   * @param  file: pointer to the source file name
  122.   * @param  line: assert_param error line source number
  123.   * @retval None
  124.   */
  125. void assert_failed(uint8_t* file, uint32_t line)
  126. {
  127.   /* User can add his own implementation to report the file name and line number,
  128.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  129.   /* Infinite loop */
  130.   while (1)
  131.   {
  132.   }
  133. }
  134. #endif

  135. /**
  136.   * @}
  137.   */

  138. /**
  139.   * @}
  140.   */

  141. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
復(fù)制代碼





作者: 阿瓦塞翻譯    時(shí)間: 2018-5-28 21:41
不錯(cuò)哦,學(xué)習(xí)一下
作者: scypw    時(shí)間: 2018-7-3 13:16
不錯(cuò)哦,學(xué)習(xí)一下
作者: plj213    時(shí)間: 2018-7-24 15:31

不錯(cuò)哦,學(xué)習(xí)一下
作者: abcd123.    時(shí)間: 2019-3-26 11:14
好東西,學(xué)習(xí)一下
作者: godlzm    時(shí)間: 2019-7-23 21:51
看下學(xué)習(xí)下
作者: 牛奶大開(kāi)發(fā)    時(shí)間: 2019-9-25 10:50

好東西,學(xué)習(xí)一下
作者: 52301    時(shí)間: 2020-5-11 18:00
不錯(cuò),有參考價(jià)值
作者: nmgbtzyf    時(shí)間: 2020-7-18 05:51
LZ,給個(gè)原圖嘛,
  //使能PA時(shí)鐘,PC時(shí)鐘,SPI1時(shí)鐘和APB2復(fù)用功能時(shí)鐘
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 | RCC_APB2Periph_AFIO, ENABLE);

  //關(guān)閉SPI所有相關(guān)器件:SD_CS(SD卡),W25_CS(W25X16),T_CS(觸摸屏),N_CS(RF24L01無(wú)線(xiàn)模塊)
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  GPIO_SetBits(GPIOC,GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12);
       
  //使能SPI1引腳(SCK和MOMI)推挽輸出
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
       
  //使能SPI1引腳(MIMO)上拉輸入
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

雖然有說(shuō)明,還是不確定-----.C12 是CS,上面的,C9-10-11,是關(guān)閉一些外設(shè)的,這個(gè)必有的嘛
還有,就是,CLK,和MOMI,對(duì)應(yīng)是,A5和7嘛




歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 欧美不卡 | www.五月天婷婷 | 国产一区 | 亚洲一区免费视频 | 视频在线观看一区二区 | 美女久久| 成人av网站在线观看 | 亚洲精品久久久一区二区三区 | av中文字幕在线 | 久久精品国产久精国产 | 亚洲精品久久久久久久不卡四虎 | 精品在线免费看 | 亚洲精品欧美一区二区三区 | 国产高清在线精品一区二区三区 | 在线一区| 亚洲精品久久久久久久久久吃药 | 国产精品久久久久久婷婷天堂 | 中国三级黄色录像 | 天天射夜夜操 | 国产免费一区二区三区 | 高清国产午夜精品久久久久久 | 在线视频日韩精品 | 久草新视频 | 久久中文高清 | 日韩一级免费观看 | 一区二区三区视频在线观看 | 日韩欧美在线视频 | 99亚洲精品 | 日韩在线免费播放 | 欧美日韩一区二区三区四区 | 亚洲一区二区三区四区五区中文 | 一级免费在线视频 | 黄a免费网络| 国产日韩精品在线 | 亚洲va国产日韩欧美精品色婷婷 | 一区二区视频在线 | 国产一区二区三区在线 | 日韩欧美精品一区 | 福利视频三区 | 99精品国产一区二区青青牛奶 | 欧美在线a|