A collection of STM32 questions about GPIO

Original address: Collection of STM32 GPIO problems

STM32 Collection of GPIO questions

1. Question about GPIO


: The IO port of STM32 is initialized as input floating. Is the pin high or low?


A: It is neither high level nor low level, floating means not in use.


2. Questions about stm32f103 port multiplexing?


Q: When I was learning GPIO, I couldn't understand the problem of port multiplexing. Let me give an example:
PB6 and PB7 are used for normal IO by default. When I want to use I2C1, I turn on RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE) ;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB, ENABLE);
when I want to use to redefine I2C1, I want to open,
RCC_APB1PeriphClockCmd (RCC_APB1Periph_I2C1, ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_AFIO, ENABLE);
this understanding right?


Some people say that the AFIO clock must be turned on when the peripherals that come with the chip are used, but when I use usart1 without turning on the AFIO clock, I can still use usart. Why?
In short, the fundamental reason for asking this question is under what conditions should AFIO's clock be turned on?


Answer: 1. The serial port must open the AFIO clock, otherwise it will not work. Maybe your initialization function, RCC configuration has a place where it is turned on. 2. AFIO When you need to use a module, for example, you want to use GPIOC, you need to turn on the clock of the GPIOC module at this time. 3. Turn off the I2C instead of the bus of the I2C module. If you want to use the normal mode, you need to turn off the I2C module and reconfigure the GPIOB module, and it can be used normally.




3. What are the operation steps of AFIO remapping?


Answer: Enable the clock of the remapped I/O port Enable the peripheral clock to be remapped Enable the clock of the AFIO function (don't forget!) Perform remapping
 
 
4. The frequency of
 
configuring the IO port Q: Configuring the IO port When the frequency is higher, why only configure one IO port?
Answer: GPIO_InitStructure.GPIO_Speed ​​The members of this structure are always GPIO_Speed_50MHz. When configuring other io ports, 50MHz is also used by default.
 
 
 
5. How to start the peripheral input interrupt of the PB5 pin of the STM32W108CBU64 chip?
 
Q: Is there such a routine that enables peripheral interrupts and interrupt functions? 
Best answer: After reading the datasheet, the multiplexed functions of PB5 are PB5, ADC0, TIM2CLK, TIM1MSK. There should be related interrupts, depending on what peripherals you configure.
 
6. STM32F101 Tamper Pin usage problem
 
Q: Ask you prawns: How to initialize the Tamper Pin in STM32F101 BKP! ?
Answer: When TPAL=0: If the TAMPER pin is already high before intrusion detection is enabled (by setting the TPE bit), once the intrusion detection function is activated, an additional intrusion event will be generated (although in TPE There is no rising edge after bit '1'). ● When TPAL=1: If the intrusion detection pin TAMPER is enabled (by setting the TPE bit) before the intrusion detection pin is already low level, once the intrusion detection function is activated, an additional intrusion event will be generated (although in the TPE position There is no falling edge after '1'). Setting the TPIE bit in the BKP_CSR register to '1' generates an interrupt when a tamper event is detected. For details, please refer to: BKP_CSR
 
7. Questions about stm32f103 port multiplexing?
Q:
When I was learning GPIO, I couldn't understand the problem of port multiplexing. Let me give an example: 
PB6 and PB7 are used for normal IO by default. When I want to use I2C1, I turn on RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE) ; 
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB, ENABLE); 
when I want to use to redefine I2C1, I want to open, 
RCC_APB1PeriphClockCmd (RCC_APB1Periph_I2C1, ENABLE); 
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB, ENABLE); 
RCC_APB2PeriphClockCmd (RCC_APB2Periph_AFIO, ENABLE); 
this understanding right? 
Some people say that the AFIO clock must be turned on when the peripherals that come with the chip are used, but when I use usart1 without turning on the AFIO clock, I can still use usart. Why? 
In short, the fundamental reason for asking this question is under what conditions should AFIO's clock be turned on? 
Answer:
1. The serial port must open the AFIO clock, otherwise it will not work. Maybe your initialization function, RCC configuration has a place where it is turned on. 2. AFIO When you need to use a module, for example, you want to use GPIOC, you need to turn on the clock of the GPIOC module at this time. 3. Turn off the I2C instead of the bus of the I2C module. If you want to use the normal mode, you need to turn off the I2C module and reconfigure the GPIOB module, and it can be used normally.
7. In STM32, what is the use of setting GPIO_Mode_IPU
Q: The interrupt configuration includes: GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);                            GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9); The
GPIO port setting includes: GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
                       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
                       GPIO_Init(GPIOB, &GPIO_InitStructure); 
What I want to ask is, do these two sets of settings have to exist at the same time?
Answer: GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);         GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9); These two sentences in STM32 mean that pins 8 and 9 of the PB port are used as trigger signals for external interrupts, so Pin_8 and Pin_9 should be set as input mode, and GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; IPU means that the working mode of the IO port is with pull-up input, which is related to the specific circuit. In short, if you select an IO port as the trigger signal for an external interrupt, you must configure this IO The port is in input mode, otherwise the interrupt cannot be triggered. 8. How to understand the maximum output speed of the GPIO port in stm32? Q: How to understand the maximum output speed of the GPIO port in stm32? Answer: 1. This is the case, 2M, 10M and 50M refer to The sampling frequency of the GPIO port. I don't know if this is the right way to understand, but that's what I did.          2. I collect 80KBPS/S square wave through PB6, and collect through interrupt meter, which is completely competent.


 




9. Can STM32 GPIO weak pull-up be used for input and output?
Q: Can STM32 GPIO weak pull-up be used for input and output?
Answer: 32 has only pull-up input, and the one used for external connection is the drop-out output, so that it can be read correctly. For output, push-pull and open-drain are generally used. Push-pull is used for general driving. Open-drain generally adds a pull-up resistor to drive a larger current like a triode collector.


10. How is the STM32 statement: GPIO->ODR^=0X02 executed? What function to achieve?
Q: Is the data of the GPIO port stored in the ODR register, is the data XOR with 0x02 and then stored in the ODR?
Answer: ODR is the IO port output data register of stm32, the 31-16 bits of this register are always read as 0, 15-0 bits Output Data. GPIO->ODR^=0X02 is the XOR of the output data and 0x02, that is, if the second bit of the output data is the same as 1, the bit will be 0, otherwise it will be 1, so the inversion is realized, the output data is stored in the ODR, and each output is executed once The second bit of the data is inverted once.
10. GPIO configuration speed
Q: If the GPIO in stm32 is set to input mode, do you still need to configure GPIO_Speed?
A: The input mode does not need to configure the speed, but the output mode must determine the maximum output frequency.


11. stm32 GPIO input level detection
Q: GPIO two pins, the mode is initialized to input weak pull-up, one of the pins is connected to a voltage of 4.7V, the corresponding value of IDR is 1; the other pin is connected to 5.13 For the voltage of V, the value corresponding to IDR is 0;
A: Check whether the clock of the corresponding GPIO is enabled, whether there is such a sentence RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOx, ENABLE); if it is, it is enabled, otherwise the read value is unpredictable .
12. About GPIO register IDR and ODR data
in STM32 Q: Are the IDR and ODR data of GPIO register in STM32 synchronized? Why do I change the IDR and ODR at the same time when I use the GPIO_SetBits function to set the pins, and how can I only change the ODR data without changing the IDR data? Thanks!
Answer: The data in the IDR register reflects the state of the IO port in real time. Of course, when the ODR is set, the state of the IO also changes, unless it is forced to be set manually. For example, if the ODR is set to 1, and the corresponding IO port is forced to be grounded, then the IDR is inconsistent with the ODR; or the ODR is set to 0, and the corresponding IO port is forced to be connected to VCC, which is also inconsistent at this time.


13. With STM32, there are six GPIO ports (not in the same group) to output the same signal. How to set it?
Q: For example, pin10 of GPIOE is remapped to TIM1, and the PWM signal output of TIM1 is set; other IO ports such as pin5 of GPIOA, pin6 of GPIOA, pin5 of GPIOB, pin6 of GPIOB, and pin5 of GPIOC should also output the pin10 of GPIOE. The same signal, how do you set up the heroes?
Answer: Use the timer interrupt, configure the PWM pulse width as a timed interrupt, configure the GPIO pins, enable the corresponding clock, and then do the same processing in the timer interrupt function.


14. About GPIO_WriteBit and GPIO_SetBits
Q: What is the difference between GPIO_WriteBit and GPIO_SetBits
A: You can use the man command to check the difference
man ioctl :
NAME
       ioctl - control device
man write :
NAME
       write - write to a file descriptor


15. About GPIO_InitTypeDef GPIO_InitStructure
Q: What does this sentence mean?
Answer: Declare a structure, the name is GPIO_InitStructure, the prototype of the structure is determined by GPIO_InitTypeDef, and it is used to initialize GPIO in stm32. . After setting the contents of GPIO_InitStructure, call it in GPIO_Init (GPIO_TypeDef .
*GPIOx, GPIO_InitTypeDef *GPIO_InitStruct), for example, initialize the pa port, which is GPIO_Init (GPIOA, &GPIO_InitStructure), and the one after the parentheses is the structure declared in your question.


16. Can the IO port of STM32 directly control the output of the Px port like the IO port of 51
? Q: Hello everyone, can the IO port of STM32 directly control the output of the Px port like the IO port of 51? For example, if I want to use a 51-segment digital tube, I just need to send the hexadecimal value to the Px port? Can STM32 work?
Answer: Yes, give two examples: GPIO0->BRR = 0x55; GPIO1->BSRR = 0x55; GPIOx represents the number of the IO number, and BRR/BSRR represents the control register of the corresponding IO port, just follow this format Just do it.


 17. About the configuration
of the IO port of the stm32 chip: When the IO port of the stm32 chip is configured as a floating input, can the level status of the port be read.
Answer: The reading of the input status register GPIOx_IDR and output status register and GPIOx_ODR of STM32 is not affected by the port configuration. 
 
18. stm32 JTAG and common IO multiplexing question
 
: stm32 JTAG and common IO multiplexing, when the software is set to common IO, can you still use JTAG to download software?
Answer: Yes. Because when downloading, the download mode is entered through the RESET timing. But pay attention to the hardware connection method, do not force high and low, and do not let the output pin of its chip connect. This will affect jtag.
 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325893162&siteId=291194637