LED does not blink after loading the code Blackfin Processor F527

175 Views Asked by At

After successfully building the project (in VisualDSP), executable code is successfully loaded to blackfin processor BF527 but LEDs do not blink. I am using JTAG to communicate Board(contains BF527 processor) with PC. After I power up the board each LED's color is half red and half green. Am I making a mistake?

/* VisualDSP++ 5.1.2 Code to Blink LED on ADSP-BF527*/

#include <ccblkfn.h>
#include <cdefBF527.h>
#include <defBF527.h>
#include <stdio.h>

void Init_PLL(unsigned int msel, unsigned int ssel);
void Init_Leds(void);
void Delay(int);

int main( void )
{   
    Init_PLL(16,5);
    Init_Leds();

    while(1)
    {
        Delay(20000000);

        *pPORTFIO_SET |= PF8; /*Enable the pin*/
         Delay(20000000);

        *pPORTGIO_SET |= PG11;
         Delay(20000000);

        *pPORTGIO_SET |= PG12;
         Delay(20000000);

        *pPORTFIO_CLEAR |= (PF8);
        *pPORTGIO_CLEAR |= (PG11 | PG12);
    }
}

void Init_Leds()
{
    *pPORTF_FER  &= ~(PF8);
    *pPORTG_FER  &= ~(PG11 | PG12);

    *pPORTFIO_DIR |= (PF8);
    *pPORTGIO_DIR |= (PG11 | PG12);

    *pPORTFIO_CLEAR |= (PF8);
    *pPORTGIO_CLEAR |= (PG11 | PG12);   
}

void Delay(int n)
{
    while(n--);
}
1

There are 1 best solutions below

1
On

You will at least need:

void Delay(volatile int n)
{
    while(n--);
}

Otherwise any decent compiler will see that n is modified but never read, and optimise out the entire loop.

A better solution however would be to use a hardware timer to implement a constant delay regardless of code generation efficiency or processor clock rate.