CodePudding user response:
Serial clock didn't open?CodePudding user response:
Serial clock didn't open? Communication does not specify the feet?In addition, STM32 has nothing to do with whether for 485, 485 can be a TTL directly turned 485, also can be 232 turn 485485 is only one and a half duplex middle tier, is viewed from the STM32 transparent
CodePudding user response:
USART parameter configuration, the configuration of the serial clock, GPIO clock, is unlikely to be the problemCodePudding user response:
Below is I came down from my STM32F407IG program interception USART1 configuration program, you comparevoid USART1_Configuration (void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1, ENABLE);//for USART1 and USART6
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_PinAFConfig (GPIOA, GPIO_PinSource9 GPIO_AF_USART1);
GPIO_PinAFConfig (GPIOA, GPIO_PinSource10 GPIO_AF_USART1);
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_10;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);
USART_InitStructure. USART_BaudRate=9600;
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_Cmd (USART1, ENABLE);
//CPU small defects: serial interface is configured, if Send directly, the first byte sent out the following statement solve the problem of the first byte cannot be sent out right
USART_ClearFlag (USART1, USART_FLAG_TC);//send Complete logo, Transmission Complete flag
USART_ITConfig (USART1, USART_IT_RXNE, ENABLE);
//////////////////////////////////////////////////////////////////
////USART_ITConfig (USART1, USART_IT_TXE, ENABLE);
////note: do not open here send interrupt
////send interrupts enabled in USART1_Begin_Send () function opens
//////////////////////////////////////////////////////////////////
}
CodePudding user response:
I used to send complete interrupt signal character, sending the first character in the main program, and then open to send complete interruption, and then continue to send the rest of the characters in the interrupt service routinevoid USART1_Begin_Send (void)
{
GPIO_USART1_RS485_SEND_enable ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
USART_ITConfig (USART1, USART_IT_TC, ENABLE);
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
__NOP ();
MB_USART1. SendPosi=0;
USART_SendData (USART1, MB_USART1 send_buffer [MB_USART1 sendPosi++]);
}
CodePudding user response:
Below is the interrupt service routinevoid USART1_IRQHandler (void)
{
Uint8_t ch;
If (USART_GetITStatus (USART1, USART_IT_RXNE)!=RESET)
{
USART_ClearITPendingBit (USART1, USART_IT_RXNE);
Ch=USART_ReceiveData (USART1);
If (MB_USART1 receCount & lt; MSCOMM_BUFFER_LENGTH)
MB_USART1. Mscomm_buffer [MB_USART1 receCount++]=ch;
The else
MB_USART1. ReceCount=0;
}
Else if (USART_GetITStatus (USART1, USART_IT_TC)!=RESET)
{
USART_ClearITPendingBit (USART1, USART_IT_TC);
If (MB_USART1 sendPosi & lt; MB_USART1. SendCount)
USART_SendData (USART1, MB_USART1 send_buffer [MB_USART1 sendPosi++]);
The else
{
GPIO_USART1_RS485_RECIVE_enable ();
USART_ITConfig (USART1, USART_IT_TC, DISABLE);
}
}
}
CodePudding user response:
Look at the printf functionCodePudding user response:
Is that didn't see you use printf process and definitions