If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Select the example to compile in. Only one example should be set as 1
// the rest should be set as 0.
#define EXAMPLE1 1 // Basic pinout configuration example
#define EXAMPLE2 0 // Communication pinout example
// Prototype statements for functions found within this file.
void Gpio_setup1(void);
void Gpio_setup2(void);
void main(void)
{
// WARNING: Always ensure you call memcpy before running any functions from RAM
// InitSysCtrl includes a call to a RAM based function and without a call to
// memcpy first, the processor will go "into the weeds"
#ifdef _FLASH
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the f2802x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the f2802x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the f2802x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in f2802x_DefaultIsr.c.
// This function is found in f2802x_PieVect.c.
InitPieVectTable();
// Step 4. Initialize all the Device Peripherals:
// Not required for this example
// Step 5. User specific code:
#if EXAMPLE1
// This example is a basic pinout
Gpio_setup1();
#endif // - EXAMPLE1
#if EXAMPLE2
// This example is a communications pinout
Gpio_setup2();
#endif
}
void Gpio_setup1(void)
{
// Example 1:
// Basic Pinout.
// This basic pinout includes:
// PWM1-3, TZ1-TZ4, SPI-A, EQEP1, SCI-A, I2C
// and a number of I/O pins
// These can be combined into single statements for improved
// code efficiency.
// Make GPIO34 an input
GpioCtrlRegs.GPBPUD.bit.GPIO34 = 0; // Enable pullup on GPIO34
GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // GPIO34 = GPIO34
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 0; // GPIO34 = input
EDIS;
}
void Gpio_setup2(void)
{
// Example 1:
// Communications Pinout.
// This basic communications pinout includes:
// PWM1-3, SPI-A, SCI-A
// and a number of I/O pins
/* Applicable only on those packages with GPIO32 and GPIO33 pinned out
// Enable I2C-A on GPIO32 - GPIO33
GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0; // Enable pullup on GPIO32
GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0; // Enable pullup on GPIO33
GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3; // asynch input
GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3; // asynch input
GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1; // GPIO32 = SDAA
GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1; // GPIO33 = SCLA
*/
// Make GPIO34 an input
GpioCtrlRegs.GPBPUD.bit.GPIO34 = 0; // Enable pullup on GPIO34
GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0; // GPIO34 = GPIO34
GpioCtrlRegs.GPBDIR.bit.GPIO34 = 0; // GPIO34 = input
EDIS;
}
//===========================================================================
// No more.
//===========================================================================