Home > other >  Only start the program can enter STM32f030C8T6 serial port
Only start the program can enter STM32f030C8T6 serial port

Time:10-02

Using STM32f030C8T6 serial port programming, there was a problem, is the program will enter a start receiving interrupt function, and then back into not to go, this might be the reason why, ask bosses guidance

CodePudding user response:

Used f0 series,
1: do you want to clear the interrupt flag
2: is it dead 偱 ring in the interrupt
3: the interrupt processing, whether fail interrupt

CodePudding user response:

The building should be a piece of code, interrupt service function, otherwise you how to find problems

CodePudding user response:

Look a breakpoint,
I think there is a possible your clock is slow, and then into a serial port, the data has been spread out lost,

CodePudding user response:

//clock
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1, ENABLE);
//GPIO initialization
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure. GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure. GPIO_PuPd=GPIO_PuPd_UP;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);
GPIO_PinAFConfig (GPIOA, GPIO_PinSource9 GPIO_AF_1);
GPIO_PinAFConfig (GPIOA, GPIO_PinSource10 GPIO_AF_1);
//serial port initialization
USART_InitStructure. USART_BaudRate=19200;
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);
USART_Cmd (USART1, ENABLE);
//a serial port interrupt configuration
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure. NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPriority=2;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);
A serial port interrupt
Void USART1_IRQHandler (void)
{
USART_ITConfig (USART1, USART_IT_RXNE, DISABLE);
If (USART_GetFlagStatus (USART1, USART_FLAG_RXNE)==SET)
{
USART_ClearITPendingBit (USART1, USART_IT_RXNE);

USART_ITConfig (USART1, USART_IT_RXNE, ENABLE);
}

}
Stm32f0x to use

CodePudding user response:

Check terminal processing program

CodePudding user response:

Void NVIC_Configuration (void)
{
NVIC_InitTypeDef NVIC_InitStructure;



NVIC_PriorityGroupConfig (NVIC_PriorityGroup_4);//nested priority grouped into 4, note: the default priority=15 SysTick

NVIC_InitStructure. NVIC_IRQChannel=USART2_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=7;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);

}

CodePudding user response:

Of STM32F103 USART2 serial

Void USART2_Configuration (void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;


//config USART2 clock
RCC_APB1PeriphClockCmd (RCC_APB1Periph_USART2, ENABLE);
//Configure USART2 Tx (PA. 2) as the alternate function of push - pull
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); 2
//PA.//Configure USART2 Rx (PA. 3) as input floating
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_3;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure); 3
//PA.//USART2 mode config
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 (USART2, & amp; USART_InitStructure);


//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 (USART2, USART_FLAG_TC);//send Complete logo, Transmission Complete flag
USART_ITConfig (USART2, USART_IT_RXNE, ENABLE);
USART_Cmd (USART2, ENABLE);
}


CodePudding user response:

Void USART2_IRQHandler (void)
{
Uint8_t ch;


If (USART_GetITStatus (USART2, USART_IT_RXNE)!=RESET)
{
USART_ClearITPendingBit (USART2, USART_IT_RXNE);
Ch=USART_ReceiveData (USART2);
}

Else if (USART_GetITStatus (USART2, USART_IT_TC)!=RESET)
{
USART_ClearFlag (USART2, USART_FLAG_TC);
If (MB_USART2 sendPosi & lt; MB_USART2. SendCount)
{
USART_SendData (USART2, MB_USART2 send_buffer [MB_USART2 sendPosi++]);
}
The else
{
USART2_RS485_RECIVE_enable ();
USART_ITConfig (USART2, USART_IT_TC, DISABLE);
}
}
null
  • Related