How to reset data from UART after reading?

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

cross mob
Not applicable
How to reset data from UART after reading?

while (1){
ReceiveData = XMC_UART_CH_GetReceivedData(XMC_UART0_CH1);
if(ReceiveData == 0x01){

MANCHESTER_SW_0.encoder->status = 0U;
MANCHESTER_SW_0.encoder->data = ReceiveData;

MANCHESTER_SW_Encode(&MANCHESTER_SW_0);
temp1 = MANCHESTER_SW_0.encoder->status;
while(MANCHESTER_SW_0.encoder->status != 1);
ReceiveData = 0xFF;
XMC_UART_CH_Transmit(XMC_UART0_CH1, ReceiveData);
}
}

When after 1 cycle we reach the line
ReceiveData = XMC_UART_CH_GetReceivedData(XMC_UART0_CH1);

I read old data. Accordingly I receive a picture on a pin output 1_3 such picture:2627.attach

Full code:

#define UART_RX P1_3
#define UART_TX P1_2

uint16_t ReceiveData = 0;

/* Pins configuration */
XMC_GPIO_CONFIG_t uart_tx;
XMC_GPIO_CONFIG_t uart_rx;

/* UART configuration */
const XMC_UART_CH_CONFIG_t uart_config =
{
.data_bits = 8U,
.stop_bits = 1U,
.baudrate = 9600
};

int main(void)
{
DAVE_STATUS_t status;


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

uart_tx.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT7;
uart_rx.mode = XMC_GPIO_MODE_INPUT_TRISTATE;

/* Configure UART channel */
XMC_UART_CH_Init(XMC_UART0_CH1, &uart_config);
XMC_UART_CH_SetInputSource(XMC_UART0_CH1, XMC_UART_CH_INPUT_RXD,USIC0_C1_DX0_P1_3);

/* Start UART channel */
XMC_UART_CH_Start(XMC_UART0_CH1);

/* Configure pins */
XMC_GPIO_Init(UART_TX, &uart_tx);
XMC_GPIO_Init(UART_RX, &uart_rx);


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)
{

}
}
/* Placeholder for user application code. The while loop below can be replaced with user application code. */
uint32_t temp1 = 0;
while(1U)
{
ReceiveData = XMC_UART_CH_GetReceivedData(XMC_UART0_CH1);
if(ReceiveData == 0x01){

MANCHESTER_SW_0.encoder->status = 0U;
MANCHESTER_SW_0.encoder->data = ReceiveData;

MANCHESTER_SW_Encode(&MANCHESTER_SW_0);
temp1 = MANCHESTER_SW_0.encoder->status;
while(MANCHESTER_SW_0.encoder->status != 1);
ReceiveData = 0xFF;
XMC_UART_CH_Transmit(XMC_UART0_CH1, ReceiveData);
}
}

}


XMC1200 Boot Kit
0 Likes
0 Replies