cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F051K4T6 usart only can receive one byte data

435674542
Associate
Posted on July 03, 2014 at 03:58

HI 

   I am using STM32F051K4T6 to test usart function. 

which i can receive only one byte data from my PC serial tool  when debugging in CooCox IDE 

when  send only one byte from pc  its ok  i can enter the interrupt 

but when i send two or more bytes one time . program enter the interrupt one time and after that  i can not enter interrupt any more even i send one byte. it seems that the program has gone.

following is my code . any one can help me ? thanks

0690X00000602vNQAQ.jpg0690X00000602vAQAQ.jpg
2 REPLIES 2
Posted on July 03, 2014 at 04:21

I don't see the IRQHandler, so no idea how you're servicing that.

You do something with TC that makes absolutely no sense, it has nothing to do with receiving data.

You NEED to wait for RXNE before taking each character out, or use the IRQHandler to read it on a RXNE interrupt.

To paste code to the forum use the Format Code Block tool (Paintbrush [<>] icon)
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
435674542
Associate
Posted on July 03, 2014 at 05:28

yes this is my first time sent a discussion here .

void USART1_IRQHandler(void)
{
/* USART in mode Tramitter -------------------------------------------------*/
if (USART_GetITStatus(USART1, USART_IT_TXE) == SET)
{ /* When Joystick Pressed send the command then send the data */
if (UsartMode == USART_MODE_TRANSMITTER)
{ /* Send the command */
if (UsartTransactionType == USART_TRANSACTIONTYPE_CMD)
{
USART_SendData(USART1, CmdBuffer[TxIndex++]);
if (TxIndex == 0x02)
{
/* Disable the USARTx transmit data register empty interrupt */
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
}
}
/* Send the data */
else
{
USART_SendData(USART1, TxBuffer[TxIndex++]);
if (TxIndex == GetVar_NbrOfData())
{
/* Disable the USARTx transmit data register empty interrupt */
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
}
}
}
/*If Data Received send the ACK*/
else
{
USART_SendData(USART1, AckBuffer[TxIndex++]);
if (TxIndex == 0x02)
{
/* Disable the USARTx transmit data register empty interrupt */
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
}
}
}
/* USART in mode Receiver --------------------------------------------------*/
if (USART_GetITStatus(USART1, USART_IT_RXNE) == SET)
{
if (UsartMode == USART_MODE_TRANSMITTER)
{
AckBuffer[RxIndex++] = USART_ReceiveData(USART1);
}
else
{
/* Receive the command */
if (UsartTransactionType == USART_TRANSACTIONTYPE_CMD)
{
CmdBuffer[RxIndex++] = USART_ReceiveData(USART1);
}
/* Receive the USART data */
else
{
RxBuffer[RxIndex++] = USART_ReceiveData(USART1);
}
}
} 
}

you are write the tc code in while loop does not make any sense.