1 void SPIx_Init(void)
2 {
3 RCC->APB2ENR|=1<<2; //PORTA clock enable
4 RCC->APB2ENR|=1<<12; //SPI1 clock enable
5
6 //Here is only for SPI port initialization
7 GPIOA->CRL&=0X000FFFFF;
8 GPIOA->CRL|=0XBBB00000; //PA5.6.7 multiplexed push-pull output
9 //GPIOA->ODR|=0X7<<5; //PA5.6.7 pull-up should not work because this mode
10 SPI1->CR1&=~(1<<6); //Turn off SPI to configure some bits
11
12 SPI1->CR1&=~(1<<15); //1: two-line bidirectional mode 0: unidirectional bidirectional mode
13 SPI1->CR1&=~(1<<13);//1: Enable CRC check 0: Disable CRC check Can only be rewritten when SPE=0, otherwise an error will occur. Can only be used in full-duplex mode
14 SPI1->CR1|=0<<11; //1: 16-bit data format 0: 8-bit data format It can only be rewritten when SPE=0, otherwise an error will occur.
15 SPI1->CR1|=0<<10; //1: full-duplex mode 0: receive only mode
16 SPI1->CR1|=1<<9; //1: Enable software slave device management 0: Disable software slave device management When it is 1, the NSS level is determined by the SSI bit
17 SPI1->CR1|=1<<8;//
18 SPI1->CR1|=0<<7; //1: send MSB first 0: send LSB first
19 SPI1->CR1|=0<<3 //5~3bit: frequency division coefficient 0~7 The frequency division coefficient is Fpclk/2, 4, 8, 16, 32, 64, 128, 256
20 SPI1->CR1|=1<<2; //1: master device 0: slave device
21 SPI1->CR1|=1<<1; //CPOL 1: SCK is 1 when idle 0: SCK=0 when idle
22 SPI1->CR1|=1<<0; //CPHA 1: Data sampling starts from the second clock edge 0: Data sampling starts from the first clock edge
23 SPI1->CR1|=1<<6; //1: turn on SPI 0: turn off SPI
twenty four }
Previous article:DMA configuration of STM32
Next article:NVIC interrupt control function implementation
Recommended ReadingLatest update time:2024-11-16 14:50
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- LSM6DSO MicroPython driver porting
- Keil C51 MCU Programming Software and Instructions Learning Tutorial (Full Version)
- 8 circuit designs that you must know about microcontrollers
- Antenna-on-Package Design Simplifies mmWave Sensing in Buildings and Factories
- Share: UC3842 switching power supply maintenance example
- Last week! TouchGFX prize-winning experience event, users who haven’t submitted their works yet, hurry up
- The use of const and code in KEIL C51
- The world's smallest gingerbread house
- I have a problem with using the eclipse that comes with altera. Can anyone tell me what I have used?
- Hardware Emulation