Skip to main content
pchala
Associate II
October 4, 2013
Question

Parallel output of 8bits

  • October 4, 2013
  • 3 replies
  • 804 views
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
This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
October 4, 2013
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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
pchala
pchalaAuthor
Associate II
October 4, 2013
Posted on October 04, 2013 at 14:52

What about

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

?

waclawek.jan
Super User
October 4, 2013
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