【iCore1S 雙核心板_ARM】例程十三:SDIO實驗——讀取SD卡資訊

XiaomaGee發表於2017-09-07

實驗現象:

核心程式碼:

int main(void)
{

  /* USER CODE BEGIN 1 */
    HAL_SD_TransferStateTypedef State;

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SDIO_SD_Init();
  MX_USART1_UART_Init();
  SystemClock_Config();

  /* USER CODE BEGIN 2 */
    usart1.printf("\x0c");                                   //ÇåÆÁ    
    usart1.printf("\033[1;32;40m");                          //ÉèÖÃ×ÖÌåÖÕ¶ËΪÂÌÉ«
    usart1.printf("\r\n\r\nhello! I am iCore1S!\r\n\r\n\r\n");

  if(State == SD_TRANSFER_OK)                 //ÅжÏSD¿¨ÊÇ·ñ³õʼ»¯
    {    
        usart1.printf("SD ERROR!\r\n");        //Èô³õʼ»¯´íÎóÔòÊä³ö¡°SD ERROR¡±£¬ºìµÆÉÁ˸¡£
        
            while(1){
            HAL_Delay(500);
            LED_RED_TOGGLE ;
        }
    }
    
    //Êä³öSD¿¨µÄÀàÐÍ
    switch(SDCardInfo.CardType){
        case STD_CAPACITY_SD_CARD_V1_1:
            usart1.printf("SD CardType\t\t: SDIO_STD_CAPACITY_SD_CARD_V1_1\r\n");
            break;
            
        case STD_CAPACITY_SD_CARD_V2_0:
            usart1.printf("SD CardType\t\t: SDIO_STD_CAPACITY_SD_CARD_V2_0\r\n");
            break;
            
        case HIGH_CAPACITY_SD_CARD:
            usart1.printf("SD CardType\t\t: SDIO_HIGH_CAPACITY_SD_CARD\r\n");
            break;
            
        case MULTIMEDIA_CARD:
            usart1.printf("SD CardType\t: SDIO_MULTIMEDIA_CARD\r\n");
            break;
    }
    
    //Êä³öSD¿¨µÄ²ÎÊý
    usart1.printf("SD CardCapacity\t\t: %dMB\r\n",(unsigned long int)(SDCardInfo.CardCapacity >> 20));//SD ¿¨µÄÈÝÁ¿
    usart1.printf("SD CardBlockSize\t: %dByte\r\n",SDCardInfo.CardBlockSize);// »ñÈ¡SDCardÉÏÿ¸öblockµÄSIZE  
    usart1.printf("SD RCA \t\t\t: %d\r\n",SDCardInfo.RCA);                                        //»ñÈ¡Ïà¶Ô¿¨µØÖ·
    usart1.printf("SD ManufacturerID\t: %d\r\n",SDCardInfo.SD_cid);                        //³ö³§ID

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
            HAL_Delay(500);
            LED_GREEN_TOGGLE;        //Â̵ÆÉÁ˸
        

  }
  /* USER CODE END 3 */

}

原始碼下載連結:

連結:http://pan.baidu.com/s/1jIgOPhG 密碼:44iy

相關文章