This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Getting started with Blinky

Hi, there,

I am new to ARM and just downloaded MDK3.70 demo to try to get Blinky to run on lpc2106.

I set up uvision3, and wired up the schematic in Proteus (7.1), since I already downloaded an almost identical program there - with a .hex file. the program is to flash LEDs linked to P0.0-P0.7. The Proteus simulation, with the pre-made .hex file, worked well.

so I decided to produce my own .hex file in uvision3, see below.

=========code===========
#include <LPC210x.H> /* LPC210x definitions */

void wait (void) { /* wait function */ ; /* only to delay for LED flashes */
}

int main (void) {
// unsigned int i; /* Delay var */
// unsigned int j; /* LED var */

PINSEL0=0x00; IODIR = 0xFF; // P0.0..7 defined as Outputs */

while (1) { IOSET=0xff; //?? IOCLR=0xff; }
}

========end of code==============

I didn't put the wait() function there for simplicity.

well, uvision did produce a .hex file. I loaded the file to the proteus simulation, and replaced the pre-made .hex. no go. all ports are in high impedance mode and nothing happened.

I would appreciate very much if you can point me in the right direction. I am thinking the problem is likely caused by my uvision not producing the right .hex file (wrong settings somewhere?) but I am not sure where to start.

your help is greatly appreciated. Thanks.

Parents
  • tamir, thanks for the reply. but I am not sure if wait() is the problem.

    here is the complete code, including the wait function.

    ===========code================
    #include <LPC210x.H> /* LPC210x definitions */

    void wait(void)
    { int i,dly; for (dly=10;dly>0;dly--) for(i=0;i<50000;i++);
    } /****************************************************************
    *??: main()
    *??: ??LED?
    ****************************************************************/
    int main(void)
    { PINSEL0=0x00; //??????GPIO IODIR= 0xff; //????? while(1){ IOSET=0xff; //?? wait(); IOCLR=0xff; }
    } =============end of code================

    again, any help is greatly appreciated. Thanks.

Reply
  • tamir, thanks for the reply. but I am not sure if wait() is the problem.

    here is the complete code, including the wait function.

    ===========code================
    #include <LPC210x.H> /* LPC210x definitions */

    void wait(void)
    { int i,dly; for (dly=10;dly>0;dly--) for(i=0;i<50000;i++);
    } /****************************************************************
    *??: main()
    *??: ??LED?
    ****************************************************************/
    int main(void)
    { PINSEL0=0x00; //??????GPIO IODIR= 0xff; //????? while(1){ IOSET=0xff; //?? wait(); IOCLR=0xff; }
    } =============end of code================

    again, any help is greatly appreciated. Thanks.

Children
  • sorry for the messy posting.

    I am learning the "pre" tag, :)

    #include <LPC210x.H>                       /* LPC210x definitions */
    
    void wait(void)
    {
            int  i,dly;
            for (dly=10;dly>0;dly--)
                    for(i=0;i<50000;i++);
    }
    /****************************************************************
    *??: main()
    *??: ??LED?
    ****************************************************************/
    int main(void)
    {
            PINSEL0=0x00;      //??????GPIO
            IODIR= 0xff;      //?????
            while(1){
                    IOSET=0xff;     //??
                    wait();
                    IOCLR=0xff;
            }
    }
    

  • other things to consider when trying to delay your problem with C:

    1. using 'pre' and '/pre' to post code...
    2. the effect of compiler optimization on empty loops - are you sure the compiler even generates assembly for your C loop?

  • not that it is good practice, but don't the behavior of your program change if you declare the loop variables as volatile...?

  • tamir, good questions.

    I did take a look at the disassembly window and the code is generated to jump to wait().

    I also step'd through the main() function and watched the last 8bits in port to change from 0 to 1 and then 0. so it is definitely working from a procedural point of view. Looks like when it goes from C to .hex, something happened.

  • What happened is probably brutal raw speed. Use the simulator to compute how much time the delay function actually takes.

    Or turn on assembly listings and look if the delay function contains any code, or if it is more or less empty. The compiler can clearly see that your delay function does not produce any results that you are keeping, so the compiler may throw away all code inside the function.

    Another big problem with your code, is that it should have two delays. One delay with the LEDs on, and one delay with the LEDs off.

  • thanks, per. here is the new code - still no go.

    #include <LPC210x.H>                       /* LPC210x definitions */
    
    void wait(int dly)
    {
            int  i;
            for (;dly>0;dly--)
                    for(i=0;i<50000;i++);
    }
    /****************************************************************
    *??: main()
    *??: ??LED?
    ****************************************************************/
    int main(void)
    {
            PINSEL0=0x00;      //??????GPIO
            IODIR= 0xff;      //?????
            while(1){
                    IOSET=0xff;     //??
                    wait(10);
                    IOCLR=0xff;
                    wait(10);
            }
    }
    

    here is the disassembly sectioon for wait():

         7:                 for(i=0;i<50000;i++);
    0x00000210  E59F2058  LDR       R2,[PC,#0x0058]
         6:         for (;dly>0;dly--)
         7:                 for(i=0;i<50000;i++);
    0x00000214  EA000004  B         0x0000022C
    0x00000218  E3A01000  MOV       R1,#0x00000000
    0x0000021C  E2811001  ADD       R1,R1,#0x00000001
    0x00000220  E1510002  CMP       R1,R2
    0x00000224  BAFFFFFC  BLT       0x0000021C
    0x00000228  E2400001  SUB       R0,R0,#0x00000001
    0x0000022C  E3500000  CMP       R0,#0x00000000
    0x00000230  CAFFFFF8  BGT       0x00000218
         8: }
    

    here is the main body of the program.

        15:         PINSEL0=0x00;      //??????GPIO
    0x00000240  E52DE004  STR       R14,[R13,#-0x0004]!
    0x00000244  E5810000  STR       R0,[R1]
        16:         IODIR= 0xff;      //?????
        17:         while(1){
    0x00000248  E3A0C0FF  MOV       R12,#0x000000FF
    0x0000024C  E2413901  SUB       R3,R1,#0x00004000
    0x00000250  E583C008  STR       R12,[R3,#0x0008]
        18:                 IOSET=0xff;     //??
    0x00000254  E583C004  STR       R12,[R3,#0x0004]
        19:                 wait(10);
    0x00000258  E3A0000A  MOV       R0,#0x0000000A
    0x0000025C  EBFFFFEB  BL        wait(0x00000210)
        20:                 IOCLR=0xff;
    0x00000260  E583C00C  STR       R12,[R3,#0x000C]
        21:                 wait(10);
    0x00000264  E3A0000A  MOV       R0,#0x0000000A
    0x00000268  EBFFFFE8  BL        wait(0x00000210)
    

  • out of desparation, I took the blinky project under the examples folder, and made it to compile for lpc2106, and it still wouldn't work.

    see the code attached below. In Proteus, there is no change in pin status: they are all in high impedance mode.

    what gives?

    /******************************************************************************/
    /* BLINKY.C: LED Flasher                                                      */
    /******************************************************************************/
    /* This file is part of the uVision/ARM development tools.                    */
    /* Copyright (c) 2005-2006 Keil Software. All rights reserved.                */
    /* This software may only be used under the terms of a valid, current,        */
    /* end user licence from KEIL for a compatible version of KEIL software       */
    /* development tools. Nothing else gives you the right to use this software.  */
    /******************************************************************************/
    
    #include <LPC210x.H>                       /* LPC21xx definitions */
    
    void wait (void)  {                        /* wait function */
      int  d;
    
      for (d = 0; d < 1000000; d++);           /* only to delay for LED flashes */
    }
    
    int main (void) {
      unsigned int i;                          /* LED var */
    
      IODIR = 0x00FF0000;                     /* P0.16..23 defined as Outputs */
    
      while (1)  {                             /* Loop forever */
        for (i = 1<<16; i < 1<<23; i <<= 1) {  /* Blink LED 0,1,2,3,4,5,6 */
          IOSET = i;                          /* Turn on LED */
          wait ();                             /* call wait function */
          IOCLR = i;                          /* Turn off LED */
        }
        for (i = 1<<23; i > 1<<16; i >>=1 ) {  /* Blink LED 7,6,5,4,3,2,1 */
          IOSET = i;                          /* Turn on LED */
          wait ();                             /* call wait function */
          IOCLR = i;                          /* Turn off LED */
        }
      }
    }
    

  • also, I noticed that some (all?) projects in the examples and board folders have "retarget.c" in the project file list. but my own blinky project doesn't have it.

    what's is that file for?

  • problem resolved!

    I still don't know what happened but I went through a couple uninstall / install cycles and now the same program produces the right .hex file that flashes those lovely LEDs!

    Thanks everyone for your help.

  • this is KILLING me!!!!!!!!!!!!!!!!!!!!!!!

    so I had some issues with my mdk3.70 demo not producing the right .hex file. I solved that by uninstalling and reinstalling it a few times.

    and the program worked beautifully until I used it today. it would produce a .hex file but that .hex file wouldn't change any of the pins, as it did before.

    uninstalling / reinstalling doesn't solve the problem this time.

    I understand that the demo version has code size limitations. But does it also have a time limitation as well - the keil website isn't exactly clear on that.

    any solutions?

    Thanks.