XMC1400 UART receive and character problem

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

cross mob
User14295
Level 1
Level 1
Hello,

I am working with XMC1400 bootkit for an UART application. My aim is to receive an end character like =0x0D. I am trying to use UART_AbortReceive. Here are the DAVE App and code:
2920.attach

/*
* main.c
*
*/




#include //Declarations from DAVE Code Generation (includes SFR declaration)

/**

* @brief main() - Application entry point
*
* Details of function

* This routine is the application entry point. It is invoked by the device startup code. It is responsible for
* invoking the APP initialization dispatcher routine - DAVE_Init() and hosting the place-holder for user application
* code.
*/

uint8_t txdata[] = "Hello";
uint8_t rxdata[5];

int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init(); /* Initialization of DAVE APPs */

if(status != DAVE_STATUS_SUCCESS)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}

UART_Transmit(&UART_0, txdata, sizeof(txdata));
DIGITAL_IO_SetOutputHigh (&DIGITAL_IO_0);
/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{
while(UART_0.runtime->rx_busy)
{
//If user enters character, accept the value
if((UART_0.runtime->rx_data_index > 0) && (UART_0.runtime->rx_data[UART_0.runtime->rx_data_index - 1] == 0x0D))
{
//End reception of data on finding character
UART_AbortReceive(&UART_0);
DIGITAL_IO_SetOutputLow (&DIGITAL_IO_0);
}
}
}
}

void endoftransmit (void)
{
UART_Receive(&UART_0, rxdata, sizeof(rxdata));
}

void endofreceive (void)
{
UART_Transmit(&UART_0, txdata, sizeof(txdata));
}


Now if I enter exactly 5 character (let's say 12345 or 1234\r) regardless of ending character I receive my txdata on the terminal program. But other than this I got nothing. Any help will be appreciated.
0 Likes
1 Reply
User14295
Level 1
Level 1
Hello,

I come up with the following solution.

I used Direct mode receive and put an external interrupt connected to event_std_receive. Get each byte one by one. I don't whether it is the most elegant way, but my solution is this.

Then;


#include //Declarations from DAVE Code Generation (includes SFR declaration)

uint8_t wordbuffer;
uint8_t wordlength = 0;
uint8_t newdata[100];

bool transmitbusy = false;
bool dataready = false;

int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init(); /* Initialization of DAVE APPs */

/* Placeholder for user application code. The while loop below can be replaced with user application code. */

while(1U)
{

if (dataready)
{
transmitbusy=true;
UART_Transmit(&UART_0, newdata, wordlength);
while (transmitbusy);
dataready = false;
wordlength = 0;
}

}
}

void endoftransmit(void)
{
transmitbusy = false;
}

void receivehandler (void)
{
UART_Receive (&UART_0, &wordbuffer, 1);
newdata[wordlength] = wordbuffer;
wordlength++;
if (wordbuffer == 0x0D) dataready = true;
}


Here you see the terminal output:

2921.attach
0 Likes