auto baudrate detection

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

cross mob
Not applicable
hello
is there any code snippet available for auto baudrate detection function for the XMC1100?
regards
enzo
0 Likes
2 Replies
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

You can either try with counter register in the USIC or your could even use the capture functionality of the CCUx.
Below is the code using the capture register in the USICx

#include 
#include

#define UART_TX P1_5
#define UART_RX P1_4


__STATIC_INLINE uint32_t XMC_USIC_CH_GetCaptureTimerValue(const XMC_USIC_CH_t *const channel)
{
return channel->CMTR;
}

__STATIC_INLINE void XMC_USIC_CH_SetFractionalDivider(XMC_USIC_CH_t *const channel, const XMC_USIC_CH_BRG_CLOCK_DIVIDER_MODE_t mode, const uint16_t step)
{
channel->FDR = mode | step;
}

int main(void)
{
volatile uint32_t baudrate;

XMC_USIC_CH_Enable(XMC_UART0_CH0);

XMC_GPIO_SetMode(UART_RX, XMC_GPIO_MODE_INPUT_TRISTATE);
XMC_USIC_CH_SetInputSource(XMC_UART0_CH0, XMC_UART_CH_INPUT_RXD, USIC0_C0_DX0_P1_4);

// Set counter frequency to 1MHz
XMC_USIC_CH_SetFractionalDivider(XMC_UART0_CH0, XMC_USIC_CH_BRG_CLOCK_DIVIDER_MODE_NORMAL, 1023 - (uint32_t)(SystemCoreClock / 1000000));

XMC_USIC_CH_EnableTimeMeasurement(XMC_UART0_CH0);

XMC_USIC_CH_SetInputTriggerCombinationMode(XMC_UART0_CH0, XMC_UART_CH_INPUT_RXD, XMC_USIC_CH_INPUT_COMBINATION_MODE_FALLING_EDGE);
while ((XMC_UART_CH_GetStatusFlag(XMC_UART0_CH0) & XMC_UART_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION) == 0);
XMC_UART_CH_ClearStatusFlag(XMC_UART0_CH0, XMC_UART_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION);

XMC_USIC_CH_SetInputTriggerCombinationMode(XMC_UART0_CH0, XMC_UART_CH_INPUT_RXD, XMC_USIC_CH_INPUT_COMBINATION_MODE_RISING_EDGE);
while ((XMC_UART_CH_GetStatusFlag(XMC_UART0_CH0) & XMC_UART_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION) == 0);

// The host will send 0x00, the pulse length will be 9 * (1 / baudrate)
baudrate = (9 * 1E6) / XMC_USIC_CH_GetCaptureTimerValue(XMC_UART0_CH0);

/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{

}
}


Regards,
Jesus
0 Likes
Not applicable
thank you
regards
enzo
0 Likes