Forum: Mikrocontroller und Digitale Elektronik How to speed update time of IDR Register STM32?


von Amadou B. (amadu)


Lesenswert?

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
}
} '''

von Doran S. (utzer)


Lesenswert?

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.

: Bearbeitet durch User
von Matthias S. (Firma: matzetronics) (mschoeldgen)


Lesenswert?

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.

von Stefan F. (Gast)


Lesenswert?

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.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.