KST-STM Learning I2C+SPI

Publisher:SereneDreamsLatest update time:2018-12-14 Source: eefocusKeywords:KST-STM  I2C  SPI Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I can only say that it is not much different from 51. I will just record the main precautions here.


1. I2C communication is divided into standard mode 100kbit/s, fast mode 400kbit/s and high-speed mode 3.4Mbit/s. Because all I2C devices support standard mode, but not necessarily the other two speeds. 


Therefore, as a general I2C program, we choose 100k rate to implement it. That is to say, the timing generated by the actual program must be less than or equal to the timing parameter of 100k. For devices with special speed requirements, we can write high-speed communication programs specifically.


2. The I2C pin is an open-drain parallel structure. When the GPIO port pin of STM32 is set to open-drain output, the I/O level status can be directly obtained from the input data register. Therefore, the I2C pin is configured as open-drain output mode.


3. Since the I2C bus is high by default when idle, the pin needs to be set to output high level during initialization. However, setting the pin to output high level should not be done after initialization, but before initialization. 


This is because the I/O port of STM32 is in high impedance state when it is powered on and reset. After the reset, the GPIO port pin defaults to floating input. Due to the presence of the pull-up resistor, the I 2 C pin is pulled high; 


When the program is executed to I2C initialization, it is configured as open-drain output mode. Since the initial value of the GPIO port output data register is all 0 by default, the I/O port outputs a low level after initialization. If the pin is set to output a high level after initialization, a low-level glitch will inevitably be generated on the I/O port. 


If the corresponding bit of the output data register is set high before the I 2 C pin is initialized, the I/O port will directly output a high level after the I 2 C pin is initialized to avoid glitch signals.


Write the picture description here


4. In fact, the configuration process of I2C is quite complicated. For example, it is necessary to fully consider the processing methods such as conflicts and arbitration, but those processing methods are not used in most occasions. The design of the I2C protocol module of the STM32F103 series is too complicated and not very practical for practical applications. Therefore, when I2C is actually applied, it is better to use the IO port to directly simulate the protocol.


5. That is, the SPI master starts to output data half a clock cycle earlier than the first clock edge of SCK, but the SPI slave starts to output data after the chip select SSEL is set low. In short, the SPI device outputs data earlier than SCK, which is why the chip select must be enabled first during SPI communication.


Write the picture description here

Write the picture description here


6. Comparison between SPI and I2C


Write the picture description here


7. SPI interface


Write the picture description here

8. Pin connection 


Write the picture description here


9. SPI peripherals 


Write the picture description here


Things to note about SP3 


Write the picture description here

Write the picture description here


Things to note about NSS 


Write the picture description here


A few points to note (marked in yellow)


Write the picture description here


10. Configuration process


Write the picture description here


11. Comparison between SPI sending and receiving and USART


Write the picture description here


12. Data transmission process


Write the picture description here


The judgment of sending completion needs attention 


Write the picture description here


So how should we judge? 


Write the picture description here


If data is still written to SPI_DR when TXE = 0


Write the picture description here


13. Domineering...


Write the picture description here


14. Notes on receiving and sending in SPI query mode


Write the picture description here

Keywords:KST-STM  I2C  SPI Reference address:KST-STM Learning I2C+SPI

Previous article:Use of STM32 ST-LINK Utility
Next article:Summary of eight GPIO modes of KST-STM learning

Recommended ReadingLatest update time:2024-11-16 11:38

ARM7 microcontroller (learning) - (VI), SPI interface - 01
6. SPI interface 6-(01) Introduction to SPI related applications and registers~~ 1. Features 2. Description 3. Pin description 4. Register Description a. SPI control register (SPCR—0XEOO2000)   b. SPI Status Register (SPSR —0XE0020004) c. SPI data register (SPDR - 0XE0020008) d. SPI clock c
[Microcontroller]
ARM7 microcontroller (learning) - (VI), SPI interface - 01
Serial Design Based on SPI of AVR Microcontroller
1. SPI interface of AVR microcontroller   The SPI (Serial Peripheral INTERFACE) bus system is a synchronous serial peripheral interface that allows the MCU to communicate and exchange data with various peripheral devices in a serial manner. It is widely used in various industrial control fields. Based on this standard
[Microcontroller]
Serial Design Based on SPI of AVR Microcontroller
LPC1788 SPI usage
#ifndef __SPI_H_ #define __SPI_H_   #include "common.h" #include "delay.h"   // cs p1.21 //sck p1.20 //miso p1.23 //mosi p1.24   #define SPI_CLOCK   12000000   void spi0_select_cs(void);   void spi0_disSelect_cs(void);   u8 spi0_rw_data(u8 writeByte);   void spi0_set_speed(u8 speed);   void spi0_init(u8 divide);      
[Microcontroller]
SPI initialization based on STM32F051 library function version
void SPI_Init(void) {   GPIO_InitTypeDef  GPIO_InitStruct;   SPI_InitTypeDef   SPI_InitStruct;   /*! SPI_CS_GPIO, SPI_MOSI_GPIO, SPI_MISO_GPIO, SPI_SCK_GPIO Init */   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF| RCC_AHBPeriph_GPIOB, ENABLE);   RCC_APB1PeriphClockCmd(FLASH_SPI2, ENABLE);    /*! Configure SPI pins: SCK */
[Microcontroller]
AsiaInfo Electronics launches new generation PCIe to multi-I/O (4S, 2S+1P, 2S+SPI, LB) controller
AsiaInfo Electronics launches the latest generation of "AX99100A PCIe to multi-I/O (4S, 2S+1P, 2S+SPI, LB) controller", providing a cost-effective PCIe to multi-serial and parallel I/O bridge chip solution. Through the PCI Express interface, customers can easily support multiple serial, parallel, SPI or local bus inte
[Network Communication]
AsiaInfo Electronics launches new generation PCIe to multi-I/O (4S, 2S+1P, 2S+SPI, LB) controller
Setting the slave address of the I2C device
I just started to use microcontrollers and I don’t understand a lot. Today I saw a sentence: #define WriteDeviceAddress 0xa0           //Write device address #define ReadDviceAddress 0xa1               //Read device address I don't understand how 0xa0 and 0xa1 are determined, so I looked up some information and se
[Microcontroller]
STM8L052C6 hardware I2C debugging: PCF8563/BM856 clock chip
The Internet generally advocates using software to simulate I2C. I also used simulation to read temperature and humidity sensors before. This time I have the time and opportunity to use I2C again, so I decided to debug it with hardware I2C. So far, there seems to be no problem, and both reading and writing devices are
[Microcontroller]
Shenzhou IV Study Notes (VI) I2C Interface EEPROM-Software and Hardware Implementation
EEPROM is also called electrically erasable programmable read-only memory. Data is not lost after power failure. It is widely used to save small amounts of data. Some enhanced 51 microcontrollers and AVRs have EEPROM integrated inside the chip. The development board uses the I2C interface ATMEL's 24C02 chip, which has
[Microcontroller]
Shenzhou IV Study Notes (VI) I2C Interface EEPROM-Software and Hardware Implementation
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号