Blinking LED on KL25Z - KDS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Blinking LED on KL25Z - KDS

Jump to solution
5,656 Views
wojciech22a
Contributor II

I wrote a program for blinking LED. The program does not work:

#include "Cpu.h"

#include "Events.h"

//#include "Bit.h"

/* Including shared modules, which are used for whole project */

#include "PE_Types.h"

#include "PE_Error.h"

#include "PE_Const.h"

#include "IO_Map.h"

void opz(int ile)

{

  int p;

  for(p=0;p<ile;p++)

  {

  }

}

void ledkonf(void)

{

  PORTB_PCR18=PORTB_PCR18 &~(1<<10) &~(1<<9) | (1<<8);

  GPIOB_PDDR=GPIOB_PDDR | (1<<18);

}

void swiec(void)

{

   opz(100000);

   GPIOB_PDOR=GPIOB_PDOR|(1<<18);

   opz(100000);

   GPIOB_PTOR=GPIOB_PTOR|(1<<18);

   opz(100000);

}

int main(void)

{

#ifdef PEX_RTOS_START

    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */

#endif

   ledkonf();

  for(;;){

   swiec();

  }

}

But when I added element BitIO_LDD in the Processor Expert, the program works, and the only new element of the program is generated file Bit.h. When I create a project without Processor Expert, the program does not work either. Why is it like that? Please help!

Labels (1)
0 Kudos
1 Solution
3,240 Views
EarlOrlando
Senior Contributor II

Hello,

Please take a look into the thread below, specially the post marked as correct answer. It explains how to get a LED and a push button working in baremetal. The explanation is based in the FRDM-KL05Z but it works exactly the same way to the KL25Z.

Re: Port configuration

Best regards,

Earl.

View solution in original post

0 Kudos
3 Replies
1,206 Views
fireflies_at_night
Contributor II

Also, just wanted to add to this post. Learning from this helpful link, I see that the three LEDs (blue, green and red) are all having common anode configuration. This means that (counter-intuitively) all the LED's must be driven high to switch off (using PSOR registers) and driven low to switch on (using PCOR registers).

0 Kudos
3,241 Views
EarlOrlando
Senior Contributor II

Hello,

Please take a look into the thread below, specially the post marked as correct answer. It explains how to get a LED and a push button working in baremetal. The explanation is based in the FRDM-KL05Z but it works exactly the same way to the KL25Z.

Re: Port configuration

Best regards,

Earl.

0 Kudos
3,240 Views
mjbcswitzerland
Specialist V

Hi

Probaby the reason why the code doesn't work is because the GPIO is not being enabled/clocked.

Add

SIM_SCGC5 |= SIM_SCGC5_PORTB;

at the start of ledkonf().

[if there is a compilation error check the name of the register/bits in the header that you use and modfiy as required]

Regards

Mark

Kinetis: µTasker Kinetis support

KL25: µTasker Kinetis FRDM-KL25Z support  / µTasker Kinetis TWR-KL25Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market