PortOut misunderstanding

01 Sep 2010

Hi to all

I am fighting now with PortOut and PortInOut libraries ...

I have simple prog.

#include "mbed.h"

#define LED_MASK 0x00000ff0

PortOut IoPort(Port0, LED_MASK);

DigitalOut myled(LED1);


int main() {
    while(1) {              
        myled = !myled;
        wait(0.5);
        IoPort = 0xff;
        wait(0.5);
        IoPort = 0xaa;
        wait(0.5);
        IoPort = 0x55;
    }
}
I set 8bit (ports p30, p29, p8, p7, p6, p5, p28, p27) mask on port0 but when I try to set 8 bit value I get only first 4 bite working

where is problem ?

01 Sep 2010

Hi Tomislav,

You still need to write the bits in the appropriate positions. The mask just defines which parts are updated. So, in your example, you would write as:

#include "mbed.h"

#define LED_MASK 0x00000ff0

PortOut IoPort(Port0, LED_MASK);

DigitalOut myled(LED1);


int main() {
    while(1) {              
        myled = !myled;
        wait(0.5);
        IoPort = 0xff0;
        wait(0.5);
        IoPort = 0xaa0;
        wait(0.5);
        IoPort = 0x550;
    }
}
That should work!

Simon

01 Sep 2010

Thanks Simon for great support  32bit controllers ale little tricky for me now as a total newbie

this is also reason why i cant get lcd working > from other thread :)

if you come to Prague I have beer or two for you ;)

01 Sep 2010

Another hint needed ...

how to change pullup/pulldown settings in PortInOut library ?

When I set the mask LEDs starts to glow a little ( deffault pullup? )

if I use this :

#include "mbed.h"
#define LED_MASK 0x00000ff0

PortInOut IoPort(Port0, LED_MASK);
IoPort.mode(PullDown);
I get compiler error that IoPort is already defined ... is this usage right

01 Sep 2010

Hi Tomislav,

The problem here is that mode() is a method, so you have to call it like any other function (from within a code section). So, for example:

#include "mbed.h"
#define LED_MASK 0x00000ff0

PortInOut IoPort(Port0, LED_MASK);

int main() {
    IoPort.mode(PullDown);
}
That'll then work I suspect.

Simon

01 Sep 2010

works great ... thanks again :)

great service :)

16 Aug 2017

Hi,

I still cannot make the portout work could you please look at the following and let me know what I am doing wrong

  1. define maskout 0x01878ff3 PortOut data(Port0, maskout);

how will I write any data for example 0xab4c to the port. Any help would be greatly appreciated. Many Thanks Abid