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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 7989|回復: 8
打印 上一主題 下一主題
收起左側

stm32讀取SD卡信息程序,通過SPI的方式

  [復制鏈接]
跳轉到指定樓層
樓主
ID:225248 發表于 2017-8-6 19:00 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
這是一個讀取SD卡信息的程序
所有資料51hei提供下載:
SD程序.rar (2.53 MB, 下載次數: 223)


stm32單片機源程序如下:
  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卡數據緩存區
  46. int main(void)
  47. {
  48.   u8 tmp;
  49.   u16 mm,nn;
  50.   u32 nummber,nummber_bak;

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

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


  57.   //檢測當前系統時鐘SystemCoreClock
  58.   SystemCoreClockUpdate ();



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

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

  67.   //邏輯0扇區的物理扇區號
  68.   nummber_bak=SD_GetLogic0();

  69.   while(1)
  70.   {
  71.     RxCounter1=0;
  72.     printf("\r\n請發送要讀取的邏輯扇區號\r\n");

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

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

  82.     if(SD_ReadBlock(SD_Buffer,nummber_bak+nummber,512)==0)//讀指定扇區
  83.                
  84.     printf("\r\n第%d邏輯扇區數據:",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測試程序");           
  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); /*發送一個字符函數*/

  110.   /* Loop until the end of transmission */
  111.   while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)/*等待發送完成*/
  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****/
復制代碼




分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏6 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:290380 發表于 2018-5-28 21:41 | 只看該作者
不錯哦,學習一下
回復

使用道具 舉報

板凳
ID:122107 發表于 2018-7-3 13:16 | 只看該作者
不錯哦,學習一下
回復

使用道具 舉報

地板
ID:138247 發表于 2018-7-24 15:31 | 只看該作者

不錯哦,學習一下
回復

使用道具 舉報

5#
ID:221379 發表于 2019-3-26 11:14 | 只看該作者
好東西,學習一下
回復

使用道具 舉報

6#
ID:318452 發表于 2019-7-23 21:51 | 只看該作者
看下學習下
回復

使用道具 舉報

7#
ID:349782 發表于 2019-9-25 10:50 | 只看該作者

好東西,學習一下
回復

使用道具 舉報

8#
ID:739683 發表于 2020-5-11 18:00 | 只看該作者
不錯,有參考價值
回復

使用道具 舉報

9#
ID:285416 發表于 2020-7-18 05:51 | 只看該作者
LZ,給個原圖嘛,
  //使能PA時鐘,PC時鐘,SPI1時鐘和APB2復用功能時鐘
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 | RCC_APB2Periph_AFIO, ENABLE);

  //關閉SPI所有相關器件:SD_CS(SD卡),W25_CS(W25X16),T_CS(觸摸屏),N_CS(RF24L01無線模塊)
  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);

雖然有說明,還是不確定-----.C12 是CS,上面的,C9-10-11,是關閉一些外設的,這個必有的嘛
還有,就是,CLK,和MOMI,對應是,A5和7嘛
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 精品区一区二区 | 久草成人| 一级黄色片在线免费观看 | 欧美午夜视频 | 久久综合久色欧美综合狠狠 | 国产成人精品免费视频大全最热 | 亚洲一二三区免费 | 一区二区三区视频在线 | 国产精品免费观看视频 | 中文字幕不卡视频在线观看 | 色av一区二区 | 国产三级大片 | 欧美国产精品 | 欧美一级久久精品 | 久久精品亚洲精品 | 人人九九精| 亚洲精品视频在线 | 国产欧美日韩在线 | 夜夜骚| 国产精品亚洲综合 | 午夜免费电影 | 91社区在线观看高清 | 成年人精品视频在线观看 | 国产一区91精品张津瑜 | 奇米超碰 | 亚洲欧美中文日韩在线v日本 | 欧美伊人 | 中文字幕成人av | 国产精品一区久久久 | 男女精品久久 | 国产精品日日摸夜夜添夜夜av | 亚洲精品福利视频 | 中文字幕av中文字幕 | 国产一区二区av | 欧美一级欧美三级在线观看 | 精品久久久久一区二区国产 | 综合久久av | 中文字幕欧美日韩 | 免费99视频 | 中文字幕av第一页 | 日韩视频三区 |