AVR 때는 자주 쓴거 같은데
stm32 되면서 함수를 통해 1개 핀에 대해서만 바꾸다 보니 불편해서 찾아보는데
머.. 결국은 레지스터 건드릴 수 밖에 없는 듯
ODR 값 읽고 마스킹 후에 한번에 갈아 치우는게 나을 듯
| If you want the whole port (all 16 pins) get the value, then you simply write it to the ODR register: GPIOB->ODR = 0xFFFF; //writing 1/0 in a bit position, sets/resets that bit. ALL BITS ARE AFFECTED no matter the value your write in. If you want to set some pins, but not altering the other pins, with one instruction: GPIOB->BSRR = 0x00F; //writing 1 in a bit position, sets that bit leaves the others as they are If you want to reset some pins, but not altering the other pins, with one instruction: GPIOB->BRR = 0x00F; //writing 1 in a bit position, clears that bit and leaves the others as they are If you want a "portion" of a GPIO port to get an specific value, this method is 2 instructions instead of "read-change-write": GPIOB->BRR = 0x00F; //clear the first 4 bits GPIOB->BSRR = 0x00A; //set the desired bits in that 4-bit field |
ODR 정도는 low level 함수로 존재하나 보다.
| using LL API: LL_GPIO_WriteOutputPort(GPIOA,x); |
| wtite_bits(uint16_t cmd) { uint32_t data = GPIOA -> ODR; data &= ~(0x1fff); data |= cmd & 0x1fff; GPIOA -> ODR = data; data = GPIOB -> ODR; data &= ~(0x0007); data |= (cmd & 0x8fff) >> 13; GPIOB -> ODR = data; } |
[링크 : https://stackoverflow.com/questions/48365156/stm32f4-write-read-16bits-into-two-8-bit-gpio-port]
'embeded > Cortex-M3 STM' 카테고리의 다른 글
| stm32 uart data bit (0) | 2026.03.17 |
|---|---|
| stm32 다른 영역으로 점프(부트로더) (0) | 2026.03.06 |
| stm32cubeide cpp 변환이후 generate code (0) | 2026.02.25 |
| mbed + stm32cube hal...? (0) | 2026.02.23 |
| Mbed studio on ubuntu 22.04 (0) | 2026.02.23 |
