Home > other >  Why the F4 USART6 cannot print data on the serial port assistant (serial assistants have no reaction
Why the F4 USART6 cannot print data on the serial port assistant (serial assistants have no reaction

Time:11-22

If # 1
# pragma import (__use_no_semihosting)
//the standard library needs the support of function
Struct __FILE
{
Int handle;
};

The FILE __stdout;
//define _sys_exit () to avoid using half a host mode
Void _sys_exit (int x)
{
X=x;
}
//redefine fputc function
Int fputc (int ch, FILE * f)
{
While ((USART6 - & gt; SR& 0 x40)==0);//cycle to send, until completion of the send
USART6 - & gt; DR=(u8) ch;
return ch;
}
# endif

Void uart6_init (u32 bound)
{
//set the GPIO port
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOG, ENABLE);//can make GPIOG clock
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART6, ENABLE);//can make USART6 clock

//a serial port 6 corresponding pins reuse mapping
GPIO_PinAFConfig (GPIOG, GPIO_PinSource9 GPIO_AF_USART6);//GPIOG9 reuse for USART6
GPIO_PinAFConfig (GPIOG, GPIO_PinSource14 GPIO_AF_USART6);//GPIOG14 reuse for USART6

//USART6 port configuration
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_9 | GPIO_Pin_14;//GPIOG9 GPIOG14
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF;//multiplexing function
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;//speed 50 MHZ
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;//push-pull multiplexing output
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_UP;//pull
GPIO_Init (GPIOG, & amp; GPIO_InitStructure);//initialize

//USART6 initialization setting
USART_InitStructure. USART_BaudRate=bound;//baud rate setting
USART_InitStructure. USART_WordLength=USART_WordLength_8b;//word length of 8 bits of data format
USART_InitStructure. USART_StopBits=USART_StopBits_1;//a stop bit
USART_InitStructure. USART_Parity=USART_Parity_No;//and white parity bit
USART_InitStructure. USART_HardwareFlowControl=USART_HardwareFlowControl_None;//no hardware flow control
USART_InitStructure. USART_Mode=USART_Mode_Rx | USART_Mode_Tx;//transceiver model
USART_Init (USART6, & amp; USART_InitStructure);//initialize a serial port 6

USART_Cmd (USART6, ENABLE);//can make a serial port 6

USART_ClearFlag (USART6 USART_FLAG_TC);

USART_ITConfig (USART6, USART_IT_RXNE, ENABLE);//open the relevant interrupt

//Usart6 NVIC configuration
NVIC_InitStructure. NVIC_IRQChannel=USART6_IRQn;//a serial port 6 interrupt channel
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=3;//take priority 3
NVIC_InitStructure. NVIC_IRQChannelSubPriority=2;//child priority 2
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;//IRQ channel can make
NVIC_Init (& amp; NVIC_InitStructure);//initializes the NVIC register according to the specified parameters
}


Void USART6_IRQHandler (void)//a serial port 6 interrupt service routines
{
U8 Res;

If (USART_GetITStatus (USART6, USART_IT_RXNE)!=RESET)//receiving interrupt
{
Res=USART_ReceiveData (USART6);//(USART1 - & gt; DR);//read the received data
}
}

CodePudding user response:

How much bound, wrong pin? If you have other initialization code, first shielding

CodePudding user response:

The find the problem, thanks, I will pick up the serial port connection 1

CodePudding user response:

Sometimes to confirm this small mistake easily
  • Related