mbed Blinky program doesn't work on Port2

11 Dec 2014

Hi. I have tried mbed library on a LPC1768 board (which I made for myself). So as a start point I tried simple Blinky program and a part of it didn't work!

Blinky

#include "mbed.h"
	DigitalOut myled(P2_0);
	DigitalOut myled1(P1_18);
int main() {
    while(1) {
        myled = 1;
        myled1 = 1;
        wait_ms(500);
        myled = 0;
        myled1 = 0;			
        wait_ms(500);
    }
}

What is strange is that myled which is connected to P2_0 is not toggling but myled1 which is connected to P1_18 is toggling!

But when I try to toggle P2_0 directly (not using mbed. Simply using it's registers) it does work and toggle!

What do you think the problem is?

It's very strange to me. I mean in the above program even in Keil debugger I see that P2_0 is toggling along with P1_18 but in actual board only P1_18 is toggling.

14 Dec 2014

Guys I'd really appreciate it if someone could test it on it's own mbed board ...

14 Dec 2014

I tried code below on my mbed lpc1768. It works as expected. The mbed lib version is 92.

#include "mbed.h"

DigitalOut myled(P2_0);    //p26
DigitalOut myled1(P1_18);  //LED1

int main() {
    while(1) {
        myled = 1;
        myled1 = 1;        
        wait(0.2);
        myled = 0;
        myled1 = 0;        
        wait(0.2);
    }
}

Maybe a bad/shorted pin or wire that pulls P2_0 to gnd ? Is anything else connected to P2_0 on your board?

15 Dec 2014

Thank you Wim Of course something else is connected to the port but it doesn't matter as long as I can toggle P2[7..0] using GPIO2 FIO2SET and FIO2CLR registers (or FIO2PIN) directly (without using mbed). Actually that's the weirdest part! Look:

toggle P2[7..0] without using mbed library


__INLINE static void LED_Config(void) {
  LPC_GPIO2->FIODIR = 0x000000ff;               /* LEDs PORT2 are Output */
  LPC_GPIO0->FIODIR = 0x00200000; 
  LPC_GPIO0->FIOPIN |=  0x00200000; 
}
/*------------------------------------------------------------------------------
  Switch on LEDs
 *------------------------------------------------------------------------------*/
__INLINE static void LED_On (uint32_t led) {
  LPC_GPIO2->FIOPIN |=  (led);                  /* Turn On  LED */
}
/*------------------------------------------------------------------------------
  Switch off LEDs
 *------------------------------------------------------------------------------*/
__INLINE static void LED_Off (uint32_t led) {
  LPC_GPIO2->FIOPIN &= ~(led);                  /* Turn Off LED */
}

When I call above functions from main it works perfectly fine and all LEDs are blinking just fine. That's why I'm telling you that there isn't any problem with the hardware . I don't get it. What the heck is wrong with mbed?

15 Dec 2014

Ok, so I assume the LED anode is connected to P2_0, the cathode should be connected to a series resistor. Is the other end of the resistor hardwired to GND or could that somehow be connected to another pin which prevents the LED from lighting up under mbed because it is not at GND level. Did you measure the actual voltage on P2_0 for the mbed version.

Your LED config also seems to set a pin on GPIO0

  LPC_GPIO0->FIODIR = 0x00200000; 
  LPC_GPIO0->FIOPIN |=  0x00200000; 

have you tried that under mbed. Could that cause the resistor to be a GND level. Maybe it helps to show schematic and both pieces of code. It must be something trivial (famous last words.....)

16 Dec 2014

I'm very thankful Wim

I didn't have the correct schematic of this board and now that you mentioned that two lines I got the right schematic and figured that for P2[7..0] to work I had to toggle P0_21 since P2 is connected to some sort of buffer for a LCD too. But I cant believe I've never noticed that from the sample code. I don't know how to thank you.

16 Dec 2014

Good to hear that the problem has been resolved.