6 years, 9 months ago.

How to use PortOut with the FRDM-KL05Z

I am trying to write to pins 0 - 10 of port B of this kl05z platform at a go unsuccessfully, the code in the example doesn't compile I have this

I have my code as in this snippet

#include "mbed.h"
#define LED_MASK 0xfff
PortOut ptb(PTB, LED_MASK);

int main(){
    while (true) {
           ptb = LED_MASK;
           ptb = 0;

how is Port B, or any other port defined in the headers because PortOut expects the first argument to be a port definition?

I get this error:

Error: No instance of constructor "mbed::PortOut::PortOut" matches the argument list in "main.cpp", Line: 4, Col: 13

1 Answer

6 years, 9 months ago.

The names are PortA, PortB, etc. Then it compiles at least for me. Good chance no one actually tested this after the code was refactored, it should definately work, but please report back if it does :).

Accepted Answer

Yes!! thanks Erik, thank you so much, that works. So if I may ask, in which file are these ports (PortA, PortB) defined?

posted by David Karibe 26 Feb 2014

Somewhere deep in the source code ;)


And yeah I now see it is in the common KLXX code, don't try to use other ports than A and B for the KL05, it will compile, and most likely crash immediatly.

posted by Erik - 26 Feb 2014

Aaaam, why doesn't it work for other ports? anyway, I am only using PortB for LED software driver, just in case i need to use other ports in another project

posted by David Karibe 27 Feb 2014

Simple answer: They don't exist. PortA and PortB should work fine, but PortC and higher don't exist on the KL05.

posted by Erik - 27 Feb 2014