2017-06-15 03:14 AM
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.
#stm32f103cb #gpio #input2017-06-15 06:07 AM
You may share your code of gpio initialization.
Did you turn on GPIOB CLK?
2017-06-15 08:51 AM
>>
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?
2017-06-15 09:57 PM
Liu.Zhitai
Yes, I turned on GPIOB clk. Please have a look at the update on the post for the code. Thanks!2017-06-15 10:04 PM
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.
2017-06-22 10:45 PM
Anyone have any idea on this?