I have a question about the IDR Register of STM32 I set the pin0 of the ODR Register to 1 in my code below and i want to check, if the pin0 in the IDR register is set to 1. The problem is, after setting the pin to 1, i musst wait 1 second until the pin in the IDR register is set to 1. How can i read the pin state without waiting. How can i handle this problem? ''' void init_pins(void) { GPIOG->OTYPER |= (0x01 << 0); // Pin 0 as open drain GPIOG->OTYPER &= ~(0x01 << 1); // Pin 1 as push - pull GPIOG->BSRRL = 0x01 << 1; // Pin 1 to High GPIOG->BSRRL = 0x01 << 0; // Pin 0 to High microsecond_Delay(1000000); if( !(GPIOG->IDR & 0x01) ) { errorCode = -1 ; //Error Code for Bus not floating } } '''
The datasheet/reference manual of (for instance) STM32F10x says about the IDR registers: "These bits are read only and can be accessed in Word mode only. They contain the input value of the corresponding I/O port." Maybe they can only be used if the pin is configured as input pin? That needs to be discussed.
Doran S. schrieb: > Maybe they can only be used if the pin is configured as input pin? No, those registers can be read without regarding the configuration of the pin. But here the author accesses them bytewide, which can lead to alignment trouble. Better read (and write) them as uint16_t (words) and the problem probably disappears.
Gast
#6080429
Your problem is possibly, that the Pin needs a while to change it's voltage level from low to high. You must wait a little, that is sure, but far less than a second. A lower Pull-Up resistor makes it faster.
Antwort schreiben
Bitte melde dich an, um einen Beitrag zu schreiben.