2013-10-04 02:13 AM
I have found working solution. But for me it look ugly.
uint8_t
command
=
0x55
;
uint16_t
u16Temp
=
0
;
u16Temp
=
GPIO_ReadOutputData
(
GPIOA
)&
0xFF00
;
u16Temp
|=
command
;
GPIO_Write
(
GPIOA
,
u16Temp
);
Is there better way to output 8bit value to PORTA without affecting other pins?
#gpio2013-10-04 02:30 AM
Something along the lines of the following, depending on STM32 series in question
GPIOA->BSRR = Data | ((~Data << 16) & 0xFF0000); or *((uint32_t *)&GPIOA->BSRRL) = (uint32_t)Data | ((~(uint32_t)Data & 0xFF) << 16); This uses the atomic Bit Set Reset Register, writing the Data pattern to the Set Portion, and the logical inverse to the Reset Portion.2013-10-04 05:52 AM
What about
(*(__IO uint8_t *)((uint32_t)&(GPIOA->ODR))) = command; ?2013-10-04 06:01 AM
According to the RM, some models allow bytewise access to GPIO registers, including GPIOx_ODR. Others (e.g. the STM32F1xx) don't.
I never tried, though. JW