2014-07-02 06:58 PM
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 ? thanks2014-07-02 07:21 PM
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)2014-07-02 08:28 PM
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.