主要从《手把手教你学DSP—基于TMS320F28335》、《TMS320F28335DSP原理与开发编程》这两本书,及网上资料汇聚而成。
DSP28335 GPIO模块分为三类IO口:PORTA(0-31),PORTB(32-63),PORTC(64-87)。对GPIO模块的设置主要通过三类寄存器来完成,分别是:控制寄存器、数据寄存器、中断寄存器。
1、控制寄存器
GPxCTRL; // GPIO x Control Register (GPIO0 to 31)
//设置采样窗周期T=2*GPXCTRL*Tsysclk;
GPxQSEL1; // GPIO x Qualifier Select 1 Register (GPIO0 to 15)(32-47)
GPxQSEL2; // GPIO x Qualifier Select 2 Register (GPIO16 to 31)(48-63)
//每两位控制一个引脚,确定是3周期采样还是6周期采样或者不用采样
GPxMUX1; // GPIO x Mux 1 Register (GPIO0 to 15)(32-47)(64-79)
GPxMUX2; // GPIO x Mux 2 Register (GPIO16 to 31)(48-63)(80-95)
//配置各个引脚的功能,0:I/O功能,1:外设功能。
GPxDIR; // GPIO x Direction Register (GPIO0 to 31)(32-63)(64-95)
//配置每个引脚是输入还是输出,0:数字量输入;1:数字量输出。
GPxPUD; // GPIO x Pull Up Disable Register (GPIO0 to 31)(32-63)(64-95)
//使能或禁止内部上拉 0:开启上拉,1:禁止上拉
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
2、数据寄存器
GPxDAT; // GPIO Data Register (GPIO0 to 31)(32-63)(64-95)
GPxSET; // GPIO Data Set Register (GPIO0 to 31)(32-63)(64-95)——置位
GPxCLEAR; // GPIO Data Clear Register (GPIO0 to 31)(32-63)(64-95)
GPxTOGGLE; // GPIO Data Toggle Register (GPIO0 to 31)(32-63)(64-95)—反转
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
3、中断寄存器
GPIOXINT1SEL; // XINT1 GPIO Input Selection
GPIOXINT2SEL; // XINT2 GPIO Input Selection
GPIOXNMISEL; // XNMI_Xint13 GPIO Input Selection
GPIOXINT3SEL; // XINT3 GPIO Input Selection
GPIOXINT4SEL; // XINT4 GPIO Input Selection
GPIOXINT5SEL; // XINT5 GPIO Input Selection
GPIOXINT6SEL; // XINT6 GPIO Input Selection
GPIOXINT7SEL; // XINT7 GPIO Input Selection
GPIOLPMSEL; // Low power modes GP I/O input select
可以对GPIO0-63进行外部中断设置;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
IT官方的头文件DSP2833x_Gpio.h内容如下:
// TI File $Revision: /main/4 $
// Checkin $Date: November 15, 2007 09:58:53 $
//###########################################################################
//
// FILE: DSP2833x_Gpio.h
//
// TITLE: DSP2833x 一般应用 I/O 定义.
//
//###########################################################################
// $TI Release: DSP2833x/DSP2823x C/C++ Header Files V1.31 $
// $Release Date: August 4, 2009 $
//###########################################################################
#ifndef DSP2833x_GPIO_H
#define DSP2833x_GPIO_H
#ifdef __cplusplus
extern "C" {
#endif
//----------------------------------------------------
// GPIO A 控制寄存器位定义 */
struct GPACTRL_BITS { // bits 描述
Uint16 QUALPRD0:8; // 7:0 采样周期
Uint16 QUALPRD1:8; // 15:8 采样周期
Uint16 QUALPRD2:8; // 23:16 采样周期
Uint16 QUALPRD3:8; // 31:24 采样周期
};
//GPIO A 控制寄存器
union GPACTRL_REG {
Uint32 all;
struct GPACTRL_BITS bit; //GPIO A 控制寄存器位定义
};
//----------------------------------------------------
// GPIO B 控制寄存器位定义 */
struct GPBCTRL_BITS { // bits 描述
Uint16 QUALPRD0:8; // 7:0 采样周期
Uint16 QUALPRD1:8; // 15:8 采样周期
Uint16 QUALPRD2:8; // 23:16 采样周期
Uint16 QUALPRD3:8; // 31:24 采样周期
};
//GPIO B 控制寄存器
union GPBCTRL_REG {
Uint32 all;
struct GPBCTRL_BITS bit; //GPIO B 控制寄存器位定义
};
//----------------------------------------------------
// GPIO A Qual/MUX 选择寄存器位定义 */
struct GPA1_BITS { // bits 描述
Uint16 GPIO0:2; // 1:0 GPIO0
Uint16 GPIO1:2; // 3:2 GPIO1
Uint16 GPIO2:2; // 5:4 GPIO2
Uint16 GPIO3:2; // 7:6 GPIO3
Uint16 GPIO4:2; // 9:8 GPIO4
Uint16 GPIO5:2; // 11:10 GPIO5
Uint16 GPIO6:2; // 13:12 GPIO6
Uint16 GPIO7:2; // 15:14 GPIO7
Uint16 GPIO8:2; // 17:16 GPIO8
Uint16 GPIO9:2; // 19:18 GPIO9
Uint16 GPIO10:2; // 21:20 GPIO10
Uint16 GPIO11:2; // 23:22 GPIO11
Uint16 GPIO12:2; // 25:24 GPIO12
Uint16 GPIO13:2; // 27:26 GPIO13
Uint16 GPIO14:2; // 29:28 GPIO14
Uint16 GPIO15:2; // 31:30 GPIO15
};
struct GPA2_BITS { // bits 描述
Uint16 GPIO16:2; // 1:0 GPIO16
Uint16 GPIO17:2; // 3:2 GPIO17
Uint16 GPIO18:2; // 5:4 GPIO18
Uint16 GPIO19:2; // 7:6 GPIO19
Uint16 GPIO20:2; // 9:8 GPIO20
Uint16 GPIO21:2; // 11:10 GPIO21
Uint16 GPIO22:2; // 13:12 GPIO22
Uint16 GPIO23:2; // 15:14 GPIO23
Uint16 GPIO24:2; // 17:16 GPIO24
Uint16 GPIO25:2; // 19:18 GPIO25
Uint16 GPIO26:2; // 21:20 GPIO26
Uint16 GPIO27:2; // 23:22 GPIO27
Uint16 GPIO28:2; // 25:24 GPIO28
Uint16 GPIO29:2; // 27:26 GPIO29
Uint16 GPIO30:2; // 29:28 GPIO30
Uint16 GPIO31:2; // 31:30 GPIO31
};
// GPIO B Qual/MUX 选择寄存器位定义 */
struct GPB1_BITS { // bits 描述
Uint16 GPIO32:2; // 1:0 GPIO32
Uint16 GPIO33:2; // 3:2 GPIO33
Uint16 GPIO34:2; // 5:4 GPIO34
Uint16 GPIO35:2; // 7:6 GPIO35
Uint16 GPIO36:2; // 9:8 GPIO36
Uint16 GPIO37:2; // 11:10 GPIO37
Uint16 GPIO38:2; // 13:12 GPIO38
Uint16 GPIO39:2; // 15:14 GPIO39
Uint16 GPIO40:2; // 17:16 GPIO40
Uint16 GPIO41:2; // 19:16 GPIO41
Uint16 GPIO42:2; // 21:20 GPIO42
Uint16 GPIO43:2; // 23:22 GPIO43
Uint16 GPIO44:2; // 25:24 GPIO44
Uint16 GPIO45:2; // 27:26 GPIO45
Uint16 GPIO46:2; // 29:28 GPIO46
Uint16 GPIO47:2; // 31:30 GPIO47
};
struct GPB2_BITS { // bits 描述
Uint16 GPIO48:2; // 1:0 GPIO48
Uint16 GPIO49:2; // 3:2 GPIO49
Uint16 GPIO50:2; // 5:4 GPIO50
Uint16 GPIO51:2; // 7:6 GPIO51
Uint16 GPIO52:2; // 9:8 GPIO52
Uint16 GPIO53:2; // 11:10 GPIO53
Uint16 GPIO54:2; // 13:12 GPIO54
Uint16 GPIO55:2; // 15:14 GPIO55
Uint16 GPIO56:2; // 17:16 GPIO56
Uint16 GPIO57:2; // 19:18 GPIO57
Uint16 GPIO58:2; // 21:20 GPIO58
Uint16 GPIO59:2; // 23:22 GPIO59
Uint16 GPIO60:2; // 25:24 GPIO60
Uint16 GPIO61:2; // 27:26 GPIO61
Uint16 GPIO62:2; // 29:28 GPIO62
Uint16 GPIO63:2; // 31:30 GPIO63
};
// GPIO C Qual/MUX 选择寄存器位定义 */
struct GPC1_BITS { // bits 描述
Uint16 GPIO64:2; // 1:0 GPIO64
Uint16 GPIO65:2; // 3:2 GPIO65
Uint16 GPIO66:2; // 5:4 GPIO66
Uint16 GPIO67:2; // 7:6 GPIO67
Uint16 GPIO68:2; // 9:8 GPIO68
Uint16 GPIO69:2; // 11:10 GPIO69
Uint16 GPIO70:2; // 13:12 GPIO70
Uint16 GPIO71:2; // 15:14 GPIO71
Uint16 GPIO72:2; // 17:16 GPIO72
Uint16 GPIO73:2; // 19:18 GPIO73
Uint16 GPIO74:2; // 21:20 GPIO74
Uint16 GPIO75:2; // 23:22 GPIO75
Uint16 GPIO76:2; // 25:24 GPIO76
Uint16 GPIO77:2; // 27:26 GPIO77
Uint16 GPIO78:2; // 29:28 GPIO78
Uint16 GPIO79:2; // 31:30 GPIO79
};
struct GPC2_BITS { // bits 描述
Uint16 GPIO80:2; // 1:0 GPIO80
Uint16 GPIO81:2; // 3:2 GPIO81
Uint16 GPIO82:2; // 5:4 GPIO82
Uint16 GPIO83:2; // 7:6 GPIO83
Uint16 GPIO84:2; // 9:8 GPIO84
Uint16 GPIO85:2; // 11:10 GPIO85
Uint16 GPIO86:2; // 13:12 GPIO86
Uint16 GPIO87:2; // 15:14 GPIO87
Uint16 rsvd:16; // 31:16 保留
};
// GPIO A Qual/MUX 选择寄存器 */
union GPA1_REG {
Uint32 all;
struct GPA1_BITS bit;
};
union GPA2_REG {
Uint32 all;
struct GPA2_BITS bit;
};
// GPIO B Qual/MUX 选择寄存器 */
union GPB1_REG {
Uint32 all;
struct GPB1_BITS bit;
};
union GPB2_REG {
Uint32 all;
struct GPB2_BITS bit;
};
// GPIO C Qual/MUX 选择寄存器 */
union GPC1_REG {
Uint32 all;
struct GPC1_BITS bit;
};
union GPC2_REG {
Uint32 all;
struct GPC2_BITS bit;
};
//----------------------------------------------------
// GPIO A DIR/TOGGLE/SET/CLEAR 寄存器位定义 */
struct GPADAT_BITS { // bits 描述
Uint16 GPIO0:1; // 0 GPIO0
Uint16 GPIO1:1; // 1 GPIO1
Uint16 GPIO2:1; // 2 GPIO2
Uint16 GPIO3:1; // 3 GPIO3
Uint16 GPIO4:1; // 4 GPIO4
Uint16 GPIO5:1; // 5 GPIO5
Uint16 GPIO6:1; // 6 GPIO6
Uint16 GPIO7:1; // 7 GPIO7
Uint16 GPIO8:1; // 8 GPIO8
Uint16 GPIO9:1; // 9 GPIO9
Uint16 GPIO10:1; // 10 GPIO10
Uint16 GPIO11:1; // 11 GPIO11
Uint16 GPIO12:1; // 12 GPIO12
Uint16 GPIO13:1; // 13 GPIO13
Uint16 GPIO14:1; // 14 GPIO14
Uint16 GPIO15:1; // 15 GPIO15
Uint16 GPIO16:1; // 16 GPIO16
Uint16 GPIO17:1; // 17 GPIO17
Uint16 GPIO18:1; // 18 GPIO18
Uint16 GPIO19:1; // 19 GPIO19
Uint16 GPIO20:1; // 20 GPIO20
Uint16 GPIO21:1; // 21 GPIO21
Uint16 GPIO22:1; // 22 GPIO22
Uint16 GPIO23:1; // 23 GPIO23
Uint16 GPIO24:1; // 24 GPIO24
Uint16 GPIO25:1; // 25 GPIO25
Uint16 GPIO26:1; // 26 GPIO26
Uint16 GPIO27:1; // 27 GPIO27
Uint16 GPIO28:1; // 28 GPIO28
Uint16 GPIO29:1; // 29 GPIO29
Uint16 GPIO30:1; // 30 GPIO30
Uint16 GPIO31:1; // 31 GPIO31
};
// GPIO B DIR/TOGGLE/SET/CLEAR 寄存器位定义 */
struct GPBDAT_BITS { // bits 描述
Uint16 GPIO32:1; // 0 GPIO32
Uint16 GPIO33:1; // 1 GPIO33
Uint16 GPIO34:1; // 2 GPIO34
Uint16 GPIO35:1; // 3 GPIO35
Uint16 GPIO36:1; // 4 GPIO36
Uint16 GPIO37:1; // 5 GPIO37
Uint16 GPIO38:1; // 6 GPIO38
Uint16 GPIO39:1; // 7 GPIO39
Uint16 GPIO40:1; // 8 GPIO40
Uint16 GPIO41:1; // 9 GPIO41
Uint16 GPIO42:1; // 10 GPIO42
Uint16 GPIO43:1; // 11 GPIO43
Uint16 GPIO44:1; // 12 GPIO44
Uint16 GPIO45:1; // 13 GPIO45
Uint16 GPIO46:1; // 14 GPIO46
Uint16 GPIO47:1; // 15 GPIO47
Uint16 GPIO48:1; // 16 GPIO48
Uint16 GPIO49:1; // 17 GPIO49
Uint16 GPIO50:1; // 18 GPIO50
Uint16 GPIO51:1; // 19 GPIO51
Uint16 GPIO52:1; // 20 GPIO52
Uint16 GPIO53:1; // 21 GPIO53
Uint16 GPIO54:1; // 22 GPIO54
Uint16 GPIO55:1; // 23 GPIO55
Uint16 GPIO56:1; // 24 GPIO56
Uint16 GPIO57:1; // 25 GPIO57
Uint16 GPIO58:1; // 26 GPIO58
Uint16 GPIO59:1; // 27 GPIO59
Uint16 GPIO60:1; // 28 GPIO60
Uint16 GPIO61:1; // 29 GPIO61
Uint16 GPIO62:1; // 30 GPIO62
Uint16 GPIO63:1; // 31 GPIO63
};
// GPIO C DIR/TOGGLE/SET/CLEAR 寄存器位定义 */
struct GPCDAT_BITS { // bits 描述
Uint16 GPIO64:1; // 0 GPIO64
Uint16 GPIO65:1; // 1 GPIO65
Uint16 GPIO66:1; // 2 GPIO66
Uint16 GPIO67:1; // 3 GPIO67
Uint16 GPIO68:1; // 4 GPIO68
Uint16 GPIO69:1; // 5 GPIO69
Uint16 GPIO70:1; // 6 GPIO70
Uint16 GPIO71:1; // 7 GPIO71
Uint16 GPIO72:1; // 8 GPIO72
Uint16 GPIO73:1; // 9 GPIO73
Uint16 GPIO74:1; // 10 GPIO74
Uint16 GPIO75:1; // 11 GPIO75
Uint16 GPIO76:1; // 12 GPIO76
Uint16 GPIO77:1; // 13 GPIO77
Uint16 GPIO78:1; // 14 GPIO78
Uint16 GPIO79:1; // 15 GPIO79
Uint16 GPIO80:1; // 16 GPIO80
Uint16 GPIO81:1; // 17 GPIO81
Uint16 GPIO82:1; // 18 GPIO82
Uint16 GPIO83:1; // 19 GPIO83
Uint16 GPIO84:1; // 20 GPIO84
Uint16 GPIO85:1; // 21 GPIO85
Uint16 GPIO86:1; // 22 GPIO86
Uint16 GPIO87:1; // 23 GPIO87
Uint16 rsvd1:8; // 31:24 reserved
};
// GPIO A DIR/TOGGLE/SET/CLEAR 寄存器 */
union GPADAT_REG {
Uint32 all;
struct GPADAT_BITS bit;
};
// GPIO B DIR/TOGGLE/SET/CLEAR 寄存器 */
union GPBDAT_REG {
Uint32 all;
struct GPBDAT_BITS bit;
};
// GPIO C DIR/TOGGLE/SET/CLEAR 寄存器 */
union GPCDAT_REG {
Uint32 all;
struct GPCDAT_BITS bit;
};
//----------------------------------------------------
// GPIO Xint1/XINT2/XNMI 选择寄存器位定义 */
struct GPIOXINT_BITS { // bits 描述
Uint16 GPIOSEL:5; // 4:0 选择GPIO中断输入源
Uint16 rsvd1:11; // 15:5 保留
};
// GPIO Xint1/XINT2/XNMI 选择寄存 */
union GPIOXINT_REG {
Uint16 all;
struct GPIOXINT_BITS bit;
};
//GPIO控制寄存器
struct GPIO_CTRL_REGS {
union GPACTRL_REG GPACTRL; // GPIO A 控制寄存器 (GPIO0 to 31)
union GPA1_REG GPAQSEL1; // GPIO A 选择输入限制1 (GPIO0 to 15)
union GPA2_REG GPAQSEL2; // GPIO A 选择输入限制2 (GPIO16 to 31)
union GPA1_REG GPAMUX1; // GPIO A 选择寄存器1 (GPIO0 to 15)
union GPA2_REG GPAMUX2; // GPIO A 选择寄存器2 (GPIO16 to 31)
union GPADAT_REG GPADIR; // GPIO A 输入输出方向 (GPIO0 to 31)
union GPADAT_REG GPAPUD; // GPIO A 上拉禁用寄存器 (GPIO0 to 31)
Uint32 rsvd1; // 保留
union GPBCTRL_REG GPBCTRL; // GPIO B 控制寄存器 (GPIO32 to 63)
union GPB1_REG GPBQSEL1; // GPIO B 选择输入限制1 (GPIO32 to 47)
union GPB2_REG GPBQSEL2; // GPIO B 选择输入限制2 (GPIO48 to 63)
union GPB1_REG GPBMUX1; // GPIO B 选择寄存器1 (GPIO32 to 47)
union GPB2_REG GPBMUX2; // GPIO B 选择寄存器2 (GPIO48 to 63)
union GPBDAT_REG GPBDIR; // GPIO B 输入输出方向 (GPIO32 to 63)
union GPBDAT_REG GPBPUD; // GPIO B 上拉禁用寄存器 (GPIO32 to 63)
Uint16 rsvd2[8];
union GPC1_REG GPCMUX1; // GPIO C 选择寄存器1 (GPIO64 to 79)
union GPC2_REG GPCMUX2; // GPIO C 选择寄存器2 (GPIO80 to 95)
union GPCDAT_REG GPCDIR; // GPIO C 输入输出方向 (GPIO64 to 95)
union GPCDAT_REG GPCPUD; // GPIO C 上拉禁用寄存器 (GPIO64 to 95)
};
//GPIO控制寄存器
struct GPIO_DATA_REGS {
union GPADAT_REG GPADAT; // GPIO 数据寄存器 (GPIO0 to 31)
union GPADAT_REG GPASET; // GPIO 置位数据寄存器 (GPIO0 to 31)
union GPADAT_REG GPACLEAR; // GPIO 置零数据寄存器 (GPIO0 to 31)
union GPADAT_REG GPATOGGLE; // GPIO 数据翻转寄存器 (GPIO0 to 31)
union GPBDAT_REG GPBDAT; // GPIO 数据寄存器 (GPIO32 to 63)
union GPBDAT_REG GPBSET; // GPIO 置位数据寄存器 (GPIO32 to 63)
union GPBDAT_REG GPBCLEAR; // GPIO 置零数据寄存器 (GPIO32 to 63)
union GPBDAT_REG GPBTOGGLE; // GPIO 数据翻转寄存器 (GPIO32 to 63)
union GPCDAT_REG GPCDAT; // GPIO 数据寄存器 (GPIO64 to 95)
union GPCDAT_REG GPCSET; // GPIO 置位数据寄存器 (GPIO64 to 95)
union GPCDAT_REG GPCCLEAR; // GPIO 置零数据寄存器 (GPIO64 to 95)
union GPCDAT_REG GPCTOGGLE; // GPIO 数据翻转寄存器 (GPIO64 to 95)
Uint16 rsvd1[8];
};
//GPIO中断寄存器
struct GPIO_INT_REGS {
union GPIOXINT_REG GPIOXINT1SEL; // XINT1 GPIO 输入选择
union GPIOXINT_REG GPIOXINT2SEL; // XINT2 GPIO 输入选择
union GPIOXINT_REG GPIOXNMISEL; // XNMI_Xint13 GPIO 输入选择
union GPIOXINT_REG GPIOXINT3SEL; // XINT3 GPIO 输入选择
union GPIOXINT_REG GPIOXINT4SEL; // XINT4 GPIO 输入选择
union GPIOXINT_REG GPIOXINT5SEL; // XINT5 GPIO 输入选择
union GPIOXINT_REG GPIOXINT6SEL; // XINT6 GPIO 输入选择
union GPIOXINT_REG GPIOXINT7SEL; // XINT7 GPIO 输入选择
union GPADAT_REG GPIOLPMSEL; // 唤醒低功耗模式源选择寄存器
};
//---------------------------------------------------------------------------
// GPI/O 外部引用和函数声明:
//
extern volatile struct GPIO_CTRL_REGS GpioCtrlRegs;
extern volatile struct GPIO_DATA_REGS GpioDataRegs;
extern volatile struct GPIO_INT_REGS GpioIntRegs;
#ifdef __cplusplus
}
#endif /* extern "C" */
#endif // end of DSP2833x_GPIO_H definition
//===========================================================================
// End of file.
//===========================================================================
- 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
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
在《手把手教你学DSP》的第六章为GPIO介绍,在配套例程配套文档例程资料\CCS4.12\lab2-GPIO_SETUP下的DSP2833x_Gpio.c程序如下:
// TI File $Revision: /main/1 $
// Checkin $Date: August 18, 2006 13:46:25 $
//###########################################################################
//
// FILE: DSP2833x_Gpio.c
//
// TITLE: DSP2833x 通用 I/O 初始化& 支持函数.
//
//###########################################################################
// $TI Release: DSP2833x Header Files V1.01 $
// $Release Date: September 26, 2007 $
//###########################################################################
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
//---------------------------------------------------------------------------
// InitGpio:
//---------------------------------------------------------------------------
// 该函数初始化到一个已知的(默认)状态.
//
// 更多关于配置GPIO外围功能的细节,
// 请参照个人设置的外围例子/或 GPIO 设置示例.
void InitGpio(void)
{
EALLOW;
// 每个 GPIO pin 都可以:
// a) a GPIO 输入/输出
// b) 外设功能 1
// c) 外设功能 2
// d) 外设功能 3
// 默认情况下, 所有的 GPIO 都为输入
GpioCtrlRegs.GPAMUX1.all = 0x0000; // GPIO 功能 GPIO0-GPIO15
GpioCtrlRegs.GPAMUX2.all = 0x0000; // GPIO 功能 GPIO16-GPIO31
GpioCtrlRegs.GPBMUX1.all = 0x0000; // GPIO 功能 GPIO32-GPIO39
GpioCtrlRegs.GPBMUX2.all = 0x0000; // GPIO 功能 GPIO48-GPIO63
GpioCtrlRegs.GPCMUX1.all = 0x0000; // GPIO 功能 GPIO64-GPIO79
GpioCtrlRegs.GPCMUX2.all = 0x0000; // GPIO 功能 GPIO80-GPIO95
GpioCtrlRegs.GPADIR.all = 0x0000; // GPIO0-GPIO31 都为输入
GpioCtrlRegs.GPBDIR.all = 0x0000; // GPIO32-GPIO63 都为输入
GpioCtrlRegs.GPCDIR.all = 0x0000; // GPI064-GPIO95 都为输入
// 每个输入都可以有不同的限制
// a) 输入信号同步 to SYSCLKOUT
// b) 输入合适的采样窗口
// c) 异步输入模式 (仅外围输入有效)
GpioCtrlRegs.GPAQSEL1.all = 0x0000; // GPIO0-GPIO15 同步 to SYSCLKOUT
GpioCtrlRegs.GPAQSEL2.all = 0x0000; // GPIO16-GPIO31 同步 to SYSCLKOUT
GpioCtrlRegs.GPBQSEL1.all = 0x0000; // GPIO32-GPIO39 同步 to SYSCLKOUT
GpioCtrlRegs.GPBQSEL2.all = 0x0000; // GPIO48-GPIO63 同步 to SYSCLKOUT
// 上拉可以禁止或使能.
GpioCtrlRegs.GPAPUD.all = 0x0000; // 启用上拉 GPIO0-GPIO31
GpioCtrlRegs.GPBPUD.all = 0xffff;//0x0000; // 启用上拉 GPIO32-GPIO63
GpioCtrlRegs.GPCPUD.all = 0x0000; // 启用上拉 GPIO64-GPIO79
//GpioCtrlRegs.GPAPUD.all = 0xFFFF; // 禁止上拉 GPIO0-GPIO31
//GpioCtrlRegs.GPBPUD.all = 0xFFFF; // 禁止上拉 GPIO32-GPIO34
//GpioCtrlRegs.GPCPUD.all = 0xFFFF // 禁止上拉 GPIO64-GPIO79
EDIS;
}
//===========================================================================
// End of file.
//===========================================================================
- 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
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
GPIO的控制实例在《手把手教你学DSP》配套例程CCS4.12\lab1-GPIO_LED下控制LED灯闪烁
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#define LED1 GpioDataRegs.GPADAT.bit.GPIO0 //数据寄存器宏定义
#define LED2 GpioDataRegs.GPADAT.bit.GPIO1
#define LED3 GpioDataRegs.GPADAT.bit.GPIO2
#define LED4 GpioDataRegs.GPADAT.bit.GPIO3
#define LED5 GpioDataRegs.GPADAT.bit.GPIO4
#define LED6 GpioDataRegs.GPADAT.bit.GPIO5
interrupt void ISRTimer0(void);
void configtestled(void);
void main(void)
{
// 步骤 1. 初始化系统控制:
// PLL, WatchDog, 使能外围时钟
// 这个函数在 DSP2833x_SysCtrl.c 文件中.
InitSysCtrl();
// 步骤 2. 初始化设置 GPIO:
// 这个函数例子在 DSP2833x_Gpio.c 文件中
// 说明了如何设置GPIO的默认状态.
// InitGpio(); // 跳过这个函数
InitXintf16Gpio(); //zq
// 步骤 3. 清除所有中断向量和初始化向量表:
// 禁止CPU中断
DINT;
// 初始化PIE控制寄存器的默认状态.
// 默认状态是所有的中断和中断标志被清除
// 这个函数在 DSP2833x_PieCtrl.c 文件中.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// 初始化中断向量表的地址指针
// 中断服务程序 (ISR).
// 即使不使用中断也要将表格填充满, 这样的目的是用于调试.
// 这个函数在 DSP2833x_DefaultIsr.c文件中
// 这个函数在 DSP2833x_PieVect.c.文件中
InitPieVectTable();
configtestled();
LED1=1;
DELAY_US(10);
LED2=1;
DELAY_US(10);
LED3=1;
DELAY_US(10);
LED4=0;
DELAY_US(10);
LED5=0;
DELAY_US(10);
LED6=0;
DELAY_US(10);
while(1){
LED1=~LED1;
DELAY_US(50000);
LED2=~LED2;
DELAY_US(50000);
LED3=~LED3;
DELAY_US(50000);
LED4=~LED4;
DELAY_US(50000);
LED5=~LED5;
DELAY_US(50000);
LED6=~LED6;
DELAY_US(50000);
}
}
void configtestled(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; // GPIO0 = GPIO0
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; // 输出
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0; // GPIO1 = GPIO1
GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; // 输出
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0; // GPIO2 = GPIO2
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; // 输出
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0; // GPIO3 = GPIO3
GpioCtrlRegs.GPADIR.bit.GPIO3 = 1; // 输出
GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0; // GPIO4 = GPIO4
GpioCtrlRegs.GPADIR.bit.GPIO4 = 1; // 输出
GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0; // GPIO5 = GPIO5
GpioCtrlRegs.GPADIR.bit.GPIO5 = 1; // 输出
EDIS;
}
//===========================================================================
// No more.
//===========================================================================
- 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
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
参考资料
百度文库_第5章通用输入输出学习要点
电子工程世界-TMS320F28335项目开发记录8_28335之GPIO引脚