AnsweredAssumed Answered

STM32F103CB PB8 as input problem

Question asked by Sam Wang on Jun 15, 2017
Latest reply on Jun 23, 2017 by Sam Wang

Hi,

I encountered a problem with STM32F103CB when setting PB8 as pull-up input.

In hardware, PB8 is externally pulled up to 3.3V. And it is set as pull-up input. However, after MCU start, it is being detected as low continuously (By reading GPIOB->IDR). At this point, whenever this pin is grounded externally, this unable-to-detect-level-high issue will disappear. 

 

I have also test PB5 to PB9, same setting but only PB8 experiences this problem. 

 

One other weird thing is that if I set PB8 as open-drain output low before setting it as pull-up input. The issue will disappear.

 

This issue does not appear in every chip. Actually it appear in a low quantity of chips. But the error on PB8 is consistent among the failing chips. Any idea on what could go wrong?

Thanks!

 

--------------------Update-----------------------------

Here is the test code:

 

int i;
GPIO_TypeDef a;
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
GPIOB->BSRR = (0x1 << 8);
GPIOB->CRH &= ~(0xF << 0);
GPIOB->CRH |= (0x8 << 0);


while (1) {
    a = *GPIOB;
    i = GPIOB->IDR;
}

 

That's every thing in the main function. In debug mode, when I stop at "a = *GPIOB", below is the variable watch in Keil.

 

Outcomes