The reason why the buzzer of the embedded blue bridge cup cannot be turned off

**

The reason why the buzzer of the embedded blue bridge cup cannot be turned off

**

Preface

First we see the pin of the buzzer

Insert picture description here
There are two ways to deal with IO ports.
One is IO port multiplexing, which
has other functions besides the first function of IO port. The other
is port remapping,
which redefines the attributes of IO port.
Unfortunately, our buzzer is set to second. kind
so we have to close the JNTRST then open the SWJ

	GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST,ENABLE);

Be careful not to write this out by mistake, otherwise you will have to press the reset button every time you download

GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);

Their positional relationship is correct on the left and easily misunderstood on the right

Reasons why the buzzer cannot be turned off

The reason why it can't be turned off is that the multiplexed clock is turned on and the multiplexed
push-pull output
is used. If the multiplexed push-pull output is used, it is
always low level and always beeping.
Why not always high level and not beeping?
It’s amazing.
Interested friends can Try it yourself
Error code

void BEEP_Init(void)
{
    
    
  GPIO_InitTypeDef GPIO_InitStruct;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
	GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST,ENABLE);
	GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
	GPIO_InitStruct.GPIO_Pin=GPIO_Pin_4;
	GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
	GPIO_Init(GPIOB,&GPIO_InitStruct);

}

Correct code

void BEEP_Init(void)
{
    
    
  GPIO_InitTypeDef GPIO_InitStruct;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

	GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST,ENABLE);
	GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
	GPIO_InitStruct.GPIO_Pin=GPIO_Pin_4;
	GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
	GPIO_Init(GPIOB,&GPIO_InitStruct);

}

Guess you like

Origin blog.csdn.net/m0_46179894/article/details/108335701