Implementation of STM32_SPI multi-machine communication - sorted from the Internet

Publisher:炫酷骑士Latest update time:2017-09-29 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There are several points that are easy to go wrong in SPI two-machine communication using DMA:

1) Frequency division value: The maximum frequency of SPI is 18M, SPI1 is on APB2 with a frequency of 72M, and SPI2 is on APB1 with a frequency of 36M. If the chip clock frequency is 72M, then the frequency division value of SPI1 is 4 and the frequency division value of SPI2 is 2.

2) DMA start sequence: I saw someone on the Internet saying that you should start the slave to send first, then the master to send, then the slave to receive, and finally the master to receive. I don't know why you should do this, and this way of starting DMA is difficult to implement. You may need to add two more handshake lines to determine whether the other party has started DMA. My program "slave receive-slave send-master receive-master send" sequence is also feasible.
3) DMA interrupt: When the data is sent to the first bit of the last byte, if you turn on the DMA send interrupt, you will enter the DMA send interrupt function. At this time, you cannot clear the flag immediately. You must query the ISR register to determine whether the remaining 7 bits of data have also been transmitted, and then determine whether the SR register is busy. Only after all are completed can you clear the flag and reconfigure the DMA data length, otherwise your subsequent data will be wrong.
4) Pull-up resistor: If you don't add pull-up resistor, you will occasionally get an error. This error cannot be seen in simulation. My simulation is correct every time, but I unplug the simulator and keep testing and find that the data is wrong. There can be 1 error in 5 restarts. After adding it, the data is abnormally stable. I don't understand why the online information does not add pull-up resistors.
5) Reset the buffer address: Since the project requires a variable-length buffer, I used malloc and free many times to allocate the buffer size, which caused the buffer address to change constantly, so I had to disable DMA and then reconfigure the DMA buffer address.
6) Host transmission process without interruption: I saw online that after the host enables DMA, it waits there to check whether the DMA has completed the transmission, which does not play the role of DMA. The frequency of SPI is 18M, and DMA is said to be about 10M. If you use the dead waiting method, it is better not to use DMA.

Therefore, if the host does not use the DMA interrupt method, two functions can be written, one to enable DMA and the other to determine whether the DMA transfer is completed. Between these two functions, the CPU can do its own thing, anyway, the host has the initiative.



It is recommended to add a three-state driver chip such as 243 for multiple slaves, which can make the SPI speed very fast and stable. If allowed, a better way is to add one to each slave to isolate it from the host, so that even if a slave has a problem, it will not affect the bus.


Keywords:STM32 Reference address:Implementation of STM32_SPI multi-machine communication - sorted from the Internet

Previous article:Keil MDK develops STM32 using inline functions
Next article:STM32+IAP solution realizes network upgrade application firmware

Recommended ReadingLatest update time:2024-11-16 13:33

Take stm32's TIM2 as an example and configure it step by step to become a timer
The following uses stm32's TIM2 as an example to configure it step by step as a timer:   1: Basic configuration of the timer      TIM_TimeBaseStructure.TIM_Period = 65535; //Set the automatic loading register             TIM_TimeBaseStructure.TIM_Prescaler = 100; //Division count          TIM_TimeBaseStructure.TIM_Clo
[Microcontroller]
STM32 and HC-SR04 ultrasonic distance measurement
First, let’s take a look at the basic functions and principles of this module. HC-SR04 ultrasonic distance measurement module can provide non-contact distance sensing function of 2cm-400cm, and the distance measurement accuracy can reach up to 3mm; the module includes ultrasonic transmitter, receiver and control circu
[Microcontroller]
STM32 and HC-SR04 ultrasonic distance measurement
STM32 study notes DS18B20
The STM32 development board I bought has very few peripherals, not even a digital tube, and the display must be done on the hyperterminal through the serial port. I am very lazy, so I picked a more convenient device DS18B20 to play with. DS18B20 is an entry-level device for learning embedded development, and it is als
[Microcontroller]
Solution to STM32 HSE initialization failure and HSI initialization
I encountered a problem by chance. What should I do if HSE initialization fails? The library function does not provide a processing method, but only writes    if (HSEStatus == (uint32_t)0x01) { . . . }  else   { /* If HSE fails to start-up, the application will have wrong clock           configuration. Us
[Microcontroller]
Solution to STM32 HSE initialization failure and HSI initialization
STM32 uses systick to accurately delay nms
/***************************************************************************** * File Name          : systick_delay.h * Author             : shifu * Version            :  * Date               : 09/20/2008 * Description        :  ********************************************************************************/ /*
[Microcontroller]
STM32 interrupt priority concept
I. Overview STM32 currently supports a total of 84 interrupts (16 cores + 68 external), which can provide 16 levels of programmable interrupt priority settings (only using the upper 4 bits of the interrupt priority setting 8 bits) and 16 preemption priorities (because the preemption priority can be up to 4 bits). 2. P
[Microcontroller]
Common local communication methods for 8051/2 microcontrollers: UART, RS485, I2C, SPI, Modbus 485 2
1. Description 1. Serial port UART, baud rate: 9600 When connecting a device, generally only GND RX TX is connected, and Vcc is not connected to avoid power supply conflicts with the target device. 1.1 RS485 standard (+2V ~ +6V: 1 / -6V ~ -2V: 0) 1.2 RS232 standard (-15V ~ -3V: 1 / +3V ~ +15V: 0), MAX232 needs
[Microcontroller]
Common local communication methods for 8051/2 microcontrollers: UART, RS485, I2C, SPI, Modbus 485 2
stm32 j-link offline operation settings after burning under IAR
1、 projectEWARMv4lnkarm_flash.xcl // Code memory in FLASH -DROMSTART=0x8008000 -DROMEND=0x8014fff   change to // Code memory in FLASH -DROMSTART=0x8000000 -DROMEND=0x8014fff   2、 #define NVIC_VectTab_RAM                         ((u32)0x20000000) #define NVIC_VectTab_FLASH                     ((u32)0
[Microcontroller]
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号