STM32 SPI learning

SPI

The Serial Peripheral Interface is a high-speed, full-duplex, synchronous communication bus.

insert image description here
The SCK clock signal is sent by the host.
The SPI interface is mainly used in memory chips.
insert image description here
insert image description here

  1. SPI related pins: MOSI (output data line), MISO (input data line), SCK (clock), NSS (chip select).
  2. Data transmission and reception: related to buffers, shift registers, and pins.
  3. Clock signal: The SPI clock signal is configured through the SPI_CR1 register.
  4. Main control logic: involves two control registers SPI_CR1/2 for configuring SPI work, and SPI_SR for viewing the working status.

Using software to manage NSS, the NSS pin on the hardware can be used for other purposes, and the level is controlled through SSM and SSI. The master NSS is pulled high, and the slave NSS is active low.

Pins corresponding to SPI peripherals

The STM32 chip has multiple SPI peripherals, and the signals output by each SPI peripheral will go to different GPIO ports.
STM32F1 has three SPIs.
insert image description here
SPI is an edge protocol, and IIC is a level protocol.
The master only writes to the slave, and can ignore the received data from the slave.
Mainly to perform read operations on the slave, it is necessary to send an empty data to trigger the slave to send data.

SPI working mode

Clock Polarity (CPOL) The idle state level of the clock line when no data is being transmitted.

  • 0: SCK remains low in idle state
  • 1: SCK remains high in idle state

The clock phase (CPHA) clock line samples data on which clock edge.

  • 0: The first edge of SCK (odd number) samples the data bit, and the data is latched on the first edge of the clock.
  • 1: The second edge of SCK (even number) samples the data bit, and the data is latched on the second edge of the clock.

insert image description here

SPI related registers

insert image description here
SPI_CR1
insert image description here
insert image description here
SPI_SR
insert image description here
insert image description here
SPI_DR
insert image description here

SPI related HAL library driver

insert image description here
insert image description here
insert image description here

NOR FLASH

FLASH is a commonly used semiconductor device for storing data. It has the characteristics of large capacity, rewritable rewritable, rewritable by "sector/block", and data can continue to be saved after power failure.

FLASH can only write 0, not 1, and write 1 by erasing.

FLASH mainly has two types: NOR Flash and NAND Flash. NOR and NAND are two types of digital gate circuits.

insert image description here
insert image description here

NM25Q128

NM25Q128, a serial flash memory device, is a kind of NOR FLASH with a capacity of 128Mb. The erasing and writing cycle can reach 10W times, and the data can be stored for up to 20 years.

Guess you like

Origin blog.csdn.net/Caramel_biscuit/article/details/131974849