Trouble with very simple program LPC1227

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

Trouble with very simple program LPC1227

617 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jab on Fri Sep 30 06:57:29 MST 2011
Hello,

We have built our own custom cortex M0 development board and we are having some issues with writing code for it.

The bootloader works fine, we can get the part number etc off the chip so we know the chip is working.

Our code is simple, it just toggles the pull up resistor enable on a GPIO pin (a very minimal test). We have this pin then connected to an oscilloscope.

CODE BELOW
----------------------------------------

/*
===============================================================================
Name        : main.c
Author      :
Version     :
Copyright   : Copyright (C)
Description : main definition
===============================================================================
*/

#ifdef __USE_CMSIS
#include "LPC122x.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

// TODO: insert other include files here

// TODO: insert other definitions and declarations here
#define __DISABLE_WATCHDOG 1

int main(void) {
    unsigned long Test1 = 0;

    LPC_IOCON->PIO0_0 = Test1;
    // TODO: insert code here

    while(1) {

        if (Test1 == 0)
        {
            Test1 = 16;
        }
        else
        {
            Test1 = 0;
        }

        LPC_IOCON->PIO0_0 = Test1;
    }
    return 0 ;
}

All we do is toggle bit 4 in the IOCON register for GPIO0_0.

We have LPCxpresso generating a hex file which we then download using flash magic, here are the post build commands.

arm-none-eabi-objcopy -O binary ${BuildArtifactFileName} ${BuildArtifactFileBaseName}.bin;  checksum -v ${BuildArtifactFileBaseName}.bin; arm-none-eabi-objcopy -I binary ${BuildArtifactFileBaseName}.bin -O ihex ${BuildArtifactFileBaseName}.hex;




The strange thing is, if I just disable the pullup once the line pulls low correctly, but it doesnt toggle. I have also tried to use the IO properly, writing to the out register but that didnt work, figured this program was easier to post.

The system is configured to use the internal RC osc.


Thanks for your help in advance, I feel like I have been banging my head against a brick wall for several hours!

Julian
0 Kudos
18 Replies

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ratiafak on Sat Sep 15 13:52:45 MST 2012

Quote: jab
LPC_SYSCON->SYSAHBCLKCTRL |= 0xE001001FUL;



Same problem. It apears documentation is wrong and noone bothers.
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 03 07:36:20 MST 2011

Quote: jab
...new contract so I can stay employed...



Good luck ...


Quote: jab
Just not many people here work with 32bit uC's...



That's your chance :)
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jab on Mon Oct 03 07:15:07 MST 2011

Quote: Zero
Then someone there should know that today a lot of manufacturers are supporting cheap tools :eek:

Can't believe that your universities and profs are so slow as in Germany...



Alas my supervisor/manager is not around much at the moment (busy running around trying to get me a new contract so I can stay employed :p).

Just not many people here work with 32bit uC's mainly pics and AVR's for low power stuff OR they are busy/cant be bothered to help. I thought when I became staff certain people might be more helpful but alas no..not the case.

Anyway, I have solved my problem. I looked at the blinky example code and noticed a line at the top:

LPC_SYSCON->SYSAHBCLKCTRL |= 0xE001001FUL;

which is writing an Unsigned long to the sysahbclkctrl register. It appears that this turns on the clocks for the IOCON block and the GPIO's. It says the reset value is already enabled but maybe something has changed (i.e. the documentation is wrong?)

It seems to be working now and I can run many examples....it is all a bit odd!
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 03 06:52:10 MST 2011

Quote: jab
Nah I just work at a university...



Then someone there should know that today a lot of manufacturers are supporting cheap tools :eek:

Can't believe that your universities and profs are so slow as in Germany...
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jab on Mon Oct 03 06:34:25 MST 2011
Nah I just work at a university and there isnt a whole lot of money around. Most chips use normal JTAG and we have those we just dont have one which can do the arm two wire debug thing.

Plus I didnt realkly know about the LPCxpresso stuff before this, we usually use ARM Realview but it is a bit excessive for this type of thing.
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 03 06:12:11 MST 2011

Quote: jab
Can I program my board with the LPCxpresso board too as well as debug it?



Yes, a simple 4-wire SWD connector will do that :eek::eek:

See #9 of: http://knowledgebase.nxp.com/showthread.php?p=8227
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 03 06:02:24 MST 2011
Don't know which experts and manager you have around there, but everyone who tries to work without debugger is an idiot and wasting a lot of time and money :eek:

Since LPCXpresso isn't very expensive this behaviour is even more idiotic :)

And last not least you are responsible for your work and sooner or later someone will kick you....
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jab on Mon Oct 03 05:50:11 MST 2011
I was told to design this custom board by my manager, so there wasnt much choice there.

We do however have a visiting professor from ARM working with us (although he isnt around right now). I might be able to get a debugger from him once he returns (i think he is on sabbatical at the moment)

I thought the pullups would work on the outputs too since you can then do stuff like bitbang i2c (i know there are i2c controllers on this chip but just an example).

It might be then that the pin is being set to output so thats why it toggles low.

Ah wait, no I understand, get an LPCxpresso board and use the debugger on that connected to this board...DOH! very sorry not really with it today!

Have gotten financial approval to order an Xpresso board. Which is awesome and it has been ordered :-) Can I program my board with the LPCxpresso board too as well as debug it?
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jab on Mon Oct 03 05:30:52 MST 2011
Hi Guys,

I ran the UART_small printf example as I remembered I had run it as a test on a previous board (long ago).

The sample works which would indicate that chip is working, just will find out what the difference is between my startup code and the sample project. I am sure there must be an incorrect build setting somewhere maybe.....
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 03 05:29:17 MST 2011

Quote: jab
We have designed a custom board and no debugger hardware so we cant use the debugger. (or so I believe)



Then kick 'We' in the... and buy a LPCXpresso, connect SWD and debug, otherwise you will spend a lot of time with guessing :)



Quote: jab
the pin is being pulled low which makes me believe the pull up is being disabled



Output pins shouldn't care about pull-up :eek::eek:
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jab on Mon Oct 03 05:12:33 MST 2011
We have designed a custom board and no debugger hardware so we cant use the debugger. (or so I believe)

I have tried another pin and still nothing,

the pin is being pulled low which makes me believe the pull up is being disabled.

Will try slowing down the loop.
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 03 05:05:36 MST 2011
#1 Is there a special reason why you don't use LPCXpresso debugger?

#2 Could be a good idea to slow down you toggling with a loop :)

#3 Try other pins (perhaps this pin is really damaged) :):)

#4 Reset your  mask register (although it should be 0x00).
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jab on Mon Oct 03 04:45:07 MST 2011
Okay...this is the code I tested this morning:

/*
===============================================================================
 Name        : main.c
 Author      : 
 Version     :
 Copyright   : Copyright (C) 
 Description : main definition
===============================================================================
*/

#ifdef __USE_CMSIS
#include "LPC122x.h"
#endif

#include <cr_section_macros.h>
#include <NXP/crp.h>

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

// TODO: insert other include files here

// TODO: insert other definitions and declarations here
#define __DISABLE_WATCHDOG 1

int main(void) {

    // Disable the pullup on GPIO0_0
    LPC_IOCON->PIO0_0 = 0x00;
    // TODO: insert code here
    LPC_GPIO0->DIR = 0xFFFFFFFF;

    while(1)
    {
        LPC_GPIO0->NOT = 0x00000001;

    }
    return 0 ;
}


So I disable the pullup on GPIO0_0, set the direction to output for the whole of GPIO0 and then invert the LSB of GPIO0 in the loop. Oscilloscpoe attached to the output shows the output go low but nothing else, to me it looks like the code in the loop isnt being executed.

I have started a new project, using the LPCxpresso defaults for my project, I alter the project to generate a hex file and use flash magic to download the code.

Any help guys? Have I missed something simple?
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jab on Fri Sep 30 21:00:23 MST 2011

Quote: OXO
What is there to pull it low when the pullup is disabled? if you're doing this at full speed, then the capacitance of the pin and the scope probe will probably keep it high..



When the pullup was disabled the pin did go low, it just didnt toggle, it just went once and stopped. It looked like it was running the initialization code but not the code in the loop.

I also didnt think it was damaged because the bootloader works, just unsure. Tried loading a sample program from the CMSIS examples provided by NXP, the blinky code didnt seem to be working.

Will have another go on monday when I am back in the lab. I am sure I missed something simple somewhere, been a long week....
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Sep 30 13:32:05 MST 2011

Quote: jab
Otherwise it might have been damaged during reflow....



Don't think so, this chips are not easy to destroy. If your bootloader is working, it can't be complete destroyed. Simplest test is to use debugger peripherals to set / reset a pin :)
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OXO on Fri Sep 30 13:28:19 MST 2011
What is there to pull it low when the pullup is disabled? if you're doing this at full speed, then the capacitance of the pin and the scope probe will probably keep it high..
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jab on Fri Sep 30 13:19:45 MST 2011
I tried it setting the dir bit etc, didnt work so pull up was the last resort as a sanity check.


Toggling at full speed isnt a problem, have a 2gs/s osc scope available. Just trying to get the chip to do anything remotely useful. Otherwise it might have been damaged during reflow....
0 Kudos

568 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Sep 30 07:21:20 MST 2011

Quote:

All we do is toggle bit 4 in the IOCON register for GPIO0_0. :confused::confused:

WHY :confused:

You are full speed toggling pull-up bit?? 

Use DIR register to set output direction
 LPC_GPIO0->DIR |= (1<<0); //high = output
and SET and CLR register to set or clear
 LPC_GPIO0->SET = (1<<0); //set high
 LPC_GPIO0->CLR = (1<<0); //set low
or PIN change output value:

 LPC_GPIO0->PIN ^= (1<<0); //toggle
And don't forget: without loop you are toggling very fast :eek:
0 Kudos