Tutorial: Bits and Pins with Kinetis and the FRDM-KL25Z Board

In “Optimizing the Kinetis gcc Startup” I stripped down the fat of my startup code. Now time to add some useful things. And what does a microcontroller like the KL25Z on the Freedom FRDM-KL25Z board have: Pins! And this means I have bits to set and read :-).

FRDM-KL25Z Board

FRDM-KL25Z Board

So this post is about how to use digital I/O pins on the KL25Z to either turn on or off, or to read in values. In the LED tutorial I used my LED component to control them, but of course it is possible to do that kind of thing on a lower level: BitIO_LDD.

Note: I assume that you are familiar with the basics like creating a Processor Expert project, generating code and debugging it. If not, please see one of my earlier tutorials: Enlightening the Freedom Board

BitIO_LDD for an Output Pin

The BitIO_LDD is included in CodeWarrior for MCU10.3. Adding that component to the project is easy from them Components Library View:

Adding BitIO_LDD Component

Adding BitIO_LDD Component

❗ There is as well a BitsIO_LDD component available (notice the ‘s’). This one is able to deal with multiple bits in a port, but we want here just to do it with a single bit.

This adds it to my project:

BitIO in Project

BitIO in Project

Time to configure it! I map it to the Red LED on my FRDM-KL25Z board which is connected to pin PTB18. For this I use the ‘Expert’ mode, give it a name (“RED”), assign it to PTB18, name the (optional) signal name and set it to output. I enable ‘Auto Initialization’ so the Processor Expert startup code initializes the pin for me:

Configured Pin for Red LED

Configured Pin for Red LED

Time to try it out! For this I add two lines of code to the main() routine:

int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  RED_SetVal(RED_DeviceData);
  RED_ClrVal(RED_DeviceData);

 /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
 /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
 #ifdef PEX_RTOS_START
 PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
 #endif
 /*** End of RTOS startup code.  ***/
 /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
 for(;;){}
 /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

❓ Wondering about the RED_DeviceData parameter? The logical device drivers (LDD) components in Processor Expert need this. I will explore things how this can be optimized later on as the overhead caused by this is really not good even for such a powerful ARM Cortex-M0+ microcontroller.

Time to create code (selecting the ProcessorExpert.pe file and context menu t ‘Generate Processor Expert Code’, build it and download it. The code should turn on the RED led, and then turn it off. Simple as that :-).

The same way as of above, I add a BitIO_LDD for Green (pin PTB19) and Blue (pin PTD1):

Red, Green and Blue LED as BitIO_LDD

Red, Green and Blue LED as BitIO_LDD

BitIO_LDD for an Input Pin

Now I want to use a pin as input. As the FRDM-KL25Z has no dedicated button, I’m going to use the Reset button (SW1) instead which is connected to PTA20:

SW1 on the FRDM-KL25Z Board

SW1 on the FRDM-KL25Z Board

Again I add a BitIO_LDD to my project and configure it:

SW1 connected to PTA20

SW1 connected to PTA20

Now I have a little problem, as PTA20 is configured as reset pin for the CPU. So I need to tell the CPU component that I’m using the reset pin for my purpose. For this I select the Cpu in the Components view and use the Inspector menu:

CPU in Components View

CPU in Components View

Here it tells me again that I’m ‘double booking’ that pin:

Cpu with Component Inspector

Cpu with Component Inspector

What I need to do is to disable it:

Disabled Reset Pin

Disabled Reset Pin

💡 Disabling the Reset Pin has other impact too, see “How (not) to Secure my Microcontroller”

But wait: there is one more setting:

Reset Pin Function Disabled

Reset Pin Function Disabled

Normally would need to configure an input pin with an internal pull-up resistor or similar. But SW1 already has a 10k Ohm pull-up resistor R4 attached:

Target Reset and Bootloader Push Button

Target Reset and Bootloader Push Button

Time to test it in my code.

I change the above code in main() now to turn on the LED if I press the button, plus to prove that pressing the reset button does *not* cause a reset, I turn on the green LED for a second (using the Wait component):

Added Wait Component

Added Wait Component

And my code looks like this:

  GREEN_ClrVal(GREEN_DeviceData); /* turn on green LED */
  WAIT1_Waitms(1000);
  GREEN_SetVal(GREEN_DeviceData); /* turn off green LED */
  for(;;) {
    if (SW1_GetVal(NULL)==0) { /* button low level => pressed */
      RED_ClrVal(RED_DeviceData); /* LED cathode is connected to microcontroller pin: low level turns it on */
      BLUE_SetVal(BLUE_DeviceData); /* turn off blue led */
    } else {
      RED_SetVal(RED_DeviceData); /* turn off red led */
      BLUE_ClrVal(BLUE_DeviceData); /* turn on blue led */
    }
  }

While reset/SW1 is not pressed, the blue LED is on:

Blue LED on if button is not pressed

Blue LED on if button is not pressed

Pressing the reset/SW1 button turns the red LED on:

Pressing SW1 turns Red LED on

Pressing SW1 turns Red LED on

Hardware Settings

I know now how to configure pins for input or output, and how to set or read them. But there is more you typically can configure. Things like pull-up or pull-down resistors, slew rates or driving strength. All these settings are missing in the above components. But they are available in the non-LDD (Logical Device Driver) land :-(.

💡 For other Processor Expert supported (non-LDD) cores (like the S08), such hardware settings can be configured in the BitIO component.

So it looks like these important settings are missing here. I was lucky that my reset pin in the example above had a pull-up resistor on the board. But I know that the hardware supports an internal pull-up (or pull-down) resistor. So it should be possible to establish a ‘resistor-less’ switch between GND and pin 14 on the J2 header on the FRDM-KL25Z board:

J2 with switch connection

J2 with switch connection (Source: Freescale FRDM-KL25Z Schematics)

D15 is connected to the PTE1 pin on the KL25Z. And I want it as an input with an internal pull-up. So how to configure it? The trick is to use Init_GPIO with pin sharing.

Pin with Pin Sharing

First, I add a normal BitIO_LDD for my new switch SW2, and configure it for PTE1:

SW2 Configured

SW2 Configured

I’m now going to configure the hardware (internal pull-up) in an Init_GPIO.

Init_GPIO

Init_GPIO is a component which only performs initialization, nothing else. So I add it to my project:

Init_GPIO Component Added to Project

Init_GPIO Component Added to Project

Next, I configure it to use PTE1 with enabled pull-up resistor:

Init of PTE1 with Error

Init of PTE1 with Error

But: it reports an error as PTE1 is already used by my BitIO_LDD component. How to solve this? The solution is to configure the pin for ‘pin sharing’: this means that several Processor Expert components can share that pin. To enable pin sharing I select the context menu on that pin:

Enabling Pin Sharing

Enabling Pin Sharing

Now notice the subtle color change of that icon which can easily be missed:

Pin Sharing Enabled Icon

Pin Sharing Enabled Icon

But: it means that it is enabled for sharing, and the error from above is fixed :mrgreen:.

Time to generate Processor Expert code and to update my source:

  GREEN_ClrVal(GREEN_DeviceData); /* turn on green LED */
  WAIT1_Waitms(1000);
  GREEN_SetVal(GREEN_DeviceData); /* turn off green LED */
  for(;;) {
    if (SW1_GetVal(SW1_DeviceData)==0) { /* button low level => pressed */
      RED_ClrVal(RED_DeviceData); /* LED cathode is connected to microcontroller pin: low level turns it on */
    } else {
      RED_SetVal(RED_DeviceData); /* turn off red led */
    }
    if (SW1_GetVal(SW2_DeviceData)==0) { /* button low level => pressed */
      BLUE_SetVal(BLUE_DeviceData); /* turn off blue led */
    } else {
      BLUE_ClrVal(BLUE_DeviceData); /* turn on blue led */
  }
}

Time again to try it out on the board: it will turn on the green LED for a second and then turn it off. Then the LED will be off. If I press SW1, the led will be red (as above).

LED off with open switch

LED off with open switch

If make put PTE1 to ground with a wire (emulating a switch), the LED will turn blue:

Blue LED on with switch closed

Blue LED on with switch closed

Summary

Doing Bit I/O really is easy with the Eclipse based CodeWarrior for MCU10.x. The project and source files created and discussed is available on GitHub here.

Happy Biting 🙂

PS: As noticed earlier: The LDD approach comes with some avoidable overhead. I preparing a follow-up article on this how to get things optimized, so it fits my needs and expectations. Stay tuned …

82 thoughts on “Tutorial: Bits and Pins with Kinetis and the FRDM-KL25Z Board

  1. Sorry again. The way this reply feature laid out on my computer, it appeared that my last comment, would appear before the comment now showing above it. So please delete this and the above two comments.

    Are you having a good day in spite of all this? 😉

    Like

      • I don’t blame you for being confused. I have that effect on people. 😉

        My original question was about using PTB8-11 as pull down inputs. I have since learned that it is not possible to set them as pull down. So my question has been answered from another source.

        Nevertheless, THANK YOU for your help to so many people through this blog and the excellent tutorials you have provided.

        Like

  2. Hello Erich
    I take advantage of this recent article to repeat my request about the possibility to use both USB devices on the card
    In other words:
    There are two excellent examples:
    Tutorial: A Shell for the Freedom KL25Z Board
    Tutorial: USB CDC with the KL25Z Freedom Board
    I tried to combine the two examples, but I could not get it to work
    Can you put on your work list an example that links the two tutorials in order to transmit from a usb and receive from the other and vice versa ,obviously with FreeRTOS?
    Thanks
    Carlo

    Like

  3. Pingback: Thumbs up with Assembly on ARM Cortex | MCU on Eclipse

  4. Pingback: Arduino Data-Logger Shield with the FRDM-KL25Z Board | MCU on Eclipse

  5. Pingback: LED’s for Kinetis, simplified | MCU on Eclipse

  6. Pingback: Using the Reset Button on the Freedom Board as User Button | MCU on Eclipse

  7. Pingback: Added Write Protection Pin to FatFsMemSDHC | MCU on Eclipse

  8. Hi Eric,

    I am trying to make the Freescale Processor Expert SDHC examples work at 50 MHz. My card reports “High speed: true”. Unfortunately at 50 MHz I get a “Command or data timeout” error. Now I noticed that the example code tells me to use the FAST slew rate setting for all SDHC pins. Therefore I tried your trick with adding an Init_GPIO component with pin sharing enabled for the SDHC pins. I enabled the 5 pins and only changed the slew rate setting. For some reason the generated Init method remains empty and my SDHC still does not work at 50 MHz. Any idea what the problem may be?

    Thank you in advance,
    Anguel

    Like

    • Hi Anguel,
      my K60 only allows me a SDHC frequency up to 12 MHz, so I cannot try out a value higher than that. Can you confirm that it works with a lower MHz (say 12 MHz)?

      Erich

      Like

      • My experience is based on the TWR-K70 SDHC demo project found in C:\Freescale\CW MCU v10.4\MCU\CodeWarrior_Examples\Processor_Expert\Kinetis\TWR-K70FN1M\SDHC. I have also adapted the project to my Kwikstik (K40). The demo project writes and then reads fine at 25 MHz on Kwikstik (K40) and at 15 MHz on TWR-K70, these MHz values are dictated by the main clocks of the boards.

        Then I tried to go high speed, i.e. to 50 MHz on Kwikstik and 30 MHz on TWR-K70 by using the SDHC_SelectBusClock() method as described in the SDHC LDD component help. This method seems to setup the device to high speed (no error). But then I get “ERROR Command or data timeout” (LDD_SDHC_ERR_TIMEOUT) which is returned by the SDHC_GetError() method called in the SD_Wait() method wich is called right after SDHC_TransferBlocks() which is called by SD_TransferBlock() with WRITE parameter called by SD_WriteBlockPart(). I also found out that if I run the writing part in a loop at 30 MHz on TWR-K70 the error does not occur each time, but in most cases it does. If I run it at 50 MHz on the Kwikstik the error always occurs. The strange thing is that although this error occurs, the test data (I vary this inside my loop) can be successfully written to and then read from the SD card.

        I am not sure where the error actually comes from although it seems related to the bus speed I use. The only hint I found was that the code comments in the SDHC LDD help say that HIGH slew rate should be set on all pins but they don’t say how to do this. So I found your post and tried to set it through the Init_GPIO components by only changing the slew rate setting of the pins used for SDHC. Unfortunately, this did not seem to work and it does not generate any code in the Init() method of the Init_GPIO component, this method remains empty after PEx code generation. Any hints are welcome!

        Anguel

        Like

        • Hi Anguel,
          ah, ok, this makes it now clear. Unfortunately I do not have the K70 with me so I cannot try things. And I would have changed the slew rate as you did in the shared component. But it is not clear to me why this is necessary for SDHC operation. I guess this would be a question to Freescale.

          Like

  9. I did some more research and found out that there seems to be a CMD line conflict according to the error bits set by the SDHC controller. This may be caused by the high bus speed used I think, maybe I should also check with other SD cards, although this one reports to be high speed… It also turned out that the slew rate is actually set by PEx, but not in the Init_GPIO component’s Init() method but in the CPU.c in the PE_low_level_init() method. It also turns out that fast slew rate seems to be the default for the Kinetis (K40 at least). So the problem is not the slew rate itself. Things are so complex that it can be anywhere.

    Like

  10. Hi.
    I’ve read the spect of KL05 and it says that theres a way to get 25mA from PTA12, PTA13, PTB0 and PTB1 by setting up the PTx_PCRn[DSE], but I cant find out how to get them with PE. Any help about it?

    Like

  11. Hey Erich,
    Thanks for the project that you made, I am staring up with this kit (FRDM-KL25Z), and I am trying to learn from this tutorial.
    1. I installed the necessary component, i.e Component: BitIO_LDD on process export, and also insert the extra code that you provided ( RED_SetVal(NULL);  RED_ClrVal(NULL);)
    2. I connect it with IAR Embedded workbench IDE to Debug and install the code on the kit, but I get two errors:
    Error[Li005]: no definition for “RED_ClrVal”
    Error[Li005]: no definition for “RED_SetVal”

    Can you please tell me how I can make this thing work.
    PS: I have followed the tutorial on the link https://mcuoneclipse.com/2013/01/31/tutorial-iar-freertos-freedom-board/ ………. and managed to turn on and off the led.
    ___________________________________________________________________________
    ____________________________________________________________________________
    In addition to this project, I am trying to write a code as a Data logger: to write and read from SD card from this kit………. I have tried to look this tutorial, that claims it will do data logging from Arduino kit…………. https://mcuoneclipse.com/2012/11/18/arduino-data-logger-shield-with-the-frdm-kl25z-board/ I havent tried it yet.

    But what I would really like to do is to write a C code, debug and download it on IAR Embedded workbench IDE without using process Expert or any other software.

    For example I was able to use only the IAR Embedded workbench IDE and turn on the RGB led using this code:

    /* User includes (#include below this line is
    /*————————————-*/
    #include “common.h”
    #ifdef CMSIS
    #include “start.h”
    #endif
    #define RED_PIN_A 18
    #define GREEN_PIN_A 19
    #define BLUE_PIN_A 1

    #define RED_LED_ON_F() GPIOB_PCOR = (1<<RED_PIN_A)
    #define GREEN_LED_ON_F() GPIOB_PCOR = (1<<GREEN_PIN_A)
    #define BLUE_LED_ON_F() GPIOD_PCOR = (1<<BLUE_PIN_A )
    #define RED_LED_OFF_F() GPIOB_PSOR = (1<<RED_PIN_A )
    #define GREEN_LED_OFF_F() GPIOB_PSOR = (1<<GREEN_PIN_A)
    #define BLUE_LED_OFF_F() GPIOD_PSOR = (1<<BLUE_PIN_A)
    int main (void)
    {
    uint32 i = 0;
    char ch;
    #ifdef CMSIS // If we are conforming to CMSIS, we need to call start here
    start();
    #endif
    printf("\n\rRunning the ZEKI4 project.\n\r");
    GPIOB_PDDR |= ((1 << RED_PIN_A) | (1 << GREEN_PIN_A));
    GPIOD_PDDR |= (1 << BLUE_PIN_A);
    PORTB_PCR18 |= PORT_PCR_MUX(1); //muliplexer
    PORTB_PCR19 |= PORT_PCR_MUX(1);
    PORTD_PCR1 |= PORT_PCR_MUX(1);
    }

    As I told you I am new to the kit ……… can you please suggest how I can proceed.
    Thanks for your help

    Like

    • Hi Addis_a,
      what is wrong with using Processor Expert? It generates the source code for you, so you will not have all the issues you are facing now. Processor Expert works nicely with IAR, so you have the freedom of choice. And you can use and change the source code it generates. So I suggest that you try it out.

      Like

    • I’m using your code from github. Imported without any modifications. Reset function is disabled in both places in Cpu component. I wonder if it can be an issue with IDE version. I’m using CodeWarrior 10.4. Board is FRDM KL25Z RevA.

      Like

        • I see now what you are saying. The code on GitHub incorporates already the second part, where I have added an additional switch.
          If you run it on a unmodifed board (without additional switch), then
          – no LED is on after reset
          – if you press the reset button, and as long as you press reset, then the red LED is on.
          – the blue led is only on if you press the second button (which you have to add to the board)
          See the code in main() of the GitHub project.
          I hope this helps.

          Like

    • I understand how it should work. When PE1 pin is open – blue LED is off. But when I’m pressing reset button (no mater if PE1 is open or shorted to GND) red LED is not turning on. The green one is always flashing for 1s after button is pressed. I suppose MCU is still resetting.

      Like

      • Yes, this really sounds like reset is still active.
        You could verify this if you debug your code: halt the debugger in main, then press the reset switch.
        If it resets, then you will see it.

        Like

    • There is one change I have made in your project and then ignored it:) I am using USBDM firmware instead of P&E Micro OpenSDA. It looks like with USBDM it is not possible to change reset pin functionality. When I have disabled reset pin using P&E OpenSDA and then tried to flash MCU using USBDM – it was not possible to connect to the target.
      Using USBDM is important in my project as I would like to flash external MCU on my custom board. Is there any option to fix it?

      Like

    • It programm with USBDM but reset pin is still active. So only with PE micro OpenSDA I can use Reset pin as GPIO. Not satisfying solution. Has anyone found workaround for it?

      Like

      • Hi Adam,
        It seems like USBDM is not programming the flash configuration block? Can you check what gets flashed on your target? So this indeed could be an USBDM problem. I suggest you might check it with pgo on freescale community community/bdm?

        Like

  12. Pingback: Optimized BitIO_LDD Programming with Processor Expert | MCU on Eclipse

  13. My FRDM-KL25Z GPIO_Init component does not have the same controls as the one shown in this tutorial. For example, no pull-up/pull-down selection or interrupt configuration. See screen shot :

    Do I have the wrong version of this component, and how can I get the right one?
    I have CW for MCU 10.5 and added your Processor Expert update files.

    Like

    • Hi Charles,
      that Init_GPIO component is from Freescale, not mine. But you are right: at least in my MCU10.5 I see the same as you: less settings.
      Not sure if this is a bug fix (that there was too much present in the earlier version)?

      Erich

      Like

      • I have looked more closely at the KL25Z data sheet. My reading is that the GPIO ports do not have full functionality on this part. For example, there is no option for pull-down resistors, and only ports A and D support interrupts and DMA requests. So the current Init_GPIO control does appear to offer the correct options. So the question is why your screenshot appears to offer more. Maybe it was taken with a different processor? Or it is an old component that has now been corrected?

        Like

        • I believe I have used that FRDM-KL25Z as shown in that article. But this was back in 2012, so for sure there was a different CodeWarrior version (10.2 I think) involved.

          Like

  14. Hi Erich,
    I’m trying to perform a very basic BitIO_LDD initializiation and usage. I have looked under the ‘Help on Component’ tab for code examples and I am still unable to use this setup verbatim:

    LDD_TDeviceData *bit1Ptr;

    void main(void)
    {

    bit1Ptr = Bit1_Init(LDD_TUserData *)NULL); /* Initialize the pin */
    /* Wait until logical “1” is on the pin */
    while( !Bit1_GetVal(bit1Ptr) );


    }

    Error:
    Multiple markers at the Bit1_init line…
    – Syntax error
    – expected expression before ‘LDD_TUserData’ expected ‘;’ before numeric constant expected statement before ‘)’ token

    After removing thet ‘)’ after the ‘ * ‘,[I can’t figure out why it was necessary], I still am left with the error expected expression before ‘LDD_TUserData’

    Thanks

    Like

  15. Hi,

    I wonder if there is a tutorial that explains the Kinetis programming in c!
    The reason is to better understand the structure of microcontroller and not really programming!

    Thanks,

    Matheus

    Like

    • Hi,
      Kinetis is not really special for C programming. So if you are interested in a tutorial for C programming, there are plenty of it on the Internet.
      But in your second sentence you are more interested in the structure of a microcontroller (than in programming)?
      Now the question is if you are interested in microcontrollers in general, or especially in the ARM Cortex family of microcontrollers?
      If it is the later, then ARM.com has material too, including the architectural manuals and more.
      If it is for microcontrollers in general, there yet again there is plenty of microcontroller material: search for things likd ‘tutorial microcontroller programming’ and you should get something you could start with?

      Like

      • My concern would be how macros are defined, which bits would be set to control something in microcontroller!
        I would not scrutinize datasheet, because it would take too long for a first study!
        Searching, I found this material:

        Click to access 1744358872249.pdf

        Which is very close to what I was looking for!
        I do not intend to program directly in c. I will use the processor expert, but would like to know how things work!

        Regards

        Like

  16. Hello sir How can someone use UART character send froma another microcontroller to control the port of a freescale device. Eg data send from a Beagle Bone Black to contol the port of a freescale. Thank you sir.

    Like

  17. Hi Erich – I am using the freedom KL46Z boar. When I run any code after copying the hex file to the FRDM-KL46Z E: drive (as it appears on my PC), the code appears to only work for a short duration: e.g. I had two successive lines to print a char to a terminal – It only prints the first, each time I reset it just prints the first char. I though it was my uart routine, so I used the code below just to light an led –
    Bit1_SetVal(); switches the led off and Bit1_ClrVal(); switches it on.
    If I do:
    Bit1_SetVal();
    Bit1_ClrVal();
    then the led lights, but if I do say:
    Bit1_SetVal();
    Bit1_SetVal();
    Bit1_ClrVal();
    then it doesn’t light. It is as though the extra delay caused by the extra line of code has stopped the code.
    It seems to be a watchdog type issue, but I have included the default line: PE_low_level_init();

    Here is the code fragment for the led routine:

    /* Write your local variable definition here */

    /*** Processor Expert internal initialization. DON’T REMOVE THIS CODE!!! ***/
    PE_low_level_init();
    /*** End of Processor Expert internal initialization. ***/

    /* Write your code here */
    /* For example: for(;;) { } */
    Bit1_SetVal();
    Bit1_SetVal(); // If I comment this out the led lights
    Bit1_ClrVal();
    for(;;)
    {

    }
    /*** Don’t write any code pass this line, or it will be deleted during code generation. ***/

    Like

  18. Thanks – I’ll check, I can’t seem to enter the debugger (from debug – configurations) so maybe I need to sort that first.

    Like

  19. Hi Erich
    I managed to get some code working – but am interested to know what you think:
    Firstly, the watchdog (COP) was enabled by default.
    To disable it, I had to select the COP component from the expert and then select ‘disabled’ under the ‘Timeout’ setting. (interesting that this is the case)
    Then I got a flashing Led to work (hurrah!)
    After that I had the following response when doing serial comms:
    I used
    AS1_SendChar(‘a’);
    AS1_SendChar(‘b’);
    Only the ‘a’ was sent…
    Then I realized that if I include a delay between sending, then it worked.
    After that I enabled interrupts to use AS1_SendBlock
    If I then do any uart function – either AS1_SendChar or AS1_SendBlock
    The program sends one character and then hangs.
    I still cannot enter debug mode at all and can only drop and drag to the folder.
    Thanks as always for your patience
    Russell

    Like

    • Hi Russel,
      yes, watchpoints are enabled by default by many devices, so you need to make sure it gets disabled if you are not kicking the dog.
      Using the AsynchroSerial component, make sure you have interrupts enabled and that you have enough buffers allocated for Rx and Tx in the component (I belive the default is 1 byte which is not enough in your case). Set it to 32, 48 or 64. Additionally, make sure that interrupts are not disabled in your application. What happens is:
      a) SendChar() puts the character into a ring buffer
      b) The SendChar() method will trigger the UART interrupt
      c) the UART interrupt will send that character (or any others which are in the ring buffer).
      So make sure the ring buffer size is reasonable, and your interrupts are not disabled.

      I hope this helps,
      Erich

      Like

  20. Hi Erich,

    I’ve a doubt regarding KL25z Reset. Port A, pin 20 has the ability to restart the controller instead of manual reset.
    I’ve provided clock to the port A pins and made pin 20 HIGH, but the controller doesn’t seem to reboot itself. Can you suggest me what went wrong or what I’m missing.

    Thank you,

    Regards,

    Naruto Uzumaki 🙂

    Like

    • Hi Naruto,
      so I understand you correctly, you are using PTA20 as output pin and drive it high from the KL25Z itself? So your idea is to do ‘self reset with the reset pin’? If so, then this cannot work, as you then have configured the pin as GPIO and not as reset pin any more. You need to reset the device either with the ARM reset usinig the AIRCR SCB register or not serving the watchdog.
      I hope this helps.

      Like

      • Hi Erich,

        I’ve not configured the pin as GPIO (which is usually done by choosing Alt 1 of multiplexed pin). I’m keeping it in default state, and write HIGH on the pin.

        Regards,

        Naruto

        Like

        • Is reset not low active? And if you have not muxed the pin as output GPIO pin, you won’t be able to write to it (won’t have an effect). Or have you seen an effect on the pin with a scope?

          Like

      • No I didn’t get any signal while writing onto the pin.

        Hence, it has no effect on the controller.

        I’ll with one of you approaches, i.e., using AIRCR SCB register.

        I’ve searched in the datasheet, but couldn’t find information about AIRCR SCB. Where can I find the information, Erich?

        Thanks for you help!

        Regards,
        Naruto

        Like

        • Hi Naruto,
          let me write up an quick article about that topic and how to use the AIRCR. You should see an article about that tonight (my time). OK?

          Like

        • If you are writing about software resets, you’ll probably mention that you can read the System Reset Status Registers to determine the reset reason. I print these as a matter of course at boot time – it can be useful to see if I have suffered a watchdog reset, in particular. Also the very wierd “core lockup” reset I had once.

          Like

  21. Hello, after loading your program my freescale (kl25z) remains in bootloader mode and freescale is no longer viewed as Kinetis. What can I do? thank you.

    Like

  22. Hi Erich,
    Thanks again for the wonderful blog. I need help from your side.

    I am using a reset switch on my custom board which i am using to go back to factory default settings.
    If the switch is pressed continuously for time > 5 seconds, i have to reset. I am using FreeRTOS as well. Can you please help me decide how to design this? it will be of great help to me. i have something in my mind but I am sure that it is not the right thing. Your help will be much appreciated.

    Liked by 1 person

  23. Hello Erich,

    I have followed a couple of times your tutorial, specifically sections:
    BitIO_LDD for an Output Pin
    BitIO_LDD for an Input Pin

    But the example for “BitIO_LDD for an Input Pin” just don’t work for me, I tried hardconding the bit and it works, but I just use the “(SW1_GetVal(SW1_DeviceData)==0)” statement and it just don’t follow if I press the reset button.

    My settings are:
    Windows 7 64 bit.
    CodeWarrior for MCU Version: 10.6 Build Id:140329.

    Thank you.

    Like

  24. Hello,
    I have a 15 segment led char display. I have connected it to a MK10DN64 MCU on ports PTA, PTB, PTD and PTE. i use BitsIO_LDD to configure the pins and now i have 8 different generated files of .c and .h . i want to display different alpha-numeric characters. How can i do it.need some info.

    Thanks,

    Like

  25. continue of above comment,
    Port LED Pin
    PTA18 9
    PTA19 14
    PTB0 15
    PTD0 10
    PTD1 13
    PTD2 12
    PTD3 1
    PTD4 8
    PTD5 2
    PTD6 3
    PTD7 7
    PTE16 4
    PTE17 5
    PTE18 6
    PTE19 11

    Like

    • It is probably better if you control each pin individually instead as a byte. That way you can turn on/off each segment as you want. You need to write a routine which writes each digit, and for this it needs to turn on/off individual pins.

      Like

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.