cancel
Showing results for 
Search instead for 
Did you mean: 

Strange behavior on open-drain output mode for blue pill (STM32F103C8T6)

Luki_Grin
Visitor

Guys, I need to put 5V on a pin. For this, I configured my pin as an open-drain output with a pull-up resistor (10k) between the pin and the 5V line. I checked the 5V-tolerant pins in the Blue Pill datasheet and tested many of them, but the conclusion is always the same: the output is 3.7V when the pin is in high impedance. I used Keil uVision to write my code in C (at startup, I only used CMSIS and DEVICE for pre-configuration). My code is below. I used PB10 as a reference.

 

#include "stm32f10x.h"
 
int main(){
 
RCC->APB2ENR |= (1 << 3); // Clock for GPIOB
 
// Open-drain output and HIGH impedance PB10
GPIOB->CRH &= ~(0b1111 << 8); // Cleaning bits
GPIOB->CRH |= (0b0111 << 8); // Setting up bits
 
GPIOB->ODR |= (1 << 10); // HIGH impedance
 
};
 
Could you guys please tell me what I did wrong? 
5 REPLIES 5
TDK
Super User

Maybe the overwhelmingly likely counterfeit chip on the board doesn't have 5 V tolerant pins.

If you feel a post has answered your question, please click "Accept as Solution".
Peter BENSCH
ST Employee

You have (at least) made two mistakes:

  • You are using a so-called Blue Pill that has only been used with counterfeits for years (and you are asking for a solution for the counterfeit in the forum of the original manufacturer).

  • You are confusing 5V tolerance (of an input) with 5V capability of an output

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thanks for your comment! I didn't think it was a clone, as the debugger with STM32CubeIDE worked perfectly fine. However, after checking some IDs, I found very strange values, so it's probably fake =(

Thanks for the clarification, Peter. I'm new to the world of microcontrollers, and I'm diving into bare metal to understand how things really work. Didn't know there were clones. I will probably move to a NUCLEO one in the future (to avoid spending many hours on these bugs). 

"You are confusing 5V tolerance (of an input) with 5V capability of an output" --> Could you explain what you mean? I know the output voltage on a pin is normally 3.3V, but if I configure the output as open-drain (high impedance) and connect a pull-up resistor to it, I can get higher values of voltage, right? 

This depends on:

  • whether the specific GPIO has an alternative analogue function
  • and, as mentioned, whether it is an original or a counterfeit.

Details on GPIO behaviour can be found for the original device in the data sheet and in the Reference Manual RM0008.

Hope that helps?

Regard
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.