Differences between STM32 library functions GPIO_SetBits, GPIO_ResetBits, GPIO_WriteBit, and GPIO_Write

Question: When I use the STM32 library function to assign a value to the I/O port, I find four related functions in the header file that can do this operation. So what are the differences between them?

1. GPIO_SetBits

GPIO_SetBits

//eg:
GPIO_SetBits(GPIOA, GPIO_Pin_1 | GPIO_Pin_2);

Explanation: Set (set to 1) the selected data port bit, you can select multiple bits of the same port

2.GPIO_ResetBits

GPIO_ResetBits

//eg:
GPIO_ResetBits(GPIOA, GPIO_Pin_1 | GPIO_Pin_2);

Explanation: Reset (set to 0) the selected data port bit. You can select multiple bits of the same port.

3. GPIO_WriteBit

GPIO_WriteBit

//eg:
GPIO_WriteBit(GPIOA, GPIO_Pin_1 | GPIO_Pin_2, BIT_SET);

Explanation: Write port bits, support BIT_SET/BIT_RESET, write 1 or write 0, you can select multiple bits of the same port

四、GPIO_Write

GPIO_Write

//eg:
GPIO_Write(GPIOA, 0XFFFF);

Explanation: Directly write to the entire port, 0XFFFF means writing all 16 bits to 1

5. Summary:

function illustrate
GPIO_SetBits Set IO, that is, pull the IO port high to 1
GPIO_ResetBits Reset the IO, that is, pull the IO port low to 0
GPIO_WriteBit When writing to IO, you can only customize settings to write 0 or 1, both 0 or both 1.
GPIO_Write Write operation to the entire IO port, 0xFFFF corresponding to 0-15 PIN is set to 1; 0x0000 is set to 0

Guess you like

Origin blog.csdn.net/only_a_Heroic_car/article/details/130067196