XMC1100 boot kit and uart

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

cross mob
Not applicable
I'm not able to set-up interrupt uart receiving using dave app on the XMC1100 boot kit. Can someone give me an advice?
And what is the difference between UART_0 and UART_CONFIG_0 ? Some settings are duplicated and are conflictual (conflicting types for 'UART_CONFIG_t')
0 Likes
18 Replies
Not applicable
Why this works: (only transmit)

uint8_t send_data[] = "\nHello world!";

while(1U)
{
UART_Transmit(&UART_0, send_data, sizeof(send_data));
}


and this doesn't work?:

uint8_t read_data=0x00;

while(1U)
{
UART_Receive(&UART_0,&read_data,1);
if (read_data != 0x00)
{
UART_Transmit(&UART_0, &read_data, 1);
read_data = 0x0;
}
}
}
0 Likes
Not applicable
With the second code (receive and transmit), I don't see nothing in the terminal, but when I press some key on the keyboard I can see P1.3 led light ... P1.3 is TX...
0 Likes
Not applicable
With the first code that send string continuously, led P1.2 (RX) lights up...
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi,

so first of all to answer your question...difference between UART APP and UART_CONFIG APP is the functionality behind the app. CONFIG APPs are intended to provide you with all the details and options that our XMClibs and consequently our hardware supports. UART APP is more straightforward approach, it hides some details and options from the user but it provides out-of-the-box usage in the application for which majority people will use this APP. UART while it´s fairly simple protocol doesn´t not have so many options so both APPs ("regular" one and CONFIG app) share a lot of similarities. However, more complicated protocols makes the differences much more obvious.

You should not use both APPs inside the same project...it wasn´t intended to be used like this and it can cause some conflicts as you´re already aware. For this basic example with terminal, UART APP will be sufficient.

I took a look at the code you posted above and I didn´t completely understand the issue, but I believe I know why is not working for you. I see that definition of the pins is different than it should be if you´re using COM port.

So my working example (that you can use and try it on your board) defines pins as following:
2365.attach

UART APP settings for my example are:
2366.attach

2367.attach

And finally, my "main.c" code:
#include                  //Declarations from DAVE Code Generation (includes SFR declaration)

int main(void)
{
uint8_t init_data[] = "Press any key to continue:\n";
uint8_t send_data[] = "\nHello world!";
uint8_t read_data = 0x0;

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

/* Transmit the introduction message */
UART_Transmit(&UART_0, init_data, sizeof(init_data));

while(1U)
{
/* Read the data */
UART_Receive(&UART_0, &read_data,1);
if(read_data != 0x00)
{
/* Transmit the message */
UART_Transmit(&UART_0, send_data, sizeof(send_data));
read_data = 0x0;
}
}
return 0;
}


Try to run this code and let me know if you still have some issues.

Best regards,
Deni
0 Likes
Not applicable
This example works.
But I want to echo back bytes received.
If I put:

UART_Transmit(&UART_0, read_data, sizeof(read_data));

(read_data instead of send_data)

doesn't work
0 Likes
Not applicable
Sorry, my mistake.
I've corrected with:

UART_Transmit(&UART_0, &read_data, 1);

now works.

Okay, now I want an interrupt on single byte received... How can I do it?
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi,

you already have interrupt on single byte received. Notice that in my previous post I specified that FIFO buffers should NOT be used. What does that mean for you? Due to the fact that FIFO buffers are not used, we wait for following interrupt events: XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE and XMC_USIC_CH_EVENT_STANDARD_RECEIVE. Also notice that our receive function expects only 1 data byte to be received. However, I can imagine what is your concern....you feel that you don´t have enough control over the whole process and that you cannot make it more "interactive" (I guess this is not the best words usage but hopefully you get my point).

I can suggest you several things (from easiest to most complicated one to implement):
1. you can use "End of receive callback" function that is given under "Interrupt Settings" tab in UART APP. What would be the use case? Let´s say you want to receive 1 character from the terminal and do some processing on it. You enable receive callback function and once the 1 byte is received, receive interrupt handler will call the receive callback function and you can do the post-processing inside this function.
2. you can define your own receive interrupt handler routine...take a look at this post https://www.infineonforums.com/threads/2856-UART-Receive-Problem-with-Dave-and-the-XMC1300?p=8201&vi... for more details.
3. you can use "Direct" mode for "Protocol Handling" ("Advanced Settings" tab under UART APP) and then you have the full control...however you need to define the interrupt routine handler and also trigger the events and define the events which are going to be used

as you can see there are multiple approaches and everything depends what is your application. However, for the time being I suggest you try to use the first approach and see does it satisfy your needs.

Best regards,
Deni
0 Likes
Not applicable
Ok Thank you.
If I don't want to use DAVE app, how can I enable and capture the interrupt using only XMC libraries?
0 Likes
Not applicable
I think must use:

XMC_UART_CH_EnableEvent(XMC_UART0_CH1,XMC_UART_CH_EVENT_STANDARD_RECEIVE);
XMC_UART_CH_SetInterruptNodePointer(XMC_UART0_CH1,XMC_UART_CH_INTERRUPT_NODE_POINTER_RECEIVE);

and

NVIC_SetPriority(USIC0_0_IRQn, 1);
NVIC_EnableIRQ(USIC0_0_IRQn);

but I want to understand how bind interrupt request to a function without using Apps
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Exactly,

you need to use the mentioned two functions. If you want to learn how to do it without APPs, I suggest you take a look at the generated file of DAVE APP :). I know, I know...without DAVE APPs, but bear with me for a moment. You already have working example with DAVE APPs I suppose. Take a look at "uart_conf.c" and "uart.c". These files are generated by the DAVE´s code engine and they are placed under "DAVE -> Generated -> UART" inside your project. From there you can see which XMClib functions (output of the DAVE APPs is always a XMClib function) should be used to achieve your goal. Then you can try step by step to "mimic" the DAVE code engine and in no time you´ll have your own program written exclusively with XMClibs.

Try it for yourself 😉

Best regards,
Deni
0 Likes
Not applicable
Sorry but I don't have a Dave app example working.
I've tried to setup interrupt as you say. I've put a "ISR_uart_rx" as callback of end receive, pressed "Generate code", rebuilded and uploaded but nothing happens



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

int main(void)
{
DAVE_Init(); /* Initialization of DAVE APPs */

while(1U)
{
}
return 0;
}

void ISR_uart_rx (void)
{
uint8_t read_data = 0x0;
/* Read the data */
UART_Receive(&UART_0, &read_data,1);
if(read_data != 0x00)
{
/* Transmit the message */
UART_Transmit(&UART_0, &read_data, 1);
read_data = 0x0;
}

}
0 Likes
Not applicable
Sorry but Interrupt example as you said doesn't work

in generated files there is:

/*Receive ISR*/
void UART_0_RX_HANDLER()
{
UART_lReceiveHandler(&UART_0);
}

but nothing in the code call this function (UART_0_RX_HANDLER)
only in the configuration there is a refer to my own interrupt function (ISR_uart_rx) but this config is never used in the code!:

/*UART APP configuration structure*/
const UART_CONFIG_t UART_0_config =
{
.channel_config = &UART_0_channel_config,


.fptr_uart_config = UART_0_init,
.tx_cbhandler = NULL,
.rx_cbhandler = ISR_uart_rx,
.sync_error_cbhandler = NULL,
.rx_noise_error_cbhandler = NULL,
.format_error_bit0_cbhandler = NULL,
.format_error_bit1_cbhandler = NULL,
.collision_error_cbhandler = NULL,
.tx_pin_config = &UART_0_tx_pin,
.mode = UART_MODE_FULLDUPLEX,
.transmit_mode = UART_TRANSFER_MODE_INTERRUPT,
.receive_mode = UART_TRANSFER_MODE_INTERRUPT,
.tx_fifo_size = XMC_USIC_CH_FIFO_DISABLED,
.rx_fifo_size = XMC_USIC_CH_FIFO_DISABLED,
.tx_sr = 0x1U,
};

Even if i substitute ISR_uart_rx in the UART_0_RX_HANDLER() nothing happens.
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Cyb3rn0id wrote:
Sorry but I don't have a Dave app example working.
I've tried to setup interrupt as you say. I've put a "ISR_uart_rx" as callback of end receive, pressed "Generate code", rebuilded and uploaded but nothing happens



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

int main(void)
{
DAVE_Init(); /* Initialization of DAVE APPs */

while(1U)
{
}
return 0;
}

void ISR_uart_rx (void)
{
uint8_t read_data = 0x0;
/* Read the data */
UART_Receive(&UART_0, &read_data,1);
if(read_data != 0x00)
{
/* Transmit the message */
UART_Transmit(&UART_0, &read_data, 1);
read_data = 0x0;
}

}


Compare this code section with the code section I posted some posts before which is working and see how much code you have change. It´s a pretty big difference, not very iterative approach I must admit.

Dave_Init() function will initialize service requests:

2374.attach

Now let´s take a look who calls the receive callback function. Under "uart.c" (folder "DAVE -> Generated -> UART" in you active project) search for "UART_lReceiveHandler". This function calls the receive callback function if you defined it in the DAVE APP:

2375.attach

OK, so now you know that DAVE_init initializes service requests, and that function "UART_lReceiveHandler" calls callback function. Where does the function "UART_lReceiveHandler" come from? File "uart_conf.c" (folder "DAVE -> Generated -> UART" in you active project):

2376.attach

A OK....this is interrupt handler routine. So you need to have receive interrupt to trigger this function that will later on call receive callback function. I told you already that you need two things to trigger interrupt...you need to initialize service request (this is already done by Dave_Init()) and you need to define events on which the interrupt will occur. Remember this one: XMC_USIC_CH_EVENT_STANDARD_RECEIVE? Now search inside "uart.c" file for this keyword. This should caught your attention:

2377.attach

Exactly, what we need. Which function is enabling interrupt events for us? Scroll a little bit up and you find this name "UART_StartReceiveIRQ". Still doesn´t ring a bell I guess. Well let´s search that function name...aaaa this look now familiar.

2378.attach

It´s the "UART_Receive" function that enables the receive events.I hope you understand what is the issue with your code...you don´t try to receive anything from the terminal. It won´t happen just be using DAVE_init and having infinite "while" loop expecting something will happen. Add "UART_Receive" to the "while" loop and try then to receive a character from terminal.

Best regards,
Deni
0 Likes
Not applicable
DRubeša wrote:


Dave_Init() function will initialize service requests:

2374.attach


My Dave_init is very different from yours:

2379.attach

My Uart configuration is:

2380.attach
2381.attach
2382.attach

DRubeša wrote:

It´s the "UART_Receive" function that enables the receive events.I hope you understand what is the issue with your code...you don´t try to receive anything from the terminal. It won´t happen just be using DAVE_init and having infinite "while" loop expecting something will happen. Add "UART_Receive" to the "while" loop and try then to receive a character from terminal.


It's a very strange approach for me.
I work with other microcontrollers (such as microchip picmicro and AVRs): If I have an UART interrupt, after settings (in the main, outside the main loop) I must put nothing in the main loop to receive data: interrupt will do all the job regardless the main.
I don't understand the need of put an "uart_receive" in the loop if I've enabled an Uart-receive-interrupt with his own function. It's very strange to me.

Can you attach your project since the example you're writing are very different to my generated code?
I'm using DAVE 4.3 and latest libraries.
Thank you for your patience.
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi,

sorry, I wasn´t totally explicit. Dave_init will call Uart_init that will set the service requests. When you try to debug the code by single-stepping you´ll notice exactly the things I mentioned. Your other DAVE APP settings look good.

I know that this approach is different from the things you may encounter before but that is what it is 🙂 the thing is that here we use Interrupt mode as a Protocol Handling. I guess the Direct mode would be something that is more familiar to your previous experience. In Direct mode you need to take care of enabling interrupt and defining which events should cause an interrupt. In Interrupt mode APP does it for you, so there is less work on your side. But I can understand that is slightly different from the things you´re used.

I can do an example tomorrow that will support my previous post. Today I need to excuse myself, while I´m on a sick leave 🙂 and I don´t have XMC1100 Boot kit at home. But try to incorporate UART_Receive function in your code...it´s seams you really close to the correct solution.

Best regards,
Deni
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi,

me again. So as I promised...example using Interrupt mode as as Protocol Handling:
2384.attach
2385.attach
2386.attach
2388.attach

My "main.c" code:
#include                  //Declarations from DAVE Code Generation (includes SFR declaration)

uint8_t read_data = 0x0;

int main(void)
{

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

while(1U)
{
/* Read the data */
UART_Receive(&UART_0, &read_data,1);
}

return 0;
}

void ISR_uart_rx (void)
{
if(read_data != 0x00) /* this condition is not even necessary, while we only enter "ISR_uart_rx" routine after we received some
data and stored it into "read_data" variable */
{
/* Transmit the message */
UART_Transmit(&UART_0, &read_data, 1);
}
}


And finally, result on the HTerm window (you can see that every character that I receive FROM the terminal is transmitted BACK to the terminal). As you can see, echo functionality is achieved.
2387.attach

I can maybe even prepare a short example using Direct mode or even using XMClibs only but don´t take me for my word, I have also another tasks to do 😄

Best regards,
Deni
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi 🙂

so, I had some time and I done the Direct mode as I said but to be honest it´s not very useful example and I think you would prefer something that uses XMClibs....so I built exactly that. UART echo functionality using only XMClibs and interrupt handler like you probably used it in your previous projects with other architectures/vendors.

#include 
#include

#define UART_TX_HANDLER IRQ_Hdlr_10
#define UART_RX_HANDLER IRQ_Hdlr_9

typedef struct GPIO_PIN
{
XMC_GPIO_PORT_t *const port; /**< Pointer to the GPIO port base address */
const uint8_t pin; /**< Pin number in the port*/
const XMC_GPIO_CONFIG_t *const config; /**< Pin configuration structure */
} GPIO_PIN_t;

/*USIC channel configuration*/
const XMC_UART_CH_CONFIG_t UART_channel_config =
{
.baudrate = 19200U,
.data_bits = 8U,
.frame_length = 8U,
.stop_bits = 1U,
.oversampling = 16U,
.parity_mode = XMC_USIC_CH_PARITY_MODE_NONE
};

/*Transmit pin configuration*/
const XMC_GPIO_CONFIG_t UART_tx_pin_config =
{
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT7,
.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH
};

/*Transmit pin configuration used for initializing*/
const GPIO_PIN_t UART_tx_pin =
{
.port = (XMC_GPIO_PORT_t *)PORT1_BASE,
.config = &UART_tx_pin_config,
.pin = 2U
};

/*Receive pin configuration*/
const XMC_GPIO_CONFIG_t UART_rx_pin_config = {
.mode = XMC_GPIO_MODE_INPUT_TRISTATE,
.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH,
.input_hysteresis = XMC_GPIO_INPUT_HYSTERESIS_STANDARD
};

/*Receive pin configuration used for initializing*/
const GPIO_PIN_t UART_rx_pin =
{
.port = (XMC_GPIO_PORT_t *)PORT1_BASE,
.config = &UART_rx_pin_config,
.pin = 3U
};

int main(void)
{

/* Initialize UART RX pin */
XMC_GPIO_Init(UART_rx_pin.port, UART_rx_pin.pin, UART_rx_pin.config);

/* Initialize USIC channel in UART mode*/
XMC_UART_CH_Init(XMC_UART0_CH1, &UART_channel_config);

/*Set input source path*/
XMC_USIC_CH_SetInputSource(XMC_UART0_CH1, XMC_USIC_CH_INPUT_DX0, USIC0_C1_DX0_P1_3);

/* Start UART */
XMC_UART_CH_Start(XMC_UART0_CH1);

/* Initialize UART TX pin */
XMC_GPIO_Init(UART_tx_pin.port, UART_tx_pin.pin, UART_tx_pin.config);

/*Set service request for transmit interrupt */
XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH1, XMC_USIC_CH_INTERRUPT_NODE_POINTER_TRANSMIT_BUFFER, 1U);

/*Set service request for receive interrupt and enable receive interrupt events */
XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH1, XMC_USIC_CH_INTERRUPT_NODE_POINTER_RECEIVE, 0U);
XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH1, XMC_USIC_CH_INTERRUPT_NODE_POINTER_ALTERNATE_RECEIVE, 0U);
XMC_USIC_CH_EnableEvent(XMC_UART0_CH1, (uint32_t)((uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE | (uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE));

/*Set priority and enable NVIC node for transmit interrupt*/
NVIC_SetPriority((IRQn_Type)10, 3U);
NVIC_EnableIRQ((IRQn_Type)10);

/*Set priority and enable NVIC node for receive interrupt*/
NVIC_SetPriority((IRQn_Type)9, 3U);
NVIC_EnableIRQ((IRQn_Type)9);

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

}
}

void UART_RX_HANDLER(void){
uint8_t read_data = 0x0;

/*Disable both standard receive and alternative receive FIFO events */
XMC_USIC_CH_DisableEvent(XMC_UART0_CH1, (uint32_t)((uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE | (uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE));

/*Enable transmit buffer interrupt */
XMC_USIC_CH_EnableEvent(XMC_UART0_CH1, (uint32_t)XMC_USIC_CH_EVENT_TRANSMIT_BUFFER);

/*Read received data */
read_data = XMC_UART_CH_GetReceivedData(XMC_UART0_CH1);

/*Transmit data back to the terminal (echo functionality) */
XMC_UART_CH_Transmit(XMC_UART0_CH1, read_data);
}

void UART_TX_HANDLER(void){

/*Disable transmit buffer interrupt */
XMC_USIC_CH_DisableEvent(XMC_UART0_CH1, (uint32_t)XMC_USIC_CH_EVENT_TRANSMIT_BUFFER);

/*Enable receive interrupt events */
XMC_USIC_CH_EnableEvent(XMC_UART0_CH1, (uint32_t)((uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE | (uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE));

}


I know...not the coolest code ever but it should suit your needs understanding how UART on XMC can be used.
If you have additional question, feel free to ask.

Best regards,
Deni
0 Likes
Not applicable
Hello deni
I was reading this post and I have an issue which is somewhat related to this thread.
I am trying to read the received data from pc using UART. But the problem is that transmission is running just fine but no reception.
Every time I send the data from terminal to xmc1300 boot kit, it doesn't read anything. I have tried almost everything. Could you please have a look at my code and see where i am doing wrong. The application is basically used to control the color of LEDs using commands sent through uart.
 */
#include
#include "xmc_gpio.h"
#include "xmc_uart.h"
#include
#include
#include
#include
// BCCU Channels for PDM outputs to Ports
#define R_LED1_CH BCCU0_CH0
#define G_LED1_CH BCCU0_CH7
#define B_LED1_CH BCCU0_CH8

// Port Pins for PDM outputs to LED drivers (BCR321)
#define R_LED1_PIN P0_4
#define G_LED1_PIN P0_11
#define B_LED1_PIN P0_1

// Port Pins for unused LEDs
#define R_LED2_PIN P0_5
#define G_LED2_PIN P0_6
#define B_LED2_PIN P0_7
#define R_LED3_PIN P0_8
#define G_LED3_PIN P0_9
#define B_LED3_PIN P0_10
/*********************************************************************************************************************
* CONFIGURATION
*********************************************************************************************************************/

/* Clock configuration */
XMC_SCU_CLOCK_CONFIG_t clock_config =
{
.pclk_src = XMC_SCU_CLOCK_PCLKSRC_DOUBLE_MCLK,
.fdiv = 0,
.idiv = 1
};

/* BCCU configuration */
XMC_BCCU_GLOBAL_CONFIG_t bccu_global_config =
{
.fclk_ps = 0x50, //800kHz @PCLK=64MHz
.dclk_ps = 0xdb, //292.237KHz @PCLK=64MHz
.bclk_sel = XMC_BCCU_BCLK_MODE_NORMAL //200KHz @PCLK=64MHz
};
XMC_BCCU_CH_CONFIG_t r_pdm_config =
{
.dim_sel = XMC_BCCU_CH_DIMMING_SOURCE_DE0 // DE0
};
XMC_BCCU_CH_CONFIG_t g_pdm_config =
{
.dim_sel = XMC_BCCU_CH_DIMMING_SOURCE_DE0 // DE0
};
XMC_BCCU_CH_CONFIG_t b_pdm_config =
{
.dim_sel = XMC_BCCU_CH_DIMMING_SOURCE_DE0 // DE0
};
XMC_BCCU_DIM_CONFIG_t bccu_dim_config =
{
.dim_div = 0x0 // immediate dimming
};


XMC_GPIO_CONFIG_t led1_config;
XMC_GPIO_CONFIG_t rx_pin_config;
XMC_GPIO_CONFIG_t tx_pin_config;
XMC_UART_CH_CONFIG_t uart_config;
int main(void)
{

//----CLOCK-SETUP-----------------------------------------------------------------------------------
XMC_SCU_CLOCK_Init(&clock_config);
//--------------------------------------------------------------------------------------------------

/* init unused LED output pins so that they will not light up */
XMC_GPIO_SetMode(R_LED2_PIN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);
XMC_GPIO_SetMode(G_LED2_PIN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);
XMC_GPIO_SetMode(B_LED2_PIN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);
XMC_GPIO_SetMode(R_LED3_PIN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);
XMC_GPIO_SetMode(G_LED3_PIN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);
XMC_GPIO_SetMode(B_LED3_PIN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);

/* init PDM output pins */
XMC_GPIO_SetMode(R_LED1_PIN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1);
XMC_GPIO_SetMode(G_LED1_PIN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1);
XMC_GPIO_SetMode(B_LED1_PIN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT6);

/* BCCU Global Initialization */
XMC_BCCU_GlobalInit(BCCU0, &bccu_global_config);

//----DIMMING&COLOR-----------------------------------------------------------------------------------------
/* init dimming engine */
XMC_BCCU_DIM_Init(BCCU0_DE0, &bccu_dim_config);
/* enable dimming engine */
XMC_BCCU_EnableDimmingEngine(BCCU0, XMC_BCCU_CH_DIMMING_SOURCE_DE0);
/* set target dimming level to max */
XMC_BCCU_DIM_SetTargetDimmingLevel(BCCU0_DE0, 4095);
/* effect the change in dimming level */
XMC_BCCU_StartDimming(BCCU0, XMC_BCCU_CH_DIMMING_SOURCE_DE0);

/* init channels */
XMC_BCCU_CH_Init(R_LED1_CH, &r_pdm_config);
XMC_BCCU_CH_Init(G_LED1_CH, &g_pdm_config);
XMC_BCCU_CH_Init(B_LED1_CH, &b_pdm_config);

/* Enable PDM channels*/
XMC_BCCU_ConcurrentEnableChannels(BCCU0, 0x181);
/* set initial color to white */
XMC_BCCU_CH_SetTargetIntensity(R_LED1_CH, 0x555);
XMC_BCCU_CH_SetTargetIntensity(G_LED1_CH, 0x555);
XMC_BCCU_CH_SetTargetIntensity(B_LED1_CH, 0x555);
/* Start linear walk */
XMC_BCCU_ConcurrentStartLinearWalk(BCCU0, 0x181);
/* UART configuration */
uart_config.data_bits = 8U;
uart_config.stop_bits = 1U;
uart_config.baudrate = 115200;
uart_config.oversampling=16U;
uart_config.parity_mode=XMC_USIC_CH_PARITY_MODE_NONE;

/* Configure TX pin */
tx_pin_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT7;
XMC_GPIO_Init(XMC_GPIO_PORT1,2, &tx_pin_config);

/* Configure RX pin */
rx_pin_config.mode = XMC_GPIO_MODE_INPUT_INVERTED_TRISTATE;
rx_pin_config.output_level=XMC_GPIO_OUTPUT_LEVEL_HIGH;
rx_pin_config.input_hysteresis=XMC_GPIO_INPUT_HYSTERESIS_STANDARD;

XMC_GPIO_Init(XMC_GPIO_PORT1,3, &rx_pin_config);

XMC_UART_CH_SetInputSource(XMC_UART0_CH1,XMC_UART_CH_INPUT_RXD,USIC0_C1_DX0_P1_3);


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

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

/*Set service request for transmit interrupt */
XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH1, XMC_USIC_CH_INTERRUPT_NODE_POINTER_TRANSMIT_BUFFER , 1U);

/*Set service request for receive interrupt and enable receive interrupt events */
XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH1, XMC_USIC_CH_INTERRUPT_NODE_POINTER_RECEIVE, 0U);
XMC_USIC_CH_SetInterruptNodePointer(XMC_UART0_CH1, XMC_USIC_CH_INTERRUPT_NODE_POINTER_ALTERNATE_RECEIVE, 0U);
XMC_USIC_CH_EnableEvent(XMC_UART0_CH1, (uint32_t)((uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE | (uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE));

/*Set priority and enable NVIC node for transmit interrupt*/
NVIC_SetPriority((IRQn_Type)10, 3U);
NVIC_EnableIRQ((IRQn_Type)10);

/*Set priority and enable NVIC node for receive interrupt*/
NVIC_SetPriority((IRQn_Type)9, 3U);
NVIC_EnableIRQ((IRQn_Type)9);
uint32_t read_data = 0x0000;
/*Disable both standard receive and alternative receive FIFO events */
XMC_USIC_CH_DisableEvent(XMC_UART0_CH1, (uint32_t)((uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE | (uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE));

/* if (XMC_UART_CH_GetStatusFlag (XMC_UART0_CH1) & XMC_UART_CH_STATUS_FLAG_RECEIVER_START_INDICATION)
{
read_data = XMC_UART_CH_GetReceivedData (XMC_UART0_CH1);
while (!XMC_UART_CH_STATUS_FLAG_RECEIVE_FRAME_FINISHED);
XMC_UART_CH_ClearStatusFlag (XMC_UART0_CH1, XMC_UART_CH_STATUS_FLAG_RECEIVER_START_INDICATION);
}*/

/*Read received data */
read_data = XMC_UART_CH_GetReceivedData(XMC_UART0_CH1);

/*Enable transmit buffer interrupt */
XMC_USIC_CH_EnableEvent(XMC_UART0_CH1, (uint32_t)XMC_USIC_CH_EVENT_TRANSMIT_BUFFER);
// receiving commands from pc and change colors according to colors//

if (read_data==0x40)
{ //load the parameters for color red
XMC_BCCU_CH_SetTargetIntensity(R_LED1_CH, 0xFFF);
XMC_BCCU_CH_SetTargetIntensity(G_LED1_CH, 0x000);
XMC_BCCU_CH_SetTargetIntensity(B_LED1_CH, 0x000);
//activate color red
XMC_BCCU_ConcurrentStartLinearWalk(BCCU0, 0x181);
}

else if (XMC_UART_CH_GetReceivedData(XMC_UART0_CH1) == 0x50)
{
//load the parameters for color green
XMC_BCCU_CH_SetTargetIntensity(R_LED1_CH, 0x000);
XMC_BCCU_CH_SetTargetIntensity(G_LED1_CH, 0xFFF);
XMC_BCCU_CH_SetTargetIntensity(B_LED1_CH, 0x000);
//activate color green
XMC_BCCU_ConcurrentStartLinearWalk(BCCU0, 0x181);
}
else if (XMC_UART_CH_GetReceivedData(XMC_UART0_CH1) == 0x50)
{
//load the parameters for color blue
XMC_BCCU_CH_SetTargetIntensity(R_LED1_CH, 0x000);
XMC_BCCU_CH_SetTargetIntensity(G_LED1_CH, 0x000);
XMC_BCCU_CH_SetTargetIntensity(B_LED1_CH, 0xFFF);
//activate blue color
XMC_BCCU_ConcurrentStartLinearWalk(BCCU0, 0x181);
}



/* Send a message via UART periodically */
SysTick_Config(SystemCoreClock / TICKS_PER_SECOND);

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


Best Regards
0 Likes