00 建立开发版与仿真器的连接
打开文件TMS320F28335.ccxml
建立连接
显示下述信息说明连接成功
2 软件编程
1 系统时钟初始化
振荡器OSC和锁相环PLL初始化
注意:
在写PLLCR寄存器前,PLLSTS[DIVSEL]必须是0。
初始化函数
1
2InitSysCtrl();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20void InitSysCtrl(void) { // // Disable the watchdog // DisableDog(); // // Initialize the PLL control: PLLCR and DIVSEL // DSP28_PLLCR and DSP28_DIVSEL are defined in DSP2833x_Examples.h // InitPll(DSP28_PLLCR, DSP28_DIVSEL); // f=30M * DSP28_PLLCR / DSP28_DIVSEL =100MHZ // // Initialize the peripheral clocks // InitPeripheralClocks(); //使能外设时钟 }
1
2
3
4
5
6
7
8
9
10
11
12// Optional: Wait for PLL to lock. // During this time the CPU will switch to OSCCLK/2 until // the PLL is stable. Once the PLL is stable the CPU will // switch to the new PLL value. // // This time-to-lock is monitored by a PLL lock counter. // // Code is not required to sit and wait for the PLL to lock. // However, if the code does anything that is timing critical, // and requires the correct clock be locked, then it is best to // wait until this switching has completed.
//可选:等待PLL锁定。
//在此期间,CPU将切换至OSCCLK/2,直到
//锁相环是稳定的。一旦PLL稳定,CPU将
//切换到新的PLL值。
//
//锁定时间由PLL锁定计数器监控。
//
//代码不需要等待PLL锁定。
//但是,如果代码执行任何对时间至关重要的操作,
//并且需要锁定正确的时钟,那么最好
//等待此切换完成。
使能外设时钟
使能有关外设时钟的寄存器为PCLKCR0/1/3,GPIO初始化在PCLKCR3中
1
2SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1; // GPIO input clock
2 初始化GPIO
On the 2833x devices, up to three independent peripheral signals are multiplexed on a single GPIO-enabled pin in addition to individual pin bit I/O capability. There are three 32-bit I/O ports. Port A consists of GPIO0-GPIO31, port B consists of GPIO32-GPIO63, and port C consists of GPIO64-87.
Figure 4-1 shows the basic modes of operation for the GPIO module.
初始化函数
1
2InitGpio();
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
48void InitGpio(void) { EALLOW; // // Each GPIO pin can be: // a) a GPIO input/output // b) peripheral function 1 // c) peripheral function 2 // d) peripheral function 3 // By default, all are GPIO Inputs // GpioCtrlRegs.GPAMUX1.all = 0x0000; // GPIO functionality GPIO0-GPIO15 GpioCtrlRegs.GPAMUX2.all = 0x0000; // GPIO functionality GPIO16-GPIO31 GpioCtrlRegs.GPBMUX1.all = 0x0000; // GPIO functionality GPIO32-GPIO39 GpioCtrlRegs.GPBMUX2.all = 0x0000; // GPIO functionality GPIO48-GPIO63 GpioCtrlRegs.GPCMUX1.all = 0x0000; // GPIO functionality GPIO64-GPIO79 GpioCtrlRegs.GPCMUX2.all = 0x0000; // GPIO functionality GPIO80-GPIO95 GpioCtrlRegs.GPADIR.all = 0x0000; // GPIO0-GPIO31 are inputs GpioCtrlRegs.GPBDIR.all = 0x0000; // GPIO32-GPIO63 are inputs GpioCtrlRegs.GPCDIR.all = 0x0000; // GPI064-GPIO95 are inputs // // Each input can have different qualification // a) input synchronized to SYSCLKOUT // b) input qualified by a sampling window // c) input sent asynchronously (valid for peripheral inputs only) // 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 // // Pull-ups can be enabled or disabled // GpioCtrlRegs.GPAPUD.all = 0x0000; // Pullup's enabled GPIO0-GPIO31 GpioCtrlRegs.GPBPUD.all = 0x0000; // Pullup's enabled GPIO32-GPIO63 GpioCtrlRegs.GPCPUD.all = 0x0000; // Pullup's enabled GPIO64-GPIO79 // GpioCtrlRegs.GPAPUD.all = 0xFFFF; // Pullup's disabled GPIO0-GPIO31 // GpioCtrlRegs.GPBPUD.all = 0xFFFF; // Pullup's disabled GPIO32-GPIO34 // GpioCtrlRegs.GPCPUD.all = 0xFFFF; // Pullup's disabled GPIO64-GPIO79 EDIS; }
3 清除所有中断 和初始化 PIE 向量表
1
2
3
4
5
6DINT; // 禁用CPU中断 InitPieCtrl(); // 初始化 PIE 控制寄存器到默认状态,默认状态是全部 PIE 中断被禁用和标志位被清除 IER = 0x0000; // 禁用 CPU 中断和清除所有 CPU 中断标志位: IFR = 0x0000; InitPieVectTable(); // 初始化 PIE 中断向量表
4 添加用户具体代码
1
2LED_GPIO_Config(); // LED端口初始化
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
32void LED_GPIO_Config(void) { EALLOW; GpioCtrlRegs.GPAMUX1.bit.GPIO0=0;//普通IO模式 GpioCtrlRegs.GPAPUD.bit.GPIO0=0;//使能内部上拉 GpioCtrlRegs.GPADIR.bit.GPIO0=1;//配置成输出 GpioCtrlRegs.GPAMUX1.bit.GPIO1=0;//普通IO模式 GpioCtrlRegs.GPAPUD.bit.GPIO1=0;//使能内部上拉 GpioCtrlRegs.GPADIR.bit.GPIO1=1;//配置成输出 GpioCtrlRegs.GPAMUX1.bit.GPIO2=0;//普通IO模式 GpioCtrlRegs.GPAPUD.bit.GPIO2=0;//使能内部上拉 GpioCtrlRegs.GPADIR.bit.GPIO2=1;//配置成输出 GpioCtrlRegs.GPAMUX1.bit.GPIO3=0;//普通IO模式 GpioCtrlRegs.GPAPUD.bit.GPIO3=0;//使能内部上拉 GpioCtrlRegs.GPADIR.bit.GPIO3=1;//配置成输出 GpioCtrlRegs.GPAMUX1.bit.GPIO4=0;//普通IO模式 GpioCtrlRegs.GPAPUD.bit.GPIO4=0;//使能内部上拉 GpioCtrlRegs.GPADIR.bit.GPIO4=1;//配置成输出 GpioDataRegs. GPASET.bit.GPIO0=1; //输出高电平 GpioDataRegs. GPASET.bit.GPIO1=1; //输出高电平 GpioDataRegs. GPASET.bit.GPIO2=1; GpioDataRegs. GPASET.bit.GPIO3=1; GpioDataRegs. GPASET.bit.GPIO4=1; EDIS; }
输出高电平
1
2GpioDataRegs. GPASET.bit.GPIO0 = 1; //输出高电平
输出低电平
1
2GpioCtrlRegs.GPACLEAR.bit.GPIO0 = 1;
5 编写主循环
1
2
3
4
5
6
7
8
9
10
11while(1) { for ( i = 0; i < 5; i++) { GpioDataRegs.GPACLEAR.all = (0x01 << i); delay_1ms(1000); GpioDataRegs.GPASET.all = (0x01 << i); delay_1ms(1000); } }
最后
以上就是微笑大象最近收集整理的关于DSP学习(一)GPIO操作00 建立开发版与仿真器的连接2 软件编程的全部内容,更多相关DSP学习(一)GPIO操作00内容请搜索靠谱客的其他文章。
发表评论 取消回复