+ Reply to Thread
Results 1 to 2 of 2

Thread: UART Problem

  1. #1
    Beginner Beginner Meni is on a distinguished road
    Join Date
    May 2019
    Posts
    6
    Points
    62.5

    UART Problem

    Hi,

    I'm using Distance2Go (XMC4200) kit and I'm trying to use UART.
    Unfortunately the sample code that the company offers is not working.
    Does anyone have any code that works?
    Attached is the code I used
    include <xmc_gpio.h>
    #include <xmc_uart.h>

    /* Pins macro definition */

    #define LED1 P2_1
    #define UART_TX P0_1
    #define UART_RX P0_0

    /* Number of data to tx/rx and limits for the TX and RX FIFOs */

    #define NUM_DATA 25
    #define RX_FIFO_INITIAL_LIMIT 7
    #define TX_FIFO_INITIAL_LIMIT 1

    /* Initialization structures */

    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_GPIO_CONFIG_t led =
    {
    .mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
    .output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM
    };

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

    /* Global variables initialization. Tx and rx indexes and tx and rx arrays */
    uint32_t tx_index=0;
    uint32_t rx_index=0;
    uint8_t tx_data[NUM_DATA];
    uint16_t rx_data[NUM_DATA];


    /* Transmit handling IRQ */
    void USIC0_0_IRQHandler(void)
    {
    /* If still remaining data to be send */
    if(tx_index < NUM_DATA)
    {
    /* Fill the TX FIFO till it is full */
    while(!XMC_USIC_CH_TXFIFO_IsFull(XMC_UART0_CH0))
    {
    XMC_UART_CH_Transmit(XMC_UART0_CH0, tx_data[tx_index]);
    tx_index++;
    }
    }
    }

    /* Receive handling IRQ */
    void USIC1_1_IRQHandler(void)
    {
    /* Read the RX FIFO till it is empty */
    while(!XMC_USIC_CH_RXFIFO_IsEmpty(XMC_UART1_CH0))
    {
    rx_data[rx_index++] = XMC_UART_CH_GetReceivedData(XMC_UART1_CH0);
    }

    /* If all the data have been received */
    if(rx_index == (NUM_DATA))
    {
    /* Check if every received data match with the transmitted data */
    for (int tmp=0; tmp<NUM_DATA; tmp++)
    {
    /* If reception fails stays in an infinite while loop and switch off the LED */
    if (tx_data[tmp]!=rx_data[tmp])
    {
    while(1)
    {
    XMC_GPIO_SetOutputLow(LED1);
    }
    }
    else
    {
    /* If reception is successful switch on the LED */
    XMC_GPIO_SetOutputHigh(LED1);
    }
    }
    }

    /* If the remaining data to be received is smaller than the initial RX FTFO Limit
    * it is modified to the remaining data minus 1 in order react when we have all the data received*/
    if((NUM_DATA-rx_index) < RX_FIFO_INITIAL_LIMIT)
    {
    XMC_USIC_CH_RXFIFO_SetSizeTriggerLimit(XMC_UART1_C H0, XMC_USIC_CH_FIFO_SIZE_8WORDS, (NUM_DATA-rx_index)-1);
    }
    }

    int main(void)
    {

    /* USIC channels initialization */
    XMC_UART_CH_Init(XMC_UART0_CH0, &uart_config);
    XMC_UART_CH_Init(XMC_UART1_CH0, &uart_config);

    /* Input multiplexer configuration for UART1_CH0 */
    XMC_UART_CH_SetInputSource(XMC_UART1_CH0, XMC_UART_CH_INPUT_RXD, USIC1_C1_DX0_P0_0);

    /* FIFOs initialization for both channels:
    * 8 entries for TxFIFO from point 0, LIMIT=1
    * 8 entries for RxFIFO from point 8, LIMIT=7 (SRBI is set if all 8*data has been received)
    * */
    XMC_USIC_CH_TXFIFO_Configure(XMC_UART0_CH0, 0, XMC_USIC_CH_FIFO_SIZE_8WORDS, TX_FIFO_INITIAL_LIMIT);
    XMC_USIC_CH_RXFIFO_Configure(XMC_UART1_CH0, 8, XMC_USIC_CH_FIFO_SIZE_8WORDS, RX_FIFO_INITIAL_LIMIT);

    /* Enabling events for TX FIFO and RX FIFO */
    XMC_USIC_CH_TXFIFO_EnableEvent(XMC_UART0_CH0,XMC_U SIC_CH_TXFIFO_EVENT_CONF_STANDARD);
    XMC_USIC_CH_RXFIFO_EnableEvent(XMC_UART1_CH0,XMC_U SIC_CH_RXFIFO_EVENT_CONF_STANDARD |
    XMC_USIC_CH_RXFIFO_EVENT_CONF_ALTERNATE);

    /* Connecting the previously enabled events to a Service Request line number */
    XMC_USIC_CH_TXFIFO_SetInterruptNodePointer(XMC_UAR T0_CH0,XMC_USIC_CH_TXFIFO_INTERRUPT_NODE_POINTER_S TANDARD,0);
    XMC_USIC_CH_RXFIFO_SetInterruptNodePointer(XMC_UAR T1_CH0,XMC_USIC_CH_RXFIFO_INTERRUPT_NODE_POINTER_S TANDARD,1);
    XMC_USIC_CH_RXFIFO_SetInterruptNodePointer(XMC_UAR T1_CH0,XMC_USIC_CH_RXFIFO_INTERRUPT_NODE_POINTER_A LTERNATE,1);

    /* Start USIC operation as UART */
    XMC_UART_CH_Start(XMC_UART0_CH0);
    XMC_UART_CH_Start(XMC_UART1_CH0);

    /*Initialization of the necessary ports*/
    XMC_GPIO_Init(UART_TX,&uart_tx);
    XMC_GPIO_Init(UART_RX,&uart_rx);
    XMC_GPIO_Init(LED1,&led);

    /*Configuring priority and enabling NVIC IRQ for the defined Service Request line number */
    NVIC_SetPriority(USIC0_0_IRQn,63U);
    NVIC_EnableIRQ(USIC0_0_IRQn);
    NVIC_SetPriority(USIC1_1_IRQn,62U);
    NVIC_EnableIRQ(USIC1_1_IRQn);

    USIC1_1_IRQHandler();
    /* Filling the tx array */
    for (uint32_t i = 0; i < NUM_DATA; i++)
    {
    tx_data[i]=i;
    }

    /* Filling the the first time TX FIFO. Successive fillings will be done in the TX FIFO IRQ*/
    while(!XMC_USIC_CH_TXFIFO_IsFull(XMC_UART0_CH0))
    {
    XMC_UART_CH_Transmit(XMC_UART0_CH0,tx_data[tx_index++]);
    }


    while(1)
    {
    /* Infinite loop */
    }
    }
    ?????

  2. #2
    Beginner Beginner Meni is on a distinguished road
    Join Date
    May 2019
    Posts
    6
    Points
    62.5

    Uart

    Why the technical staff does not answer?

+ Reply to Thread
Disclaimer

All content and materials on this site are provided “as is“. Infineon makes no warranties or representations with regard to this content and these materials of any kind, whether express or implied, including without limitation, warranties or representations of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, whether express or implied, is granted by Infineon. Use of the information on this site may require a license from a third party, or a license from Infineon.


Infineon accepts no liability for the content and materials on this site being accurate, complete or up- to-date or for the contents of external links. Infineon distances itself expressly from the contents of the linked pages, over the structure of which Infineon has no control.


Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Usage Terms of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Usage Terms of this site. Infineon reserves the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.