cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103CB PB8 as input problem

Sam Wang
Associate II
Posted on June 15, 2017 at 12:14

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.

0690X00000607NLQAY.png

#stm32f103cb #gpio #input
5 REPLIES 5
Zt Liu
Senior III
Posted on June 15, 2017 at 15:07

You may share your code of gpio initialization.

Did you turn on GPIOB CLK?

Posted on June 15, 2017 at 17:51

>>

Any idea on what could go wrong?

What else is going on with PB8 in your design?

Are grounds always common? Is there a chance for high potential difference on the pins vs ground?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 16, 2017 at 04:57

Liu.Zhitai

‌ Yes, I turned on GPIOB clk. Please have a look at the update on the post for the code. Thanks!

Posted on June 16, 2017 at 05:04

May I know what do you mean by high potential difference on the pins vs ground? PB8 is externally pulled up to 3.3V with a 4.7kohm resistor. Tested the pin with oscilloscope, it stays at 3.3V on startup.

Sam Wang
Associate II
Posted on June 23, 2017 at 07:45

Anyone have any idea on this?