Problem with blue LED in own program with LPCXpresso V2 LPC1549

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

Problem with blue LED in own program with LPCXpresso V2 LPC1549

1,160 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sat Nov 08 09:39:38 MST 2014
I just tried some first steps with KEIL uVision 5.12.0 to do some blinking LEDs on LPCXpresso V2 LPC1549.
After downloading CMSIS-DAP into debug controller (via DFUsec), I am able to download self written programs to LPC1549
via KEIL uVision (don't forget to switch from JTAG to SWD).
The red and green LEDs are blinking, the blue one stays off.
The blue one is on port 1 instead of red and green one, which are on port 0.
Is there something special for port 1 or even PIO1_1?
Or some other silly bug, which I have overseen?

int main (void) 
{
  LPC_SYSCON->SYSAHBCLKCTRL0 |= ((1UL << 14) | (1UL << 15));  /* enable clock for GPIO0 and GPIO1 port */

  /* configure GPIO as output */
  LPC_GPIO_PORT->DIR[1]  |= (1UL <<  1);
  LPC_GPIO_PORT->DIR[0]  |= (1UL <<  3);
  LPC_GPIO_PORT->DIR[0]  |= (1UL << 25);

  while(1)
  {
    volatile unsigned long w;
    
    LPC_GPIO_PORT->CLR[1]  = (1UL <<  1);
    LPC_GPIO_PORT->SET[0]  = (1UL <<  3);
    LPC_GPIO_PORT->SET[0]  = (1UL << 25);
    
    for(w = 0; w < 10000000; w++);

    LPC_GPIO_PORT->SET[1]  = (1UL <<  1);
    LPC_GPIO_PORT->CLR[0]  = (1UL <<  3);
    LPC_GPIO_PORT->SET[0]  = (1UL << 25);

    for(w = 0; w < 10000000; w++);

    LPC_GPIO_PORT->SET[1]  = (1UL <<  1);
    LPC_GPIO_PORT->SET[0]  = (1UL <<  3);
    LPC_GPIO_PORT->CLR[0]  = (1UL << 25);

    for(w = 0; w < 10000000; w++);
  }
}
Labels (1)
0 Kudos
8 Replies

970 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat Nov 08 12:03:17 MST 2014

Quote: capiman
So it is perhaps a good idea to reset all register of SWM at startup to default values...



IOCON setup table in board_sysinit.c of your board library is a good option to set your board defaults...


Quote: capiman
SWM is the only peripheral with this behaviour.



Yes  :)
0 Kudos

970 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sat Nov 08 11:39:45 MST 2014
Many thanks for the quote! This makes it clear!

So it is perhaps a good idea to reset all register of SWM at startup to default values (especially if not otherwise used)
to avoid wired errors...
I have just done a quick search over the user manual, but correct me if I am wrong, SWM is the only peripheral with this behaviour.

0 Kudos

970 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat Nov 08 11:29:12 MST 2014
Working with SWM and Reset can be confusing:

UM:

Quote:

Chapter 8: LPC15xx Switch Matrix (SWM)
8.3 Basic configuration:
...
Remark: [color=#f00]The switch matrix is only reset by a POR or BOD reset.[/color] A hardware reset via the
RESET pin or a watchdog timer reset do not reset the switch matrix. Therefore, peripheral
functions remain connected to pins through the hardware or watchdog reset and the pins
remain input or output as defined by the switch matrix and assume the default state as
defined by the peripheral connected to them. See also Section 3.7.1.

0 Kudos

970 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sat Nov 08 11:27:40 MST 2014
Details for (1):

It is this code in original blinky for MCB1500 which makes problems:

  /* configure PIN P1.1 for ADC1 */
  LPC_SYSCON->SYSAHBCLKCTRL0 |= ((1UL << 15) |  /* enable clock for GPIO1     */
                                 (1UL << 12)  );/* enable clock for SWM       */

  LPC_SWM->PINENABLE0   &= ~(1UL << 12);        /* P1.1 is ADC1_0             */


When I add the following code to my code, it works (all 3 LEDs can be controlled and are blinking):

  LPC_SYSCON->SYSAHBCLKCTRL0 |= ((1UL << 15) |  /* enable clock for GPIO1     */
                                 (1UL << 12)  );/* enable clock for SWM       */

  LPC_SWM->PINENABLE0 = 0xFFFFFFFF;


I let the debugger print the content of PINENABLE0 (then with setting it back to 0xFFFFFFFF) and it has a value of 0xFFFF[color=#f00]E[/color]FFF.
This is exactly the value which was set by other project.

Ok, I think I must stop here. All other things must be clarified by NXP.
0 Kudos

970 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sat Nov 08 11:12:42 MST 2014
Ok, I am now able to reproduce the problem.

I remembered that I loaded a project before which was for a KEIL MCB1500 board.
It is the blinky delivered with MCB1500.
When I download this program (via uVison -> Flash -> Download, it is for internal FLASH) and let it run,
afterwards load my own project (which is based on the original blinky, but then only the code above in main, all other commented out),
then only red and green LEDs are blinking, blue LED stays off.

Now, when I press the reset button (SW4), blue LED stays still off.

Now, when I power-cycle, it works.

Now 3 questions come to my mind:

1) It looks like original blinky is doing something which prevents my blue LED to work. This is try to find afterwards.
It uses ADC, I saw PIO1_1 is also an analog port, perhaps original blinky configures the PIO1_1 to work as an analog port?
It also has some LCD routine inside, but can't think why it shall be a problem.

2) When downloading via KEIL uVision 5.12.0 to flash, letting it run, loading a new project (my blinky) and let it run.
Is there no reset during download? Or is there a reset, but a certain register is not reset?

3) When I press the reset switch, which I checked in schematic to be going to nReset/PIO0_21 of LPC1549 (not just to debug controller or so),
why does it not reset all registers to some default value?

PS: Already checked errata, seem to be nothing written, which could be a hint for this case...
0 Kudos

970 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sat Nov 08 10:20:32 MST 2014
Mmh, mmh, now it works, without me changing something...
(perpaps I have re-powered the device...)

I really don't know, but it seems to work, even after flashing, debugging, re-power again, ...
0 Kudos

970 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sat Nov 08 10:15:34 MST 2014
Many thanks for the link!

But it looks like I have already the right port pins: P1.1 (blue), P0.3 (green), P0.25 (red).
I have the port numbers from schematic, not silk screen.
My board has a printing "Rev B" on the bottom of the board.

0 Kudos

970 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat Nov 08 09:51:35 MST 2014

Quote: capiman
Or some other silly bug, which I have overseen?



See: http://www.lpcware.com/content/forum/lpc1549-periphgpio-example-rgb-led-pin-mapping-wrong
0 Kudos