cancel
Showing results for 
Search instead for 
Did you mean: 

Read data in multiple GPIOx_IDR register / Combine GPIO Ports

SHong.5
Associate II

Hi

I'm currently using STM32H743 and I'm trying to Read Data in multiple GPIOx_IDR register

Previously, I was using 16 bits and trying to change into 32 bits for IDR.

When I debug, I could find correct data on SFRs -> Register -> GPIOA -> GPIO_IDR with below code.

previous code

main.h

#define my_data_Pin (0xFFFF) // Use all PA0-PA15 pins

#define my_data_GPIO_Port GPIOA

otherfile.c

void read_my_data(uint16_t *pbuf)

{

*pbuf++ = (uint16_t)my_data_GPIO_Port -> IDR;

}

Now, I'm not sure how to define the code for using all PA0-PA15 pins & PB0-PB15 pins for 32bit data.

 0693W000006E7baQAC.pngI've tried something like below, but it didn't work.

#define my_data_Pin (0xFFFF) && (0xFFFF)

#define my_data_GPIO_Port GPIOA && GPIOB

Could somebody help me out with this please?

Your help will be highly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
You can read 32 bits at the same time, but only from a single location. You can't read 16 bits from location A and another 16 bits from location B simultaneously.
BSRR always reads as 0, don't see how that would help anything here.
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

14 REPLIES 14
TDK
Guru

Since your array is of uint16_t, just do two operations:

*pbuf++ = GPIOA->IDR;
*pbuf++ = GPIOB->IDR;

The cast to (uint16_t) isn't hurting anything but it's not necessary.

This will require two operations. Trying to do something like GPIOA && GPIOB is nonsense.

If you feel a post has answered your question, please click "Accept as Solution".
SHong.5
Associate II

Thank you for your answer

I've tried that, but I want to make it happen simultaneously.

  1. *pbuf++ = GPIOA->IDR;
  2. *pbuf++ = GPIOB->IDR;

#2 is always late than #1.

Currently, I'm using uint32_t instead of uint16_t.

Thank you for your answer

I've tried that, but I want to make it happen simultaneously.

  1. *pbuf++ = GPIOA->IDR;
  2. *pbuf++ = GPIOB->IDR;

#2 is always late than #1.

Currently, I'm using uint32_t instead of uint16_t.

TDK
Guru

You can't do them at the same time. The CPU only does one instruction at a time. You could combine them into the same C statement, but it still won't occur at the same time.

*pbuf++ = (GPIOA->IDR << 16) + GPIOB->IDR;

If you feel a post has answered your question, please click "Accept as Solution".

oh... thank you so much for your help.

seems like reading 32bit data at the same time is impossible for STM32H7.

I'm trying BSRR instead of IDR to try 32 bit. However, the data only comes in through IDR register.

You can read 32 bits at the same time, but only from a single location. You can't read 16 bits from location A and another 16 bits from location B simultaneously.
BSRR always reads as 0, don't see how that would help anything here.
If you feel a post has answered your question, please click "Accept as Solution".

Every GPIO Pins have 16 pins as maximum.

  • PA00 - PA15
  • PB00 - PB15
  • ...
  • PG00 - PG15

What do you mean, reading 32 bits at the same time is possible?

Do you mean, use only a single pin, instead of 32 pins?

Thanks

> What do you mean, reading 32 bits at the same time is possible?

You can read 32 bits at the same time, but you cannot read 32 pin states at the same time, since those bits are not contiguous.

If you feel a post has answered your question, please click "Accept as Solution".

Well... I was sending data from other devices to MCU via 16 pins at the same time.

ex) 0000 0000 0000 0101

Then, when I debug, I could read the value 0x101 from below.

SFRs -> Register -> GPIOA -> GPIO_IDR

This kind of process wouldn't be possible for 32 pins, right?