cancel
Showing results for 
Search instead for 
Did you mean: 

Parallel output of 8bits

pchala
Associate II
Posted on October 04, 2013 at 11:13

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?

#gpio
3 REPLIES 3
Posted on October 04, 2013 at 11:30

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pchala
Associate II
Posted on October 04, 2013 at 14:52

What about

(*(__IO uint8_t *)((uint32_t)&(GPIOA->ODR))) = command;

?

Posted on October 04, 2013 at 15:01

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