It’s Relax Time: Blinky LED

OK, let’s start to play with the Relax Kit. It’s Relax Time… 🙂

Let’s start with the simplest thing…just blink the LED, just say hello to the world. Relax Kit has 2 LED connected to P1.0 and P1.1. Here is the schematic:

With this connection, we need to give logic HIGH the pin if want to turn on the LED, and logic LOW if want to turn off the LED.


Before we can use the port, we have to do some configuration to the related registers. Not like standard C51 family, that no need to set a register before read or write to the port. But, off course, we can not set mode for C51 port, like open drain, push pull etc. Only has internal pull up.

There are 8 registers to configure XMC4500 port:

  • Port Input/Output Control Register (IOCR)
  • Pad Drive Mode Register (PDR)
  • Pin Function Decision Control Register (PDISC)
  • Port Output Register (OUT)
  • Port Output Modification Register (OMR)
  • Port Input Register (IN)
  • Port Pin Power Save Register (PPS)
  • Port Pin Hardware Select Register (HWSEL)

IOCR will set a port as standard input/output or alternative function. As input port, it can the port can be set as direct input or inverted input, with or without internal pull up/down. For output function, we can set output mode as push pull or open drain. The port also can be configured as alternative function in output mode, like PWM outputm clock output etc.

There are 4 registers of  IOCR:

  • IOCR0: controls pin [3:0]
  • IOCR4: controls pin [7:4]
  • IOCR8: controls pin [11:8]
  • IOCR12: controls pin [15:12]

XMC4500 has 8 ports: P0, P1, P2, P3, P4, P5, P6, P14, and P15. Each ports can have until 16 pin (bit), depends on the XMC4500 package. Detail in the XMC manual.

IOCR0 structure (others are the same)

PC0, for pin 0, PC1 for pin 1 and so on, rw can be read or write, r read only bit and bit with 0 value should write 0.

And the input/output configuration:

PDR is used to select output drive strength and the slew rate.

There are 2 PDR registers: PDR0 (for bit 0-7) and PDR1 (for bit 8-15). PDR0 is used for P0-P6, and  PDR1 only use for P0-P3 and P5, the port that has more than 8 pin. P14 dan P15, that use for analog analog, did not have PDR. PDRx register structure:

The primary use for PDSIC register is to disable/enable the digital pad structure in shared analog and digital ports, see the dedicated description of the Pn_PDISC (n=14-15) register of the analog ports. PDSIC structure:

OUT register determines the value of a GPIO pin when it is selected by Pn_IOCRx as output. Writing a 0 to a Pn_OUT.Px (x = 0-15) bit position delivers a low level at the corresponding output pin. A high level is output when the  corresponding bit is written with a 1. Note that the bits of Pn_OUT.Px can be individually set/reset by writing appropriate values into the port output modification register Pn_OMR, avoiding readmodify-write operations on the Pn_OUT, which might affect other pins of the port. The Pn_OUT is also used to store/drive a defined value for the input in Deep Sleep mode. For details on this see the Port Pin Power Save Register. That is also the only use of the Pn_OUT register in the analog and digital input ports P14 and P15.

OMR register contains control bits that make it possible to individually set, reset, or toggle the logic state of a single port line by manipulating the output register.

To select for each pin, PSx bit and PRx bit can be programmed as below:

PPS registers is used for power save or sleep mode, detail information can be read from XMC4500 manual, also for HWSEL register. 🙂


OK, let’s start to make a program. In this program we will just to blink both of LED on the Relax Kit board, when P1.0 turned ON, P1.1 will turned OFF and vice versa.

We will set P1.0 and P1.1 as output with push pull mode. PC0 in IOCR0 will has value 10000B. In C we can write as:

  PORT1->IOCR0 = 0x80UL << 0; //P1.0 output, push pull   
  PORT1->IOCR0|= 0x80UL << 8; //P1.1 output, push pull   

PDR register is set to select strong driver, PD0 and PD1 will set to 2.

  PORT1->PDR0 = 0x02UL << 0; //P1.0, pad driver strong   
  PORT1->PDR0 |= 0x02UL << 8; //P1.1, pad driver strong   

To turn ON and turn OFF the LED, we will not use OUT reguster, but we will use OMR register, because we will control per pin. Set PRx=0 and PSx=1 will turn on the LED, and PRx=1 and PSx=1 will turn off the LED.


PORT1->OMR = (1UL<<0)|((1UL<<0)<<16); // P1.0 ON
PORT1->OMR = (1UL<<1)|((1UL<<1)<<16); // P1.1 ON


PORT1->OMR = (1UL<<0)<<16; // P1.0 OFF
PORT1->OMR |=(1UL<<1)<<16; //P1.1 OFF

Then, make a new project with DAVE IDE, and select Empty Main Project:

And write this in main.c and build the project.

#include  //SFR declarations of the selected device
void thedelay (unsigned long delay)
  while (delay–)

int main(void)
  PORT1->IOCR0 = 0x80UL << 0; //P1.0 output, push pull   
  PORT1->IOCR0|= 0x80UL << 8; //P1.1 output, push pull   
  PORT1->PDR0 = 0x02UL << 0; //P1.0, pad driver strong   
  PORT1->PDR0 |= 0x02UL << 8; //P1.1, pad driver strong   
      PORT1->OMR = (1UL<<0)|((1UL<<0)<<16); // P1.0 ON
      PORT1->OMR |=(1UL<<1)<<16; //P1.1 OFF
      PORT1->OMR = (1UL<<0)<<16; // P1.0 OFF
      PORT1->OMR = (1UL<<1)|((1UL<<1)<<16); // P1.1 ON
  return 0;


Connect the Relax Kit with the PC/Laptop. If we installed J-Link driver when installing DAVE 3, PC/Laptop will detect it. Just click Debug button/menu.

If BlinkyLED didn’t appear in the debugger, just compile and build our project before start download or debugging. If present, just click BlinkyLED. Select Infineon XMC Relax Kit as target. Then click Debug button. DAVE will download the program into flash memory of XMC4500. After that will show debug window:

From Debug window, click Resume(F8) to run the program. We also can run the program step by step  (Step Into), step Over, or step return, reset the target and inspect the value of declared variables on the program, register value, and the program in assembly.

Check out the video:

2 Responses

  1. Thanks dude!!! perfect tutorial !

  2. Hi U-2 Man,
    thanks for this one.
    Tried to make my XMC4500 RelaxKit blink for hours using the Infineon tutorials (crap) and almost gave up. This one worked great 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: