Home > other >  STM32 USART sending and receiving, please big pigeons, small JieJie grant instruction!
STM32 USART sending and receiving, please big pigeons, small JieJie grant instruction!

Time:09-24

Pure white issued please save...

Problem: a serial port to send less than, configuration has a lot of mistakes? Please grant instruction!!!!!
I saw her to write the code, I want to smile
 


C programs] [test.
# include "bsp_text. H"

Void RCC_Configuration (void)
{
//GPIO? ¢USARTe plus or minus? Oe1? U
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2, ENABLE);
}

Void GPIO_Configuration (void)
{

GPIO_InitTypeDef GPIO_InitStructure;


GPIO_InitStructure. GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_13;
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init (GPIOC, & amp; GPIO_InitStructure);

GPIO_SetBits (GPIOC, GPIO_Pin_13);
}

Void USART_Configuration (void)
{

USART_InitTypeDef USART2_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;


GPIO_InitStructure. GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);


GPIO_InitStructure. GPIO_Pin=GPIO_Pin_3;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);


USART2_InitStructure. USART_BaudRate=115200;
USART2_InitStructure. USART_WordLength=USART_WordLength_8b;
USART2_InitStructure. USART_StopBits=USART_StopBits_1;
USART2_InitStructure. USART_Parity=USART_Parity_No;
USART2_InitStructure. USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART2_InitStructure. USART_Mode=USART_Mode_Tx | USART_Mode_Tx;
USART_Init (USART2, & amp; USART2_InitStructure);

USART_ITConfig (USART2, USART_IT_RXNE, ENABLE);
USART_Cmd (USART2, ENABLE);
}

Void NVIC_Configuration (void)
{
NVIC_InitTypeDef NVIC_InitStructure;

NVIC_PriorityGroupConfig (NVIC_PriorityGroup_0);

NVIC_InitStructure. NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;

NVIC_Init (& amp; NVIC_InitStructure);
}

[main. C program]
# include "stm32f10x. H"
# include "bsp_text. H"
# include "stdio.h"

Void GpuSend buf1 (char *);
Void USART2_Init (void);
Void NVIC_Configuration (void);

Int fputc (int ch, FILE * f)
{
USART_SendData (USART2, (unsigned char) ch);
While (USART_GetFlagStatus (USART2, USART_FLAG_TC)!=SET);
Return (ch);
}

Void USART_SendChar (USART_TypeDef * pUSARTx uint8_t c)
{
USART_SendData (pUSARTx, c);
While (USART_GetFlagStatus (pUSARTx USART_FLAG_TXE)==RESET);
}

Void USART_SendString (USART_TypeDef * pUSARTx, char * STR)
{
Uint32_t n=0;

While (* (STR + n)!='\ 0')
{
USART_SendChar (pUSARTx, * (STR + n));
N++;
}
While (USART_GetFlagStatus (pUSARTx USART_FLAG_TXE)==RESET);
}


Int main ()
{
NVIC_Configuration ();

Printf (" 110-119-120 ");

While (1) {}

}

[test. H program]
# # ifndef _GPIO_H
# define _GPIO_H

# include "stm32f10x. H"


# endif
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Copyright statement: this article to CSDN blogger ((pure does small white)) of the original articles, follow BY CC 4.0 - SA the copyright agreement, reproduced and this statement, please attach the original source link
The original link: https://blog.csdn.net/weixin_45454723/article/details/103541931
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Copyright statement: this article to CSDN blogger ((pure does small white)) of the original articles, follow BY CC 4.0 - SA the copyright agreement, reproduced and this statement, please attach the original source link
The original link: https://blog.csdn.net/weixin_45454723/article/details/103541931

CodePudding user response:

You are in the main () does not initialize serial port, serial port will not work, of course,

CodePudding user response:

C
in mian.{
USART2_InitStructure ();
GPIO_InitStructure ();
.
.
}

To initialize the first two? There are other to initialize?

CodePudding user response:

This kind of thing many routines, find a first to learning how to learn,

CodePudding user response:

Routine sense
But some disruption, system timer, or don't understand the

CodePudding user response:

Didn't see your writing difficulty bigger, or step by step, first see,

CodePudding user response:

Ok, thank you for @ xuyaqi029
Are you a man?
  • Related