Archive for the ‘Analog Devices Blackfin’ Category

Blackfin BF533: Core and System clock

Tuesday, February 5th, 2008
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void init_PLL(void)
{
	short tmp;
 
	*pSIC_IWR=0x01; // only PLL wakeup
	ssync();
 
	*pPLL_DIV = 0x001B; //cclk=vco/1;sclk=vco/11
	ssync();
 
	tmp = cli();
 
	*pPLL_CTL=(12<<9); //vco=12*clkin, clkin=27M
	ssync();
 
	idle();
	sti(tmp);
}

Blackfin BF533: Programmable flags with interrupts example

Tuesday, February 5th, 2008
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
	This example shows how to use 
	interrupts with programmable flags.
	PF8 will be used. When PF8 goes from low to high
	there will be an interrupt.	
*/
 
#include<stdio.h>
#include<cdefbf533.h>
#include<sys\exception.h> // needed for interrupts
 
// prototype
EX_INTERRUPT_HANDLER(FlagA_ISR);
 
void main(void)
{
 
	// Register FlagA ISR to interrupt vector group 12
	register_handler(ik_ivg12, FlagA_ISR);
 
	// set direction of programmable flag PF8 to input
	*pFIO_DIR &= ~PF8;
	ssync();
 
	// interrupt enable PF8
	*pFIO_INEN |= PF8;
	ssync();	
 
	// give interrupt when FIO_FLAG_D PF8 changes
	*pFIO_MASKA_D |= PF8;
	ssync();
 
 
	// Bind FlagA interrupt to IVG12
	*pSIC_IAR2 |= 0x00005000; // flag A IVG12
	ssync();
 
 
	// Enable PFA in system interrupt mask register
	*pSIC_IMASK = 0x00080000;
	ssync();
 
	// enable IVG12 in core interrupt mask register
	*pIMASK |= 0x00001000;
	ssync();
 
	// wait for interrupt
	while(1);
}
 
EX_INTERRUPT_HANDLER(FlagA_ISR)
{	
	printf("\n interrupt received!");
	fflush(stdout);
 
	// or do something else...
}

Blackfin BF533: Programmable Flags example

Tuesday, February 5th, 2008

There are 5 important registers for the Programmable Flags:

FIO_DIR: I/O direction
FIO_FLAG_D: Direct access to data of the programmable flags
FIO_FLAG_S: Write 1 to set flags
FIO_FLAG_C: Write 1 to clear flags
FIO_FLAG_T: Write 1 to toggle flags

With the last three registers it is not needed anymore use bitwise functions for setting, clearing and toggling flags :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
	This example shows how to use programmable flags of the BF533.
	The BF533 has 16 programmable flags (GPIO).
	This program toggles all flags.	
*/
 
#include <cdefBF533.h>
 
int main(void)
{
 
	int delay;
 
	// set direction of all flags to output
	*pFIO_DIR = 0xFFFF;
	ssync();
 
	// directly access data register
	// set all flags to high
	*pFIO_FLAG_D = 0xFFFF;
	ssync();	
 
	while (1) {
 
		// set all flags to high
		*pFIO_FLAG_S = 0xFFFF;
		ssync();
 
		for (delay = 0x00FFFFFF; delay>0; delay--); 
 
		// clear all flags (set to low)
		*pFIO_FLAG_C = 0xFFFF;
		ssync();
 
		for (delay = 0x00FFFFFF; delay>0; delay--);
 
		// FIO_FLAG_T register can also be used to toggle here!		
	}	
 
	// never reached
	//return 0;
}

Blackfin BF533: ADSP-BF533 EZKIT LITE LED’s example

Tuesday, February 5th, 2008
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
	This example shows how to use the 6 LED's 
	on the ADSP-BF533 EZ-KIT LITE.
	The LED's are connected on the Flash A chip instead of GPIO.
	This program will toggle the LED's
*/
 
 
#include <cdefBF533.h>
#include <stdio.h>
 
// addresses in Flash for the LED's
#define pFlashA_PortB_Dir	(volatile unsigned char *)0x20270007
#define pFlashA_PortB_Data	(volatile unsigned char *)0x20270005
 
int main(void)
{
 
	printf("Showing how the leds work on the BF533 EZ-KIT Lite");
	fflush(stdout);
 
	// External Bus Interface Unit setup, for access to flash A
	// It is not important to understand this
	*pEBIU_AMBCTL0	= 0x7bb07bb0;
	*pEBIU_AMBCTL1	= 0x7bb07bb0;
	*pEBIU_AMGCTL	= 0x000f;
 
	// flash data direction, b 111111
	*pFlashA_PortB_Dir = 0x3f;
 
	unsigned int delay = 0;
 
	while (1) {
 
		*pFlashA_PortB_Data = 0x15;	// b 010101
		ssync();
 
		// wait some time
		for (delay = 0x00FFFFFF; delay > 0; delay--);
 
		*pFlashA_PortB_Data = 0x2A;	// b 101010	
		ssync();
 
		// wait some time
		for (delay = 0x00FFFFFF; delay > 0; delay--);
	}
 
 
	// never reached
	//return 0;
 
}

Compiled with VisualDSP++ 5.0