cancel
Showing results for 
Search instead for 
Did you mean: 

A stupid question about GPIO input mode

randyao12345
Associate II
Posted on June 07, 2014 at 00:56

Hi ST,

I'm using ST32F4Discovery board, and I want to read a 4 bit data that is continuously streaming in. I'm thinking of doing:

1. set GPIO port for the input (say PA10)

2. call this function to read data: GPIO_ReadInputDataBit(GPIOA, GPIO_PIN_10)

Would this work?

Also, i just wanted to ask how can you even use the function GPIO_ReadInputData (in the GPIO library) if it has no pin# as input parameter?

uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);

Also, is there a way to do this in DMA mode? read input 4-bit data and go straight into memory.
1 REPLY 1
Posted on June 07, 2014 at 01:22

GPIOx->IDR reads all 16 pins in the bank as a 16-bit variable, you can shift and mask multiple pins from that.

Say 4-bits at PC10,11,12,13

data = (GPIOC->IDR >> 10) & 0x0F;

Yes, you can use DMA, and have DMA clocked via a TIM, or an external clock routed through a TIM. You can DMA in or out. I've posted several examples, and it has been discussed in a couple of threads.

You can just to 4-bit, you basically get to read 16-bit and then post process the data to extract those of interest to you. For DMA out, basically I think 8-bit or 16-bit at byte/word boundaries is viable. Say you wanted to pump PCM audio data to a resistor chain/ladder DAC
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..