What is the exact procedure to set up the STM32L496 device so that the IDR will output the input of a pin?
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???
