In STM32, when you want to configure it as a slave, just configure its NSS pin to low level. If you want to configure SPI as a master, you also need to configure this NSS, but this time configure it to SPI_NSS_Soft. What are SPI_NSS_Soft and SPI_NSS_Hard? Let's take a look at the description in the data sheet: In the spi.h file of stm32, it is defined as follows
#define SPI_NSS_Soft ((uint16_t)0x0200)
#define SPI_NSS_Hard ((uint16_t)0x0000)
It corresponds to the 9th bit (starting from the 0th bit) SSM (Software slave management) of the SPI control register. The data sheet says that when SSM is 1, the input of the NSS pin is replaced by the SSI (8th bit of empty register 1) value; when it is 0, it corresponds to the state of the external NSS pin.
Let's take a look at configuring the master:
#define SPI_Mode_Master ((uint16_t)0x0104)
#define SPI_Mode_Slave ((uint16_t)0x0000)
From #define SPI_Mode_Master ((uint16_t)0x0104), we can see that the 2nd bit is configured to 1 and the 8th bit is configured to 1. In the SPI control register, the 2nd bit is MSTR. When this bit is configured to 0, the SPI is configured to slave mode. If this bit is 1, it is configured to master mode. The 8th bit is SSI (internal slave selection bit). The data sheet states that only when the SSM bit is 1, the value of the SSI bit is forced to correspond to the NSS pin, and the value of the NSS pin I/O register is ignored. When SSI is 1, the corresponding NSS pin is 1. From its internal point of view, it is enabled and configured as a master.
Maybe you are a little confused, what is NSS pin and what is NSS pin I/O? My understanding is that NSS pin is one of the signal lines of SPI communication, which can be connected to the real I/O port unnecessarily and can be set and reset by software; while NSS pin I/O is the external I/O port connected to the NSS signal line. For example, as mentioned in the third paragraph above, the input of NSS pin is replaced by the value of SSI.
Previous article:Understanding the SSM and SSI bits of the SPI_CR1 register of STM32
Next article:stm32 uses backup registers to save real-time clock data
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
- [NXP Rapid IoT Review] Rapid IoT Studio Simple Programming Step 4 Add Bluetooth RGB Light Control
- EEWORLD University - What is Dynamic Multi-Protocol Manager (DMM)?
- Ordered an MPLAB Snap
- The information on the varactor diode, laser pointer, supercapacitor, TF card and SD card on the list is all here!
- 【 Don't miss it! 9/10@Shenzhen】2019 WPI/TI Latest PoE Solutions Seminar
- Puzhong Technology 51 MCU Development Board v3.0 Dynamic Digital Tube Part
- STM32F103 timer clock not understood
- Why do clocks use 32.768K crystals?
- Problems and Solutions in TMS320F206 Simulation Debugging
- DCDC input end inrush current problem