DSP 5416如何把McBSP设置为普通IO口?如何定义?
- UID
- 827359
|
DSP 5416如何把McBSP设置为普通IO口?如何定义?
请举例说明! 我是要用3个IO口做液晶串行输出显示!! 谢谢 |
|
|
|
|
|
- UID
- 827359
|
求高人求解 datasheet 也看过 也试过 但是就是不行 急啊 |
|
|
|
|
|
- UID
- 532160
- 性别
- 男
|
McBSP模块配置为LCD12864的SPI接口
本帖最后由 yibiyuan 于 2010-12-2 09:41 编辑
McBSP模块配置为LCD12864的SPI接口void LcdObj:cdSpiSetup(void)
{
#if (ccsdebug == 0)
/*-----------------------------------------------------------
硬件McBSP模块配置为SPI接口
实验目的:
演练硬件McBSP模块配置为SPI接口的应用。
------------------------------------------------------------*/
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
// McBSP1->SPSD &= ~(1 << SPCR1_RRST);//禁止串口接收
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = 0;
// McBSP1->SPSD &= ~(1 << SPCR2_XRST);//禁止串口发送
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = (0x02 << SPCR1_CLKSTP);//CLKSTP=10b
_delay_loop_(1);//延时等待
McBSP1->SPSA = PCR;
McBSP1->SPSD = (1 << PCR_FSXM) //设置FSX引脚为输出,控制LCD12864的片选信号SS
(0 << PCR_FSXP) //FSX引脚平时输出低电平(LCD12864的片选信号SS无效)
(1 << PCR_CLKXM) //设置CLKX引脚为输出
(1 << PCR_CLKXP);//CLKXP引脚平时输出高电平
_delay_loop_(1);//延时等待
McBSP1->SPSA = SRGR1;
McBSP1->SPSD = (0x07 << SRGR1_FWID) //0x00~0x07~0xff
(0x80 << SRGR1_CLKGDV);//速率0x80
_delay_loop_(1);//延时等待
McBSP1->SPSA = SRGR2;
McBSP1->SPSD = (1 << SRGR2_CLKSM);//
_delay_loop_(1);//延时等待
McBSP1->SPSA = RCR1;
McBSP1->SPSD = (0x00 << RCR1_RFRLEN1);//8BIT
_delay_loop_(1);//延时等待
McBSP1->SPSA = XCR1;//延时等待
McBSP1->SPSD = (0x00 << XCR1_RFRLEN1);//8BIT
_delay_loop_(1);//延时等待
McBSP1->SPSA = RCR2;
McBSP1->SPSD = (0x02 << RCR2_RDATDLY);//0x01
_delay_loop_(1);//延时等待
McBSP1->SPSA = XCR2;
McBSP1->SPSD = (0x02 << XCR2_RDATDLY);//0x01
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = (1 << SPCR2_GRST) (1 << SPCR2_XRST) (1 << SPCR2_FRST);
_delay_loop_(1);//延时等待
#else
/*-----------------------------------------------------------
硬件McBSP模块配置为普通IO软件模拟SPI时序
实验目的:
演练硬件McBSP模块配置为普通IO的应用.以备IO紧缺时急用。
------------------------------------------------------------*/
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
McBSP1->SPSD &= ~(1 << SPCR1_RRST);//禁止串口接收
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = 0;
McBSP1->SPSD &= ~(1 << SPCR2_XRST);//禁止串口发送
McBSP1->SPSA = PCR;
McBSP1->SPSD = (1 << PCR_XIOEN) (1 << PCR_RIOEN);//设置收发为IO接口,DX输出,DR,CLKS输入
McBSP1->SPSD = (1 << PCR_FSXM) (1 << PCR_CLKXM);//设置FSX,CLKX可做IO输出
McBSP1->SPSD = (1 << PCR_FSRM) (1 << PCR_CLKRM);//设置FSR,CLKR可做IO输出
McBSP1->SPSD &= ~(1 << PCR_FSXP);//FSX信号=0
McBSP1->SPSD = (1 << PCR_CLKXP);//CLKX信号=1
McBSP1->SPSD = (1 << PCR_DX_STAT);//DX信号=1
#endif
}
void LcdObj:cdSend(unsigned char cData)
{
cData &= 0xff;
#if (ccsdebug == 0)
McBSP1->DXR1 = cData;//发送串行数据或命令
_delay_loop_(1);//延时等待
McBSP1->SPSA = SPCR2;
while((McBSP1->SPSD & (1 << SPCR2_XRDY)) == 0) {//等待发送结束
__nop();
__nop();
}
_delay_loop_(1);//延时等待
#else
unsigned int i;
McBSP1->SPSA = PCR;
for (i = 0; i < 8; i ++) {
McBSP1->SPSD &= ~(1 << PCR_CLKXP);//CLKX信号=0
_delay_loop_(1);//延时等待
if (cData & 0x80) {//MSB最高位为1时
McBSP1->SPSD = (1 << PCR_DX_STAT);//DX信号=1
}
else {
McBSP1->SPSD &= ~(1 << PCR_DX_STAT);//DX信号=0
}
cData <<= 1;
_delay_loop_(1);//延时等待
McBSP1->SPSD = (1 << PCR_CLKXP);//CLKX信号=1
_delay_loop_(1);//延时等待
}
McBSP1->SPSD = (1 << PCR_DX_STAT);//DX信号=1
_delay_loop_(1);//延时等待
#endif
} |
|
|
|
|
|
- UID
- 532160
- 性别
- 男
|
|
|
|
|
|
- UID
- 532160
- 性别
- 男
|
|
|
|
|
|
- UID
- 827359
|
这是两段还是一段程序? 能加个QQ吗? 3# yibiyuan |
|
|
|
|
|
- UID
- 824598
|
|
|
|
|
|
- UID
- 827359
|
好难理解
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
是什么意思? McBSP1->SPSA是什么意思?能这样用吗? 好像没定义
7# m1_ljp |
|
|
|
|
|
- UID
- 799481
|
指针 要看全这个程序 不是有PDF资料吗 好好看看 |
|
|
|
|
|
- UID
- 827359
|
研究了一天,看出点眉目,能把头文件发下吗?结构体McBSP1的定义,PCR位的定义? 5# yibiyuan |
|
|
|
|
|
- UID
- 898670
- 性别
- 男
- 来自
- 北京 丰台
|
1、DSP5416的McBSP模块配置为普通IO,通过McBSP子区地址寄存器SPSA和数据寄存器SPSD对管脚控制寄存器PCR相关位操作.SPSA用于选中地址,SPSD用于数据访问。
先在SPCR1和SPCR2中禁止串口收发,然后在PCR高8位设置成GPIO,最后在PCR低8位写数据;
2、从http://www.alldatasheet.com查看TMS320VC5416-120.PDF资料,第3.16节 是McBSP 控制寄存器和子地址,第3.8节有McBSPs的位定义。
3、Figure 3-12. Pin Control Register (PCR)是位定义
15 14 13 12 11 10 9 8
Reserved XIOEN RIOEN FSXM FSRM CLKXM CLKRM
R/W R/W R/W R/W R/W R/W R/W;
7 6 5 4 3 2 1 0
SCLKME CLKS STAT DX STAT DR STAT FSXP FSRP CLKXP CLKRP
R/W R/W R/W R/W R/W R/W R/W R/W;
LEGEND: R = Read, W = Write, n = value present after reset。 |
|
|
|
|
|