Home > other >  STM32 serial port, it will only send, not receiving
STM32 serial port, it will only send, not receiving

Time:12-01

 void USART1_IRQHandler (void) 
{
Unsigned char RxData;
If (USART_GetITStatus (USART1, USART_IT_RXNE)!=RESET)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
RxData=https://bbs.csdn.net/topics/USART_ReceiveData (USART1);
RxData=https://bbs.csdn.net/topics/RxData + 1;
USART_SendData (USART1, RxData);
}

}


Program to send out, is to interrupt receiving, receiving less than
Trouble will be the eldest brother have a look at what the devil is written

CodePudding user response:

Initialization function?

CodePudding user response:

 
# include "stm32f10x. H"
# include "stdio.h"

Void USART1_Config (void);
Void Usart1_SendBye (under-16 Bye);
Void Usart1_SendMoreBye (under-16 Bye, under-16 Len);
Void Usart1_SendString buf1 (char *);
Void Usart1_SendHalfWord uint16_t (ch);
Void Usart1_IRQHandler (void);

This?

CodePudding user response:

Uart_init function, while statement before, what did you call?

CodePudding user response:

 
# include "Usart. H"

Void USART1_Config ()
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);

GPIO_InitStructure. GPIO_Pin=GPIO_Pin_9;//TX
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_10;//RX
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

NVIC_InitStructure. NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=1;
NVIC_Init (& amp; NVIC_InitStructure);

USART_InitStructure. USART_BaudRate=115200;
USART_InitStructure. USART_WordLength=USART_WordLength_8b;
USART_InitStructure. USART_StopBits=USART_StopBits_1;
USART_InitStructure. USART_Parity=USART_Parity_No;
USART_InitStructure. USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure. USART_Mode=USART_Mode_Rx | USART_Mode_Tx;
USART_Init (USART1, & amp; USART_InitStructure);
USART_ITConfig (USART1, USART_IT_RXNE, ENABLE);//e1? U? Oe?? D??
USART_Cmd (USART1, ENABLE);
}

//USART1 SEND A BYE
Void Usart1_SendBye (under-16 Bye)
{
USART_SendData (USART1, Bye);//USART1 ¢? IO??? X?? U
While (USART_GetFlagStatus (USART1, USART_FLAG_TXE)==RESET);//? I2aUSART1e? Who? · ¢? Iie plus or minus?
}

//USART1 SEND MORE BYE
Void Usart1_SendMoreBye (under-16 Bye, under-16 Len)
{
Int count;
For (count=0; Count{
Usart1_SendBye (Bye);
}
While (USART_GetFlagStatus (USART2, USART_FLAG_TC)==RESET);
}

Void Usart1_SendString (char * buf1)
{
U8 I=0;
While (1)
{if (buf1 [I]!=0)
{USART_SendData (USART1, buf1 [I]);
While (USART_GetFlagStatus (USART1, USART_FLAG_TXE)==RESET) {};
i++;
}
The else return;
}
}

Void Usart1_SendHalfWord uint16_t (ch)
{
Uint8_t temp_h temp_l;

/* e? 3??????? °??? */
Temp_h=(ch& 0 xff00) & gt;> 8;
/* e? 3? Mu I °??? */
Temp_l=ch& 0 XFF.

/* ¢? I?? °??? */
USART_SendData (USART2, temp_h);
While (USART_GetFlagStatus (USART2, USART_FLAG_TXE)==RESET);

/* ¢? I mu I °??? */
USART_SendData (USART2, temp_l);
While (USART_GetFlagStatus (USART2, USART_FLAG_TXE)==RESET);
}

Void Usart1_IRQHandler ()
{unsigned char RxData;
If (USART_GetITStatus (USART1, USART_IT_RXNE)!=RESET)
{
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
RxData=https://bbs.csdn.net/topics/USART_ReceiveData (USART1);
RxData=https://bbs.csdn.net/topics/RxData + 1;
USART_SendData (USART1, RxData);
}
} [code]=c # include "delay. H
"# include "Usart. H"

Int main (void)
{
Delay_Config ();
USART1_Config ();
USART2_Config ();

The Output of ok on Usart1_SendString ("? \n");
Delay_ms (9000);
Usart1_SendString (" Output Over on? \n");
While (1)
{

}
[/code]}


So the

CodePudding user response:

1, AF clock you should be opened elsewhere
2, USART_ClearITPendingBit (USART1, USART_IT_RXNE); This sentence does not need to, call USART_ReceiveData (USART1); Automatically remove
3, in the routines to remember is that while there is no need to changed to the if
4, USART_SendData (USART1, RxData); Don't use this kind of thing from the receiving interrupt, write a flags such as: flag=true; In the main while judging marks a
If (flag) {
flag=false;
USART_SendData (USART1, RxData);
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related