Thread 中讨论的其他器件: controlSUITE
大家好、
我有一个 TMDSPREX28335实验套件。 它上面有4个 LED、它们连接到 GPIO、如下所示:
LED1:GPIO9
LED2:GPIO11
LED3:GPIO34
LED4:GPIO49
为了理解套件、我使用 了 example_2833xGpioToggle.c 程序的概念并将其修改为仅切换4个 LED 和相应的 GPIO。 为清晰起见、随附代码。
// OBJECTIVE IS TO CONFIGURE GPIOs AS GPIOs
// AND TOGGLE TO OBTAIN A PWM OUTPUT ON OSCILLOSCOPE
// using TOGGLE registers to TOGGLE
// Included Files
//
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
//
// Defines that select the example to compile in.
// Only one example should be set as 1 the rest should be set as 0.
//
#define EXAMPLE3 1 // Use TOGGLE registers to toggle I/O's
//
// Function Prototypes
//
void delay_loop(void);
void Gpio_example3(void);
//
// Main
//
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();
//
// Step 2. Initialize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
// InitGpio(); // Skipped for this example
//
// For this example use the following configuration
//
EALLOW;
GpioCtrlRegs.GPAMUX1.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPAMUX2.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPBMUX1.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPBMUX2.all = 0x00000000; // All GPIO
GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF; // All outputs
GpioCtrlRegs.GPBDIR.all = 0xFFFFFFFF; // All outputs
GpioCtrlRegs.GPAQSEL1.all = 0x0000; // GPIO0-GPIO15 Synch to SYSCLKOUT
GpioCtrlRegs.GPAQSEL2.all = 0x0000; // GPIO16-GPIO31 Synch to SYSCLKOUT
GpioCtrlRegs.GPBQSEL1.all = 0x0000; // GPIO32-GPIO39 Synch to SYSCLKOUT
GpioCtrlRegs.GPBQSEL2.all = 0x0000; // GPIO48-GPIO63 Synch to SYSCLKOUT
GpioCtrlRegs.GPAPUD.all = 0xFFFFFFFF; // Pullup's disabled GPIO0-GPIO31
GpioCtrlRegs.GPBPUD.all = 0xFFFFFFFF; // Pullup's disabled GPIO32-GPIO34
EDIS;
//
// 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 DSP2833x_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 DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
//
InitPieVectTable();
//
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
//
// InitPeripherals(); // Not required for this example
//
// Step 5. User specific code:
//
#if EXAMPLE3
//
// This example uses TOGGLE registers to toggle I/O's
//
Gpio_example3();
#endif
}
//
// delay_loop -
//
void delay_loop()
{
volatile long i;
for (i = 0; i < 5000000; i++)
{
asm(" NOP");
EALLOW;
SysCtrlRegs.WDKEY = 0x55;
SysCtrlRegs.WDKEY = 0xAA;
EDIS;
}
}
//
// Gpio_example3 -
//
void Gpio_example3(void)
{
//
// Example 2: Toggle I/Os using TOGGLE registers
//
//
// Set pins to a known state
//
GpioDataRegs.GPADAT.bit.GPIO9 =1;
GpioDataRegs.GPADAT.bit.GPIO11 =0;
GpioDataRegs.GPBDAT.bit.GPIO34 =1;
GpioDataRegs.GPBDAT.bit.GPIO49 =0;
//
// Use TOGGLE registers to flip the state of the pins.
// Any bit set to a 1 will flip state (toggle)
// Any bit set to a 0 will not toggle.
//
for(;;)
{
GpioDataRegs.GPATOGGLE.bit.GPIO9 =1;
GpioDataRegs.GPATOGGLE.bit.GPIO11 =1;
GpioDataRegs.GPBTOGGLE.bit.GPIO34 =1;
GpioDataRegs.GPBTOGGLE.bit.GPIO49 =1;
delay_loop();
}
}
//
// End of File
//
如果我按照所附表中的详细信息将代码 A 位从第131行修改为第134行、我会看到套件出现异常行为。 表中也列出了这些意见。
| 情况1. | 情况2. | 情况3. | 情况4. | 情况5. | 情况6. | 情况7. | |
| GPIO (LED) | GPxDAT | GPxDAT | GPxSET | GPxSET | GPxSET | GPxCLEAR | GPxCLEAR |
| 9 (1) | 1 | 0 | 0 | 1 | 0 | 1 | 0 |
| 11 (2) | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
| 34(3) | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 49 (4) | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
| 观察结果 | LED1和 LED2应 相互互补 但是、它们同时 打开和关闭。 LED3和 LED4之间的开关相互补充。 不稳定的行为 |
LED1和 LED2也会亮起。 LED3和 LED4也会亮起。 正常行为 |
LED1和 LED2完全不发光。 LED3和 LED4同样亮起。
不稳定的行为 |
LED1和 LED2也会亮起。 LED3和 LED4也会亮起。 正常行为 |
LED1和 LED2也会亮起。 LED3和 LED4也会亮起。 正常行为 |
LED1、LED2、LED3和 LED4都 同时打开和关闭。 不稳定的行为 |
LED1、LED2、LED3和 LED4都 同时打开和关闭。 不稳定的行为 |
有人能不能简单地说明 为什么我在案例1、3、6和7中遇到这种异常行为?
此致、
Ankit
PS: 可能还有更多可能的组合、我尚未尝试、这些组合可能会产生意外输出!!!!
PPS:详尽的解释或/和批评是/是非常受欢迎的

