Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
// Description:
//! \addtogroup f2833x_example_list
//!
//! <h1>GPIO Toggle (gpio_toggle)</h1>
//!
//! \note ALL OF THE I/O'S TOGGLE IN THIS PROGRAM. MAKE SURE
//! THIS WILL NOT DAMAGE YOUR HARDWARE BEFORE RUNNING THIS
//! EXAMPLE.
//!
//! Three different examples are included. Select the example
//! (data, set/clear or toggle) to execute before compiling using
//! the macros found at the top of the code.
//!
//! Each example toggles all the GPIOs in a different way, the first
//! through writing values to the GPIO DATA registers, the second through
//! the SET/CLEAR registers and finally the last through the TOGGLE register
//!
//! The pins can be observed using Oscilloscope.
//
//###########################################################################
// $TI Release: F2833x/F2823x Header Files and Peripheral Examples V141 $
// $Release Date: November 6, 2015 $
// $Copyright: Copyright (C) 2007-2015 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################
// Select the example to compile in. Only one example should be set as 1
// the rest should be set as 0.
#define EXAMPLE1 0 // Use DATA registers to toggle I/O's
#define EXAMPLE2 0 // Use SET/CLEAR registers to toggle I/O's
#define EXAMPLE3 0 // Use TOGGLE registers to toggle I/O's
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();
// 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 DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();
#if EXAMPLE1
#endif // - EXAMPLE1
#if EXAMPLE2
#endif
#if EXAMPLE3
#endif
void delay_loop()
{
volatile long i;
for (i = 0; i < 1000000; i++) {}
}
void Gpio_example1(void)
{
// Example 1:
// Toggle I/Os using DATA registers
for(;;)
{
GpioDataRegs.GPADAT.all =0xAAAAAAAA;
GpioDataRegs.GPBDAT.all =0x0000000A;
delay_loop();
GpioDataRegs.GPADAT.all =0x55555555;
GpioDataRegs.GPBDAT.all =0x00000005;
delay_loop();
}
}
void Gpio_example2(void)
{
// Example 2:
// Toggle I/Os using SET/CLEAR registers
for(;;)
{
GpioDataRegs.GPASET.all =0xAAAAAAAA;
GpioDataRegs.GPACLEAR.all =0x55555555;
GpioDataRegs.GPBSET.all =0x0000000A;
GpioDataRegs.GPBCLEAR.all =0x00000005;
delay_loop();
GpioDataRegs.GPACLEAR.all =0xAAAAAAAA;
GpioDataRegs.GPASET.all =0x55555555;
GpioDataRegs.GPBCLEAR.all =0x0000000A;
GpioDataRegs.GPBSET.all =0x00000005;
delay_loop();
}
}
void Gpio_example3(void)
{
// Example 2:
// Toggle I/Os using TOGGLE registers
// Set pins to a known state
GpioDataRegs.GPASET.all =0xAAAAAAAA;
GpioDataRegs.GPACLEAR.all =0x55555555;
GpioDataRegs.GPBSET.all =0x0000000A;
GpioDataRegs.GPBCLEAR.all =0x00000005;
for(;;)
{
GpioDataRegs.GPATOGGLE.all =0xFFFFFFFF;
GpioDataRegs.GPBTOGGLE.all =0xFFFFFFFF; //0x0000000F;
delay_loop();
}
}
for(;;)
{
GpioDataRegs.GPCTOGGLE.all =0xFFFFFFFF;
delay_loop();
}
}
void Gpio_select(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPAMUX2.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPAMUX1.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF; // All outputs
GpioCtrlRegs.GPBDIR.all = 0xFFFFFFFF; // All outputs
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1; // Enable pulldown on GPIO1 PWM-1B
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0; // GPIO1 = GPIO1
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; // GPIO1 = output
EDIS;
GpioDataRegs.GPACLEAR.bit.GPIO1 = 0; // SET INPUT TO LOW.
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1; // Enable pulldown on GPIO2 PWM-2B
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0; // GPIO3 = GPIO3
GpioCtrlRegs.GPADIR.bit.GPIO3 = 1; // GPIO3 = output
EDIS;
GpioDataRegs.GPACLEAR.bit.GPIO3 = 0; // SET INPUT TO LOW
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO5 = 1; // Enable pulldown on GPIO2 PWM-3B
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0; // GPIO5 = GPIO5
GpioCtrlRegs.GPADIR.bit.GPIO5 = 1; // GPIO4 = output
EDIS;
GpioDataRegs.GPACLEAR.bit.GPIO5 = 0; // SET INPUT TO LOW
}
2. Secondly, I want to set PWM1A to LOW and PWM1B to HIGH. Similary for PWM2A/3A to LOW and PWM2B/3B to
HIGH. Below is the code.
function:
// PWM1A is set to ZERO and PWM1B is set to HIGH on GPIO Pin 0 and 1.
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1; // Enable pulldown on GPIO1 PWM-1A
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; // GPIO0 = GPIO0
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; // GPIO0 = output
EDIS;
GpioDataRegs.GPACLEAR.bit.GPIO0 = 0; // SET INPUT TO LOW.
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1; // Enable pulldown on GPIO1 PWM-1B
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0; // GPIO1 = GPIO1
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; // GPIO1 = output
EDIS;
GpioDataRegs.GPASET.bit.GPIO1 = 1; // SET INPUT TO HIGH.
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1; // Enable pulldown on GPIO3 PWM-2B
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0; // GPIO3 = GPIO3
GpioCtrlRegs.GPADIR.bit.GPIO3 = 1; // GPIO3 = output
EDIS;
GpioDataRegs.GPASET.bit.GPIO3 = 0; // SET INPUT TO HIGH
// PWM3A is set to ZERO and PWM3B is set to HIGH in GPIO Pin 4 and 5
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO4 = 1; // Enable pulldown on GPIO4 PWM-3A
GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0; // GPIO4 = GPIO4
GpioCtrlRegs.GPADIR.bit.GPIO4 = 1; // GPIO4 = output
EDIS;
GpioDataRegs.GPACLEAR.bit.GPIO4 = 0; // SET INPUT TO LOW
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO5 = 1; // Enable pulldown on GPIO5 PWM-3B
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0; // GPIO5 = GPIO5
GpioCtrlRegs.GPADIR.bit.GPIO5 = 1; // GPIO5 = output
EDIS;
GpioDataRegs.GPASET.bit.GPIO5 = 0; // SET INPUT TO HIGH
Kuldeep,
The main issue that I see with your code is that:
GpioCtrlRegs.GPACLEAR.bit.GPIO0 = 0;
does nothing to the GPIO. If instead you do:
GpioCtrlRegs.GPACLEAR.bit.GPIO0 = 1;
GPIO0 will become low.
In general, to change the output of a GPIO, you only need the GPxCLEAR, GPxSET, or GPxDAT instruction. The GPIO
control registers only need to be edited during initialization (or whenever you want the basic functionality of a pin to
change (ie GPIOoutput to PWM output) )
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#include "lab2.h"
long int i,k,l;
long int retardo=5000000;
long int test=0; // Variable para buscar errores
void main(void) {
DINT; //deshabilita interrupciones
DRTM; //deshabilita interrupciones real time mode
InitSysCtrl(); //inicializa el sistema como PLL,clocks,watcgdog
InitPieCtrl(); //inicializa el apoyo de interrupción de periféricos
IER = 0x0000; //limpia máscara de interrupciones
IFR = 0x0000; //limpia bandera de interrupciones
InitPieVectTable(); //inicializa tabla de interrupciones por defecto
EINT; //habilita interrupciones
ERTM;
EALLOW;
//Pull up y Multiplexor de los pines
GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0; // Habilitar pullup en GPIO0
GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0; // Habilitar pullup en GPIO1
GpioCtrlRegs.GPAPUD.bit.GPIO2 = 0; // Habilitar pullup en GPIO2
GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0; // Habilitar pullup en GPIO3
GpioCtrlRegs.GPAPUD.bit.GPIO4 = 0; // Habilitar pullup en GPIO4
GpioCtrlRegs.GPAPUD.bit.GPIO5 = 0; // Habilitar pullup en GPIO5
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; // GPIO0 = GPIO0
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0; // GPIO1 = GPIO1
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1; // GPIO2 = PWM2A
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 2; // GPIO3 = ECAP5
GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0; // GPIO4 = GPIO4
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 3; // GPIO5 = ECAP1
// Habilitar un GPIO como salida en el GPIO6, usar el "set" para puesta a uno
GpioCtrlRegs.GPAPUD.bit.GPIO6 = 0; // Habilitar pullup en GPIO6
GpioDataRegs.GPASET.bit.GPIO6 = 1; // cargar latch de salida = 1
GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0; // GPIO6 = GPIO6
GpioCtrlRegs.GPADIR.bit.GPIO6 = 1; // GPIO6 = es salida
// Habilitar un GPIO como salida en el GPIO10, usar el "clear" para puesta a cero
GpioCtrlRegs.GPAPUD.bit.GPIO10 = 0; // Habilitar pullup en GPIO10
GpioDataRegs.GPACLEAR.bit.GPIO10 = 1; // cargar latch de salida = 1
GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 0; // GPIO10 = GPIO10
GpioCtrlRegs.GPADIR.bit.GPIO10 = 1; // GPIO10 = es salida