UART Recieve Data Problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
I am using Universal Serial Interface Channel (USIC) - AP32303 - Application Note as a reference to reference to create sample UART communication.
I am able to transmit successfully however I have problem while receiving.
I am only able to receive last two bytes for any stream of data greater than two bytes. Kindly advice.

int index1 = 0, len;
const uint8_t message[] = "Hello world!!\n";
const uint8_t message1[] = "Data Received : ";
int8_t recieveBuffer[80];
int32_t dataCount = 0;

int main(void)
{
uint16_t tempData;
bool recieveComplete = false;
XMC_GPIO_CONFIG_t uart_tx =
{
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM
};

XMC_GPIO_CONFIG_t uart_rx =
{
.mode = XMC_GPIO_MODE_INPUT_TRISTATE
};

XMC_UART_CH_CONFIG_t uart_config =
{
.baudrate = 9600U,
.data_bits = 8U,
.frame_length = 8U,
.oversampling = 16U,
.stop_bits = 1U,
.parity_mode = XMC_USIC_CH_PARITY_MODE_NONE
};

XMC_UART_CH_Init(XMC_UART0_CH0, &uart_config);
XMC_UART_CH_SetInputSource(XMC_UART0_CH0, XMC_UART_CH_INPUT_RXD, USIC0_C0_DX0_P1_4);

/* Enabling events for TX and RX */
XMC_UART_CH_EnableEvent(XMC_UART0_CH0, XMC_UART_CH_STATUS_FLAG_TRANSMIT_BUFFER_INDICATION);
XMC_UART_CH_EnableEvent(XMC_UART0_CH0, XMC_UART_CH_STATUS_FLAG_TRANSMIT_BUFFER_INDICATION);
/* Connecting the previously enabled events to a Service Request line number */
XMC_UART_CH_SetInterruptNodePointer(XMC_UART0_CH0, XMC_UART_CH_INTERRUPT_NODE_POINTER_TRANSMIT_SHIFT);
XMC_UART_CH_SetInterruptNodePointer(XMC_UART0_CH0, XMC_UART_CH_INTERRUPT_NODE_POINTER_RECEIVE);
/* Start USIC operation as UART */
XMC_UART_CH_Start(XMC_UART0_CH0);

/*Initialization of the necessary ports*/
XMC_GPIO_Init(UART_TXD, &uart_tx);
XMC_GPIO_Init(UART_RXD, &uart_rx);

/*Configuring priority and enabling NVIC IRQ for the defined Service Request line number */
NVIC_SetPriority(USIC0_0_IRQn, 1U);
NVIC_EnableIRQ(USIC0_0_IRQn);
len = strlen(message);
for(index1 = 0; index1 < len;)
XMC_UART_CH_Transmit(XMC_UART0_CH0, message[index1++]);
memset(recieveBuffer, 0, 80);
/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{
if(!recieveComplete) //Routine to receive data from PC
{
while((XMC_UART_CH_GetStatusFlag(XMC_UART0_CH0) &
(XMC_UART_CH_STATUS_FLAG_RECEIVE_INDICATION | XMC_UART_CH_STATUS_FLAG_RECEIVE_FRAME_FINISHED |
XMC_UART_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION)) == 0){}
tempData = XMC_UART_CH_GetReceivedData(XMC_UART0_CH0);
if(tempData == '>')
recieveComplete = true;
recieveBuffer[dataCount++] = (int8_t) tempData;
}
if(recieveComplete) //Transmit received data back to the PC
{
len = strlen(message1);
for(index1 = 0; index1 < len;)
XMC_UART_CH_Transmit(XMC_UART0_CH0, message1[index1++]); //Send string "Data Received : "
len = strlen(recieveBuffer);
for(index1 = 0; index1 < len;)
XMC_UART_CH_Transmit(XMC_UART0_CH0, recieveBuffer[index1++]); //Send back received data
XMC_UART_CH_Transmit(XMC_UART0_CH0, '\n');
recieveComplete = false;
dataCount = 0;
memset(recieveBuffer, 0, 80);
}

}
}
1 Reply
user8710
Level 3
Level 3
5 questions asked 50 sign-ins 10 replies posted

Same problem and not answers in this "Community"

0 Likes