STM32_SPI driver analysis (SD card)

Publisher:幸福时刻Latest update time:2018-08-21 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

SD card has two optional communication protocols: SD mode and SPI mode. In order to simplify the circuit and program, SPI mode is selected. ZC09's SD is connected to STM32 through SPI1. Because STM32 has an integrated SPI controller, SPI timing can be achieved with simple configuration.

 

1. Configure SPI1 controller

1. First, you need to turn on the clock of SPI1 and the clock of the GPIO port where the SPI1 signal line is located. Since the SPI1 signal line is on GPIOA, use the following code to turn on the required clock. It should be noted that it is best to turn on SPI1 and GPIOA together, because I have tried to turn on the SPI1 clock first, and then turn on the GPIOA clock after a few lines of code, which caused the SD card operation to fail.

    

 

2. Configure pins 5, 6, and 7 of GPIOA as multiplexed push-pull outputs, 50MHz.

 

 

3. The enable pin of the SD card is directly connected to pin 15 of GPIOB of STM32, so I also want to configure this pin.

    

 

4. The next step is to configure the SPI1 controller. According to the SD card data sheet, configure the registers of the SPI1 controller.                    

   

5. After configuration, you can start the SPI1 controller.

 

2. Write other SPI drivers

1. Since the operation of SD card after power-on is in low speed mode, the operation of SD card after power-on must be less than 400kHz, so we need to write an interface that can set the SPI speed.

 

2. SPI read and write driver

 


Keywords:STM32 Reference address:STM32_SPI driver analysis (SD card)

Previous article:STM32 IAP program upgrade
Next article:STM32 SD card test, using Cubemax configuration

Recommended ReadingLatest update time:2024-11-22 20:03

Create a keil project and light up the LED light of the STM32 board
Open the previously created project, as shown in the figure below (the creation of the Keil project is in the previous article, and students who don’t know can turn to the previous article.) (The picture above is a completed project) Then, open the LED light routine in the routine package of the corresponding develo
[Microcontroller]
(I) CMSIS standard, library directory, GPIO of stm32
1. CMSIS Standard   ST's stm32 uses the cortex-m3 core, which is the CPU of the entire microprocessor. The core is a processor architecture designed by ARM. The relationship between the core and peripherals is like the relationship between the CPU and the hard disk, motherboard, memory, etc. on a PC. The processor cor
[Microcontroller]
(I) CMSIS standard, library directory, GPIO of stm32
STM32 UART4 UART5
Today, when debugging the serial port program (STM32107RC), I found that UART4 was clearly configured and could send, but it could not interrupt the reception. I saw many people on the Internet had this question. I finally solved it tonight and wrote a blog by the way. I hope it can help the next person who encounters
[Microcontroller]
STM32 ADC conversion interrupt read
The ADC interrupt reading method is suitable for low-frequency ADC acquisition, while high-frequency AD acquisition must use DMA. The initialization function of ADC interrupt reading only adds an interrupt configuration file compared to the direct reading method in the previous article. The code is as follows: static
[Microcontroller]
About assert_param() in STM32
In the STM32 firmware library and the provided routines, assert_param() can be seen everywhere. If you open the stm32f10x_conf.h file in any routine, you can see that assert_param is actually a macro definition; In the firmware library, its function is to detect whether the parameters passed to the function are valid
[Microcontroller]
stm32 EXTI interrupt BUG, ​​unable to enter external interrupt problem
When I was debugging a program, I found that there was an EXTI interrupt that I could not enter no matter what. Although I checked various experiences on the Internet, none of them helped my program. Later, I finally found the problem. The reason was that there were some problems with the official library function.  T
[Microcontroller]
BMP180 test based on STM32 platform (simulated IIC)
1. Test description: Use analog IIC to get the ID number, temperature, pressure and altitude from BMP180. 2. Test preparation: Hardware platform: Atomic Battleship V3 development board  Test tools: logic analyzer, serial port debugging tool 3. Data sheet interpretation: (1) First is the timing diagram of reading m
[Microcontroller]
BMP180 test based on STM32 platform (simulated IIC)
STM32 printf function remapping
/* Private function prototypes --------------------------------------------- --*/ #ifdef __GNUC__   /* With GCC/RAISONANCE, small printf (option LD Linker- Libraries- Small printf      set to 'Yes') calls __io_putchar() */   #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else   #define PUTCHAR_PROTOTYPE int
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号