the problem of Distance2Go's UART about setting of the MSB/LSB

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

cross mob
User21703
Level 1
Level 1
Dear, Infenion.

I'm haneul yun.

I used Distance2Go and i try to uart communication.

i am trying to configure UART transmission for an Distance2Go.

and i finished setting of the UART Pins in order to use the UART as belows.

#define UART_TX P0_1
#define UART_RX P0_0

And i tried to transfer data using the UART_TX and it's successful.

But there are problems about sending the data transmit.

I don't see the ascii data in my serial data monitoring programs.

i only see the incorrented hex data compare of original data.

Also, When I checked the signal with an oscilloscope the bits came out LSB.

ex) i send the 0x3A(0x00111010), the signal with an oscilloscope is 0x5C(0x0101 1100)

I guess this problem occurs the LSB setting and in order to solve this problems i have to set as the MSB when the data is transmit.

how can i set the MSB setting in UART?

Could you give me an example code or information about MSB/LSB setting?




my code is as belows.


#include "uart.h"
#include "xmc_uart.h"


/* Initialization structure for both USIC0_CH0 and USIC0_CH1 channels */
XMC_UART_CH_CONFIG_t uart_config =
{
.data_bits = 8U,
.stop_bits = 1U,
.baudrate = 9600, //Baudrate
};

XMC_GPIO_CONFIG_t uart_tx =
{
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2,
.output_level = XMC_GPIO_OUTPUT_LEVEL_LOW,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_WEAK
};

XMC_GPIO_CONFIG_t uart_rx =
{
.mode = XMC_GPIO_MODE_INPUT_TRISTATE
};

/* Transmit handling IRQ */
void USIC0_0_IRQHandler(void)
{

}

const uint8_t message[] = "Hello radar!!\n";


void uart_init()
{

XMC_UART_CH_Init(XMC_UART1_CH1, &uart_config);

XMC_UART_CH_Start(XMC_UART1_CH1);

XMC_GPIO_Init(UART_TX, &uart_tx);

// XMC_USIC_CH_SetShiftDirection(XMC_UART1_CH1, XMC_USIC_CH_SHIFT_DIRECTION_MSB_FIRST);

// XMC_USIC_CH_SHIFT_DIRECTION_LSB_FIRST /**< Shift LSB first. The first data bit of a data word is located at bit position 0. */
// XMC_USIC_CH_SHIFT_DIRECTION_MSB_FIRST /**< Shift MSB first. The first data bit of a data word is located at the bit position given by the configured word length. */

send_uart_data("Uart/n",sizeof("Uart/n"));

XMC_UART_CH_Transmit(XMC_UART1_CH1, 0x60);


}

void send_uart_data(unsigned char *data, uint32_t length)
{
uint32_t index;

for (index = 0; index < length; index++)
{
XMC_UART_CH_Transmit(XMC_UART1_CH1, data[index]);

}
}
0 Likes
1 Solution
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked
Hi haneul yun,

The shift direction can be programmed by SCTR.SDIR. The standard setting for ASC frames with LSB first is achieved with the default setting SDIR = 0. You can change this to 1 to change it to MSB.
It is recommended to change SCTR.SDIR only when no data frame is running to avoid interference between hardware and software. So you can do it at the beginning before transmission.

Best Regards,
Vasanth

View solution in original post

0 Likes
3 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked
Hi haneul yun,

The shift direction can be programmed by SCTR.SDIR. The standard setting for ASC frames with LSB first is achieved with the default setting SDIR = 0. You can change this to 1 to change it to MSB.
It is recommended to change SCTR.SDIR only when no data frame is running to avoid interference between hardware and software. So you can do it at the beginning before transmission.

Best Regards,
Vasanth
0 Likes
User21703
Level 1
Level 1
Dear, Vasanth.

I try to change the register using the function as below.

XMC_USIC_CH_SetShiftDirection(XMC_UART1_CH1, XMC_USIC_CH_SHIFT_DIRECTION_MSB_FIRST);

But, the UART_TX setting didn't change as MSB and the setting was set as the LSB when the data is transmit still.


please the information about solution in order to set the MSB.

as below, my program code for setting of UART communication.

p.s. I used Distance2Go board(XMC4200) and DAVE-4.4.2-64Bit

====================================================================
/*
* uart.c
*/


#include "uart.h"
#include "xmc_uart.h"


/* Initialization structure for both USIC0_CH0 and USIC0_CH1 channels */
XMC_UART_CH_CONFIG_t uart_config =
{
.data_bits = 8U,
.stop_bits = 1U,
.baudrate = 9600, //Baudrate
.parity_mode = XMC_USIC_CH_PARITY_MODE_EVEN
};

XMC_GPIO_CONFIG_t uart_tx =
{
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2,
.output_level = XMC_GPIO_OUTPUT_LEVEL_LOW,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_WEAK
};

XMC_GPIO_CONFIG_t uart_rx =
{
.mode = XMC_GPIO_MODE_INPUT_TRISTATE
};

/* Transmit handling IRQ */
void USIC0_0_IRQHandler(void)
{

}

const uint8_t message[] = "Hello radar!!\n";


void uart_init()
{

XMC_UART_CH_Init(XMC_UART1_CH1, &uart_config);

XMC_UART_CH_Start(XMC_UART1_CH1);

XMC_GPIO_Init(UART_TX, &uart_tx);
// XMC_GPIO_Init(UART_RX, &uart_rx);

XMC_USIC_CH_Enable(XMC_UART1_CH1);

XMC_USIC_CH_SetShiftDirection(XMC_UART1_CH1, XMC_USIC_CH_SHIFT_DIRECTION_MSB_FIRST);


send_uart_data("Uart/n",sizeof("Uart/n"));


}

void send_uart_data(unsigned char *data, uint32_t length)
{
uint32_t index;

for (index = 0; index < length; index++)
{
XMC_UART_CH_Transmit(XMC_UART1_CH1, data[index]);
}
}
0 Likes
Aashita_R
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted
Hi @hnyun1030

Can you please try using this particular API to change shift direction, using before enabling UART?

Regards,
Aashita
0 Likes