输入限制:
输入限制电路设计的十分灵活,你可以通过配置GPxQSELn寄存器来选择输入限制的类型。在GPIO的输入模式中,可以配置为与SYSCLKOUT同步或者采样窗口限制。对于外设的输入,还可以配置成异步模式。
不同步(异步输入):此模式用于不要求同步或者本身就要异步的外设中,比如SCI,SPI和I2C。或者独立于SYSCLKOUT的ePWM触发。通用数字接口不能用此模式。
采样窗口限制:在此模式中,输入信号首先与SYSCLKOUT同步,然后用一定的周期来确定采样信号。用3个或者6个,如果连续3个或者6个采样周期都采样到一样的电平,这认为是有效信号。采样周期通过GPACTRL寄存器设置。
采样周期:
能采样到的最短信号电平宽度:
配置步骤(参考文档SPRUFN3C):
1. 总体规划IO口。
2. 使能或者除能上拉电阻(GPxPUD)。
ePWM模式默认除能,其他功能默认使能。模拟IO没有上拉电阻。
3. 输入采样设置(GPxCTRL、 GPxQSELn)。
4. 选择引脚功能(GPxMUXn or AIOMUXn)。
5. 如果是数字IO的话,选择方向(GPxDIR or AIODIR)。
6. 选择低功耗模式下的唤醒输入引脚(GPIOLPMSEL)。
7. 选择中断源(GPIOxINTnSEL),极性(xINTnCR)。
程序设计:
实现板上的LED的驱动程序, LED相关IO的初始化都用同一个函数,分别提供了两种种方法改变LED的状态,一,通过一个函数实现。二、通过宏定义实现。第一种效率不高,占用程序存储空间较多,需要装载参数和调用指令,子函数里还有switch造成的跳转表等,但是可以用过同一个函数设置LED的状态,第二种效率高,通过三个调用设置三种状态,只是一个复制语句,相当于三条汇编指令。建议使用第二种,通过条件编译,保留第一种,但不编译。最后,写成两个LED.c和LED.h文件,供日后使用。
程序:
/********************************************* 标题:LED_test.c 软件平台:CCS v5.2 硬件平台:C2000 LaunchPad 主频:60M 描述:练习gpio,测试led 基于2802x C/C++ Header Files V1.26 author:小船 data:2012-09-23 As supplied, this project is configured for "boot to SARAM" operation. The 2802x Boot Mode table is shown below. $Boot_Table While an emulator is connected to your device, the TRSTn pin = 1, which sets the device into EMU_BOOT boot mode. In this mode, the peripheral boot modes are as follows: Boot Mode: EMU_KEY EMU_BMODE (0xD00) (0xD01) --------------------------------------- Wait !=0x55AA X I/O 0x55AA 0x0000 SCI 0x55AA 0x0001 Wait 0x55AA 0x0002 Get_Mode 0x55AA 0x0003 SPI 0x55AA 0x0004 I2C 0x55AA 0x0005 OTP 0x55AA 0x0006 Wait 0x55AA 0x0007 Wait 0x55AA 0x0008 SARAM 0x55AA 0x000A <-- "Boot to SARAM" Flash 0x55AA 0x000B Wait 0x55AA Other Write EMU_KEY to 0xD00 and EMU_BMODE to 0xD01 via the debugger according to the Boot Mode Table above. Build/Load project, Reset the device, and Run example $End_Boot_Table **********************************************/ #include "DSP28x_Project.h" // Device Headerfile and Examples Include File #define LED0 0x00000001 #define LED1 0x00000002 #define LED2 0x00000004 #define LED3 0x00000008 #define LED_on(LED_num) GpioDataRegs.GPACLEAR.all = LED_num #define LED_off(LED_num) GpioDataRegs.GPASET.all = LED_num #define LED_toggle(LED_num) GpioDataRegs.GPATOGGLE.all = LED_num #define config_leds_by_funtion #ifdef config_leds_by_funtion enum LED_action {on, off, toggle}; void LEDs(Uint32 LED_num, enum LED_action action); #endif // Prototype statements for functions found within this file. void Gpio_select(void); void LEDs_init(); void main(void) { // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP2802x_SysCtrl.c file. InitSysCtrl(); // Step 2. Initalize GPIO: // This example function is found in the DSP2802x_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: Gpio_select(); // 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 DSP2802x_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 DSP2802x_DefaultIsr.c. // This function is found in DSP2802x_PieVect.c. InitPieVectTable(); // Step 4. Initialize all the Device Peripherals: // This function is found in DSP2802x_InitPeripherals.c // InitPeripherals(); // Not required for this example // Step 5. User specific code: LEDs_init(); while(1) { LEDs(LED0|LED1|LED2|LED3, off); DELAY_US(1000000); LEDs(LED1, on); DELAY_US(1000000); LEDs(LED2, toggle); DELAY_US(1000000); LED_toggle(LED1); DELAY_US(1000000); } } void LEDs_init() { EALLOW; //使能上拉电阻 GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1; GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1; GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1; GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1; //选择GPIO功能 GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0x0; GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0x0; GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0x0; GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0x0; //方向 GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; GpioCtrlRegs.GPADIR.bit.GPIO3 = 1; EDIS; } #ifdef config_leds_by_funtion void LEDs(Uint32 LED_num, enum LED_action action) { switch (action) { case on:{ GpioDataRegs.GPACLEAR.all = LED_num; break; } case off:{ GpioDataRegs.GPASET.all = LED_num; break; } case toggle:{ GpioDataRegs.GPATOGGLE.all = LED_num; break; } } } #endif void Gpio_select(void) { EALLOW; GpioCtrlRegs.GPAMUX1.all = 0x00000000; // All GPIO GpioCtrlRegs.GPAMUX2.all = 0x00000000; // All GPIO GpioCtrlRegs.GPBMUX1.all = 0x00000000; // All GPIO GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF; // All outputs GpioCtrlRegs.GPBDIR.all = 0x0000000F; // All outputs EDIS; } //=========================================================================== // No more. //===========================================================================
/************************************ 标题:LEDs.h 软件平台:CCS v5.2 硬件平台:C2000 LaunchPad 主频:60M author:小船 data:2012-09-23 *************************************/ #ifndef LEDS_H_ #define LEDS_H_ #include "DSP28x_Project.h" #define no_config_leds_by_funtion #define LED0 0x00000001 #define LED1 0x00000002 #define LED2 0x00000004 #define LED3 0x00000008 #define LED_on(LED_num) GpioDataRegs.GPACLEAR.all = LED_num #define LED_off(LED_num) GpioDataRegs.GPASET.all = LED_num #define LED_toggle(LED_num) GpioDataRegs.GPATOGGLE.all = LED_num #ifdef config_leds_by_funtion enum LED_action {on, off, toggle}; void LEDs(Uint32 LED_num, enum LED_action action); #endif void LEDs_init(); #endif /* LEDS_H_ */
/************************************ 标题:LEDs.c 软件平台:CCS v5.2 硬件平台:C2000 LaunchPad 主频:60M author:小船 data:2012-09-23 *************************************/ #include "LEDs.h" void LEDs_init() { EALLOW; //使能上拉电阻 GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1; GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1; GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1; GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1; //选择GPIO功能 GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0x0; GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0x0; GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0x0; GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0x0; //方向 GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; GpioCtrlRegs.GPADIR.bit.GPIO3 = 1; EDIS; } #ifdef config_leds_by_funtion void LEDs(Uint32 LED_num, enum LED_action action) { switch (action) { case on:{ GpioDataRegs.GPACLEAR.all = LED_num; break; } case off:{ GpioDataRegs.GPASET.all = LED_num; break; } case toggle:{ GpioDataRegs.GPATOGGLE.all = LED_num; break; } } } #endif