Some lessons on STM3216 IO port operation

Publisher:巳午未Latest update time:2018-09-06 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I have taken a lot of detours when using TFT screens recently. Since TFT screens are all 16-bit, most of them use a set of IO ports corresponding to 16 data bits to transmit data through parallel ports. Recently, due to the shortage of IO ports, I wanted to change to a serial port, but found that the serial port refreshes the screen too slowly, so I finally changed to an 8-bit parallel port. However, the registers for operating the IO port of STM32 are 16 bits. That is to say, if you use a parallel port, although only 8 bits are used to transmit data together, the operation is still 16 bits together. Although there are 8 bits that are not used, they are still operated together when transmitting data, and the values ​​of the unused 8 bits will be overwritten together.

 #define DATAOUT(x) GPIOB->ODR=x; //Data output

As above, when the macro is called, the entire B port is operated together.


Method 1: ODR configuration method, you can directly use GPIO->ODR = value << N; to perform output operations on the corresponding IO port.
However, the hardware must ensure that:
1. The remaining IO ports on this function port (such as GPIOA) are not used as ordinary IO output ports
2. GPIO ports outside the rows and columns are either common IO input ports or function ports. Function ports are UART, USB, PWM, ADC, etc. When operating the ODR of GPIO, it will not affect the function port.
That is to say, for example, if the high 8 bits of port B are selected, then IO ports 8--15 are selected to drive TFT, but IO ports 0-7 cannot be used as ordinary output IO ports, but can be set as input, or UART, USB, PWM, ADC and other functions.
Method 2
The IO port can be operated individually by bit operation, but the data refresh speed is very slow.
void WriteData(u8 data)
{
   // Operate the IO ports connected to the LCD separately, the order is from high to low
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x80) >> 7 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x40) >> 6 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x20) >> 5 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x10) >> 4 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x08) >> 3 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x04) >> 2 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x02) >> 1 ); 
    GPIO_WriteBit(GPIO number, Pin number, data & 0x01);
 }
Using this method will not affect the bottom 8 bits, but the refresh speed will be very slow.


Keywords:STM32 Reference address:Some lessons on STM3216 IO port operation

Previous article:STM32---Understanding of GPIO circuit structure (output circuit)
Next article:STM32 IO operation (based on library functions)

Recommended ReadingLatest update time:2024-11-16 12:00

Things to note when using FPU in stm32
In addition to online tutorials, you should also pay special attention to adding an f after the number when there are floating-point numbers in the calculation. For example, 4.321 is involved in the calculation in the expression. When you do not add f after 4.321, the stm32F405 chip does not know whether it will be tr
[Microcontroller]
STM32-GPIO settings: quickly light up the first LED
Introduction The schematic diagrams of different development boards are different. Here, I use the Wildfire MINI-V3 (F103VET6) simple development board to briefly introduce the settings of the GPIO port and realize the key control of the LED light, so that readers can quickly become familiar with it and apply it flexi
[Microcontroller]
STM32-GPIO settings: quickly light up the first LED
STM32 serial port controls small lights with different brightness levels
Use the serial port input to control the brightness of the LED light, so as to achieve the function of interactive communication between the PC and the MAU This function consists of three parts: serial port communication, setting the brightness level of the LED light, and turning off the LED light by pressing a butt
[Microcontroller]
An easy-to-understand entry-level example of I2C for stm32
I bought a core board, which means I have my own STM32 board, so I also learned about I2C (because it is 24C02, hehe, it is more familiar). At the beginning, I wrote a read and write program according to the routine in the reference book, but there was no data output from the serial port when I downloaded the program
[Microcontroller]
An easy-to-understand entry-level example of I2C for stm32
STM32 startup process analysis
In the current embedded application development process, C language has become the best choice for most occasions. In this way, the main function seems to be the natural starting point - because C programs often start execution from the main function. But a question that is often overlooked is: how does the microcontr
[Microcontroller]
STM32 Learning: Internal Flash
When we develop applications, we often need to save some program running parameters, such as some correction coefficients. The characteristics of these data are: small in number and do not need to be modified frequently, but they cannot be defined as constants, because each device may be different and may be modified
[Microcontroller]
STM32 Learning: Internal Flash
STM32 controls 3 ultrasonic sensors
Use the STM32 timer input capture module to control 3-way ultrasonic sensors. The  ultrasonic sensor used this time is the common HC-SR04, which is often used in the obstacle avoidance system of small robots and smart cars.    In the above figure, 5v and GND provide power to the module, Trig is used to trigger the mo
[Microcontroller]
STM32 interrupt priority related concepts and usage notes
I. Basic Concepts 1. The ARM cortex_m3 core supports 256 interrupts (16 cores + 240 external) and programmable 256-level interrupt priority settings. The interrupt control and interrupt priority control registers (NVIC, SYSTICK, etc.) related to it also belong to the cortex_m3 core. STM32 uses the cortex_m3 core, so t
[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号