0

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--);
}
Clifford
  • 88,407
  • 13
  • 85
  • 165
Zain
  • 9
  • 2
  • Probably, since most of your code is commented out:( – Martin James Feb 11 '18 at 17:49
  • 1
    'I am using JTAG' well, presumably you have a debugger to go with that? – Martin James Feb 11 '18 at 17:51
  • Not sure if you delay loop is getting optimized out. Your debugger will tell you. – Martin James Feb 11 '18 at 17:54
  • @MartinJames Sorry, Now, I have corrected the code. Can you have a look again please. – Zain Feb 11 '18 at 18:16
  • @MartinJames. I did not understand your point about debugger . Could please elaborate? – Zain Feb 11 '18 at 18:18
  • Do you not have source-level debugging with your IDE and JTAG? – Martin James Feb 11 '18 at 18:19
  • @MartinJames. Yes I have – Zain Feb 11 '18 at 18:31
  • 1
    The point is that if you used the debugger to single step through your code the problem would become obvious. The LEDs _are_ blinking. But your `Delay` loop is not working as you intended and they are blinking so fast that the LED appears to be half red and half green to your eye. If you used the debugger to single step then execution would be slow enough that you could observe the blinking with your eye and direct your suspicion to the `Delay` function. See Clifford's answer about fixing `Delay`. – kkrambo Feb 12 '18 at 13:20

1 Answers1

2

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.

Clifford
  • 88,407
  • 13
  • 85
  • 165