This post is translated from Chinese into English through AI.View Original
AI-generated summary
The document discusses the STM32F407 microcontroller, focusing on its peripheral interfaces, particularly GPIO and ADC.
### GPIO (General Purpose Input/Output)
- The STM32F4 series has multiple GPIO registers controlling various functions, including mode, output type, speed, and pull-up/pull-down configurations.
- Each GPIO port has 16 pins, with specific registers for controlling their modes and behaviors.
- The GPIO mode register (GPIOx_MODER) sets the operational mode of the pins, while the output type register (GPIOx_OTYPER) controls the output type (push-pull or open-drain).
- The pull-up/pull-down register (GPIOx_PUPDR) allows for configuring pull-up or pull-down resistors.
### ADC (Analog to Digital Converter)
- The STM32F4 features three independent ADCs, with ADC1 and ADC2 capable of operating in dual mode for higher sampling rates.
- The ADCs are 12-bit successive approximation converters with 19 channels, allowing measurement of external and internal signals.
- Key features include configurable resolution, interrupt generation, and support for various sampling modes.
- Conversion can occur in regular or injected groups, with specific configurations for each.
### SPI (Serial Peripheral Interface)
- SPI is a communication protocol with a master-slave architecture, allowing for full-duplex communication.
- It uses four main signals: MISO, MOSI, SCLK, and CS.
- The working mode of SPI is determined by CPOL and CPHA, which define clock idle states and sampling edges.
- The document details the SPI control and status registers, outlining their bit configurations for data frame format, mode selection, and error handling.
Overall, the document provides a comprehensive overview of the STM32F407's GPIO, ADC, and SPI functionalities, highlighting their configurations and operational principles.
1.1.1.1 GPIO Port Mode Register (GPIOx_MODER) (x=A.. I)#
Used to control the working mode of GPIO
Each group of GPIO has 16 IO ports, with two register bits controlling 1 IO. The reset value of PortA is 0xA8000000, corresponding to the binary 1010 1000 0000 0000 0000 0000 0000 0000, indicating that PA 15/14/13 are in alternate function mode, while the other ports are in input mode.
1.1.1.2 GPIO Port Output Type Register (GPIOx_OTYPER)#
Used to control the output type of GPIO.
Does not take effect in input mode. The lower 16 bits are valid. In default output mode, the IO port is push-pull output.
1.1.1.3 GPIO Port Output Speed Register (GPIOx_OSPEEDR)#
Also only used in output mode.
1.1.1.4 GPIO Port Pull-Up/Pull-Down Register (GPIOx_PUPDR)#
STM 32 F 4 has 3 independently usable ADCs, among which ADC 1 and ADC 2 can be combined into dual mode to increase the sampling rate. The ADC of STM 32 is a 12-bit successive approximation ADC. It includes 19 channels, capable of measuring 16 external and 2 internal signal sources as well as the Vbat channel. The A/D conversion of these channels can be performed in single, continuous, scan, and discontinuous sampling modes. The converted results are stored in a 16-bit data register of LSB or MSB.
When any ADCx multi-channel performs a series of conversions in any order, grouped conversions are born, with two types of grouped conversions: regular group and injected group. The regular group allows up to 16 input channels for conversion, while the injected group allows up to 4 input channels for conversion.
"Injected" means breaking the original state, equivalent to an interrupt. If the injected group starts during the regular group conversion, the regular group will continue conversion only after the injected group conversion is completed.
The ADC conversion time calculation formula is $$
T_{CONV}=Sample_Time+TSAR\times ADC_CLK
Sampling time is controlled by the ADC_SMPR register.
ADC_CLK is generated by APB 2, and the division factor is set by the PPRE 2 in the RCC_CFGR register, with division options of 2/4/6/8/16.
### Registers
## Timer
The basic characteristics of the timer are as follows:

## SPI
SPI stands for Serial Peripheral Interface. The block diagram of SPI is as follows:

The pin information for SPI is:
1. MISO (Master In / Slave Out): Master device data input, slave device data output.
2. MOSI (Master Out / Slave In): Master device data output, slave device data input.
3. SCLK (Serial Clock): Clock signal, output from the master device.
4. CS (Chip Select): Slave device chip select signal, output from the master device.
==Working Principle==: In the SPI communication between the slave and master, there is a Shift Register in both. The master initiates a transmission by writing a Byte of data to its own shift register. The shift register transmits the byte to the slave via MOSI, while the slave transmits the contents of its byte shift register back to the master via MISO, thus achieving data exchange between the two shift registers. Therefore, if only write operations are performed, the master can ignore the received data. If the master wants to read data from the slave, it sends an empty byte to trigger the slave's transmission.
SPI supports full-duplex, half-duplex, and simplex transmission modes.
### SPI Working Modes
The working mode of SPI is determined by CPOL and CPHA, both of which have 0 and 1 states, so there are four working modes for SPI.
| Working Mode | CPOL | CPHA | SCL Idle State | Sample Edge | Sample Time |
| ---- | ---- | ---- | -------- | ---- | ---- |
| 0 | 0 | 0 | Low Level | Rising Edge | Odd Edge |
| 1 | 0 | 1 | Low Level | Falling Edge | Even Edge |
| 2 | 1 | 0 | High Level | Falling Edge | Odd Edge |
| 3 | 1 | 1 | High Level | Rising Edge | Even Edge |
From the table, it can be seen that CPOL determines whether the SCL idle state is high or low, and CPHA determines whether sampling occurs on the odd edge or the even edge of the clock.
### SPI Registers
#### SPI_CR1 (SPI Control Register 1)

- Bit 11 DFF: Data frame format, 0: 8-bit data frame, 1: 16-bit
- Bit 10 RXONLY: Receive only. 0: full-duplex, 1: receive only
- Bit 7: Frame format. 0: send MSB first, 1: send LSB first. **This bit should not be modified during communication**
- Bit 6: SPI enable. 0: disable peripheral, 1: enable peripheral.
- Bit 5-3: BR[2:0]: Control baud rate.
- 
- Bit 2: Master mode selection. 0: slave mode, 1: master mode
- Bit 1: CPOL
- Bit 0: CPHA
#### SPI_SR (SPI Status Register)

- Bits 15-9 are reserved, forced to 0
- Bit 8: Frame format error. 0: no frame format error, 1: frame format error
- Bit 7: Busy flag. 0: not busy, 1: SPI is in communication state or Tx buffer is not empty
- Bit 1: Send buffer empty. 0: not empty, 1: empty
- Bit 0: Receive buffer not empty. 0: empty, 1: not empty
#### SPI_DR (SPI Data Register)

When the data frame is 8 bits, only the lower eight bits are used; when it is 16 bits, the entire register is used.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.