cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103VCT6,Serial port 1 interrupts, and simultaneously outputs data in serial port 1 and serial port 2. Serial port 1 stops sending after just a few frames of data are output, while serial port 2 still has data output.Is there a solution?

一李.1
Associate II

In the interrupt of serial port 1, data is output in both serial port 1 and serial port 2. Serial port 1 first sends data, then serial port 2 sends data. After serial port 1 outputs a few frames of data at the beginning, there is no data output, while serial port 2 still has data output。

The two serial port functions are as follows

 USART1_Config(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

USART_InitTypeDef USART_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE); //

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

//USART1_TX  GPIOA.9

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure); //GPIOA.9

//USART1_RX  GPIOA.10

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PA10

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //

// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //

GPIO_Init(GPIOA, &GPIO_InitStructure); //GPIOA.10

  /* UserTestOperation NVIC */

  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5 ;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

//USART1 �?始化设置

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, &USART_InitStructure); //

USART_ITConfig(USART1, USART_IT_PE, ENABLE);

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

USART_ITConfig(USART1, USART_IT_ORE, ENABLE);

USART_ITConfig(USART1, USART_IT_TC, ENABLE);

USART_Cmd(USART1, ENABLE);          //

}

2.

void USART1_IRQHandler(void)

{

u8 temp0 = 0;

__NOP();

if(USART_GetITStatus(USART1, USART_IT_PE) != RESET)

{

__NOP();

}

if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

{

UART1Rx[UART1RxIndex] = USART_ReceiveData(USART1);

UART1Idle = 0;

if(UART1RxIndex < UART1_RX_LENGTH - 1)

{

UART1RxIndex++;

}

__NOP();

}

if(USART_GetITStatus(USART1, USART_IT_ORE) != RESET)

{

USART_ReceiveData(USART1);

USART_ClearITPendingBit(USART1,USART_IT_ORE);

__NOP();

}

if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)  //useless

{

__NOP();

}

  if( USART_GetITStatus(USART1, USART_IT_TC) == SET )

  {

   USART_ClearITPendingBit(USART1,USART_IT_TC);

   UART1TxIndex++;

   if(UART1TxIndex < UART1TxLong)

   {

   temp0 = UART1Tx[UART1TxIndex];

   while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)

   {

     NOP();

     NOP();

     NOP();

     NOP();

     NOP();

     NOP();

   }

   USART_SendData(USART1,temp0);

   while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)

   {

     NOP();

     NOP();

     NOP();

     NOP();

     NOP();

     NOP();

   }

   USART_SendData(USART2,temp0);

   }

__NOP();

  }

if(USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)

{

USART_ClearITPendingBit(USART1,USART_IT_IDLE);

USART_ReceiveData(USART1);

__NOP();

}

if(USART_GetITStatus(USART1, USART_IT_ERR) != RESET)

{

USART_ReceiveData(USART1);

USART_ClearITPendingBit(USART1,USART_IT_ERR);

__NOP();

}

if(USART_GetITStatus(USART1, USART_IT_NE) != RESET)

{

USART_ReceiveData(USART1);

USART_ClearITPendingBit(USART1,USART_IT_NE);

__NOP();

}

if(USART_GetITStatus(USART1, USART_IT_FE) != RESET)

{

USART_ReceiveData(USART1);

USART_ClearITPendingBit(USART1,USART_IT_FE);

__NOP();

}

__NOP();

}

1 REPLY 1

Certainly shouldn't be any interplay between the USARTs, something else going on here

I would recommend clearing local/auto variables to reduce the chance of odd behaviour generally

{

GPIO_InitTypeDef GPIO_InitStructure = {0};

USART_InitTypeDef USART_InitStructure = {0};

NVIC_InitTypeDef NVIC_InitStructure = {0};

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..