cancel
Showing results for 
Search instead for 
Did you mean: 

What is the exact procedure to set up the STM32L496 device so that the IDR will output the input of a pin?

RoKsPy
Associate II

Currently, it seems that the IDR of any port updates only when the IO is configured as an output and does not record the state when the IO is configured as an input.

Here is two examples of simple code for each situation

1) Both PC2 and PC15 is set as output. LED(PC15) does light up if PC2 is set high

int main(void){

   RCC->AHB2ENR |= BIT2;            // Enable clock for the PORTC

   GPIOC->MODER &= ~BIT31;         // Configure the PC15 as an output (LED pin)

   GPIOC->MODER &= ~BIT5;

   GPIOC->ODR |= BIT2;

   // PC2 is an input, which should be recorded as high in the IDR register

   while(1){

      if(GPIOC->IDR & BIT2) GPIOC->ODR |= BIT15;

   }

   return 0;

}

2) PC2 is set as input, PC15 set as output. LED(PC15) does not light up even if the level on the PC2 is high (hooked wire to between supply voltage and the test point connected to the PC2).

int main(void){

   RCC->AHB2ENR |= BIT2;            // Enable clock for the PORTC

   GPIOC->MODER &= ~BIT31;         // Configure the PC15 as an output (LED pin)

   // PC2 is an input, which should be recorded as high in the IDR register

   while(1){

      if(GPIOC->IDR & BIT2) GPIOC->ODR |= BIT15;

   }

   return 0;

}

Is there anything else necessary to set up the IDR for detecting the state of input pin???

2 REPLIES 2
TDK
Guru

IDR should always reflect the state of the input, unless you're in analog mode. It's possible your PC2 pad isn't connected to what you think it is.

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

Okay... yeah, the device was in the analog mode and not the input... For further reference, the fix is changing MODER from 11 to 00, which I did not do...

Thanks!