Debugging method of Usart2 serial port of STM32 microcontroller

First refer to http://wenku.baidu.com/view/78f6b1350b4c2e3f572763e9.html to tune usart1

Then modify the program and configure Usart2. After the configuration is completed, the program is still not correct, and then add a sentence to the voidGPIO_cfg(); function

GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);

The final procedure is as follows,

#include "stm32f10x_lib.h"

FlagStatusRX_status;

FlagStatusTx_status;

voidRCC_cfg(void);

voidGPIO_cfg(void);

voidUSART_cfg(void);

voidNVIC_cfg(void);

unsignedcharRxbuf[20];

inTIndex_send, index_rev;

u8flag;

intmain()

{

inTI;

unsignedcharTxBuf1[] = "WelcometomySTM32! I'midiot!";

index_send=0;

index_rev=0;

flag=0;

RCC_cfg();

GPIO_cfg();

NVIC_cfg();

USART_cfg();

//Clear the flag, otherwise the first bit of data will be lost

USART_ClearFlag(USART2, USART_FLAG_TC);

//send data

//The role of PB5 is to show that data is being sent

//When there is data being sent, PB5 will light up

for(i=0;TxBuf1[i]!='\0';i++)

{

USART_SendData(USART2, TxBuf1[i]);

GPIO_SetBits(GPIOB, GPIO_Pin_5);

//Wait for the data to be sent

while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);

GPIO_ResetBits(GPIOB, GPIO_Pin_5);

}

while(1)

{

}

}

//RCC clock configuration

voidRCC_cfg()

{

// reset the RCC register to its default value

RCC_DeInit();

//Open GPIO clock, multiplex function, serial port 1 clock

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

}

//IO port configuration

voidGPIO_cfg()

{

GPIO_InitTypeDefGPIO_InitStructure;

//PAD5 as the TX end of US2, open multiplexing, responsible for sending data

GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);

GPIO_StrucTInit(&GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;

GPIO_Init(GPIOD, &GPIO_InitStructure);

//PD6, as the RX end of US2, is responsible for receiving data

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOD, &GPIO_InitStructure);

//LED shows the serial port is sending/receiving data

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

GPIO_Init(GPIOB, &GPIO_InitStructure);

}

// serial port initialization

voidUSART_cfg()

{

USART_InitTypeDefUSART_InitStructure;

//Set the structure to the default state

USART_StructInit(&USART_InitStructure);

//The baud rate is set to 115200

USART_InitStructure.USART_BaudRate=115200;

//The width of a frame of data is set to 8bits

USART_InitStructure.USART_WordLength=USART_WordLength_8b;

//Transmit 1 stop bit at the end of the frame

USART_InitStructure.USART_StopBits=USART_StopBits_1;

//Parity disabled mode, no parity check

USART_InitStructure.USART_Parity=USART_Parity_No;

// send/receive enable

USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;

//Hardware flow control disabled

USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;

//Set serial port 2

USART_Init(USART2, &USART_InitStructure);

//Open the interrupt response function of serial port 2 and receive the interrupt

USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

//Open serial port 2

USART_Cmd(USART2, ENABLE);

}

// configure interrupt

voidNVIC_cfg()

{

NVIC_InitTypeDefNVIC_InitStructure;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//Select interrupt group 2

NVIC_InitStructur

Maskking Vape

The utility model provides a disposable electronic cigarette, comprising: a hollow shell, the bottom of the shell is provided with a lower cover; the shell contains an atomizer, and the outer side of the atomizer is sheathed with a disposable cigarette A bomb, a microphone cover is arranged under the atomizer, a microphone is covered under the microphone cover, a battery is arranged on one side of the atomizer, and an upper cover is arranged on the top of the casing; The atomizer includes an atomizing core, an oil-absorbing cotton sleeved on the outside of the atomizing core, and an atomizer outer tube sleeved on the outside of the oil-absorbing cotton. The disposable electronic cigarette provided by the utility model absorbs the smoke oil on the surface through the absorbing cotton, and then atomizes the smoke through the atomizing core, which greatly reduces the risk of oil leakage, at the same time, reduces the burning of cotton and ensures the smoking taste.The utility model provides a disposable electronic cigarette, comprising: a hollow shell, the bottom of the shell is provided with a lower cover; the shell contains an atomizer, and the outer side of the atomizer is sheathed with a disposable cigarette A bomb, a microphone cover is arranged under the atomizer, a microphone is covered under the microphone cover, a battery is arranged on one side of the atomizer, and an upper cover is arranged on the top of the casing; The atomizer includes an atomizing core, an oil-absorbing cotton sleeved on the outside of the atomizing core, and an atomizer outer tube sleeved on the outside of the oil-absorbing cotton. The disposable electronic cigarette provided by the utility model absorbs the smoke oil on the surface through the absorbing cotton, and then atomizes the smoke through the atomizing core, which greatly reduces the risk of oil leakage, at the same time, reduces the burning of cotton and ensures the smoking taste.The utility model provides a disposable electronic cigarette, comprising: a hollow shell, the bottom of the shell is provided with a lower cover; the shell contains an atomizer, and the outer side of the atomizer is sheathed with a disposable cigarette A bomb, a microphone cover is arranged under the atomizer, a microphone is covered under the microphone cover, a battery is arranged on one side of the atomizer, and an upper cover is arranged on the top of the casing; The atomizer includes an atomizing core, an oil-absorbing cotton sleeved on the outside of the atomizing core, and an atomizer outer tube sleeved on the outside of the oil-absorbing cotton. The disposable electronic cigarette provided by the utility model absorbs the smoke oil on the surface through the absorbing cotton, and then atomizes the smoke through the atomizing core, which greatly reduces the risk of oil leakage, at the same time, reduces the burning of cotton and ensures the smoking taste.

maskking vape,maskking vape price,maskking vape review,maskking vape shop,,maskking vape cost,maskking vape disposable,maskking vape informacion

Suizhou simi intelligent technology development co., LTD , https://www.msmsmart.com

This entry was posted in on