void McBSPObj::McBSP0Init(void)//McBSP从设备SPI硬件配置
{
/*-------------------------------------------------------------
DSP5402之McBSP从设备SPI硬件四种模式配置实例(经过硬件测试)
--------------------------------------------------------------*/
//PCR设置过程(FSM=0,CLKM=0)
McBSP0->SPSA = PCR;
McBSP1->SPSD = (0 << PCR_XIOEN) //发送非通用I/O模式位
| (0 << PCR_RIOEN) //接收非通用I/O模式位
| (0 << PCR_FSXM) //外部发送帧同步脉冲(外部片选)
| (0 << PCR_FSRM) //外部接收帧同步脉冲(外部片选)
| (0 << PCR_CLKXM) //外部发送时钟(外部时钟源)
| (0 << PCR_CLKRM) //外部接收时钟(外部时钟源)
#if SPIMODE == 0
//SPI设置过程00(0--FS高电平有效,0--CLK上升沿收发数据)
| (0 << PCR_FSXP) //发送帧同步脉冲极性(高电平有效)
| (0 << PCR_FSRP) //接收帧同步脉冲极性(高电平有效)
| (0 << PCR_CLKXP) //发送时钟极性(上升沿发送数据)
| (0 << PCR_CLKRP);//接收时钟极性(上升沿接收数据)
#endif
#if SPIMODE == 1
//SPI设置过程01(0--FS高电平有效,1--CLK下降沿收发数据)
| (0 << PCR_FSXP) //发送帧同步脉冲极性(高电平有效)
| (0 << PCR_FSRP) //接收帧同步脉冲极性(高电平有效)
| (1 << PCR_CLKXP) //发送时钟极性(下降沿发送数据)
| (1 << PCR_CLKRP);//接收时钟极性(下降沿接收数据)
#endif
#if SPIMODE == 2
//SPI设置过程10(1--FS低电平有效,0--CLK上升沿收发数据)
| (1 << PCR_FSXP) //发送帧同步脉冲极性(低电平有效)
| (1 << PCR_FSRP) //接收帧同步脉冲极性(低电平有效)
| (0 << PCR_CLKXP) //发送时钟极性(上升沿发送数据)
| (0 << PCR_CLKRP);//接收时钟极性(上升沿接收数据)
#endif
#if SPIMODE == 3
//SPI设置过程11(1--FS低电平有效,1--CLK下降沿收发数据)
| (1 << PCR_FSXP) //发送帧同步脉冲极性(低电平有效)
| (1 << PCR_FSRP) //接收帧同步脉冲极性(低电平有效)
| (1 << PCR_CLKXP) //发送时钟极性(下降沿发送数据)
| (1 << PCR_CLKRP);//接收时钟极性(下降沿接收数据)
#endif
//MCR1设置过程(RMCM=0)
McBSP0->SPSA = MCR1;//
McBSP0->SPSD = (0 << MCR1_RMCM) //允许接收多通道选择(0)
| (0x00 << MCR1_RPBBLK)
| (0x00 << MCR1_RPABLK)
| (0x00 << MCR1_RCBLK);
//MCR2设置过程(XMCM=0)
McBSP0->SPSA = MCR2;//
McBSP0->SPSD = (0x00 << MCR2_XMCM) //允许发送多通道选择(00b)
| (0x00 << MCR2_XPBBLK)
| (0x00 << MCR2_XPABLK)
| (0x00 << MCR2_XCBLK);
//RCERA设置过程
McBSP0->SPSA = RCERA;//
McBSP0->SPSD = 0;
//RCERB设置过程
McBSP0->SPSA = RCERB;//
McBSP0->SPSD = 0;
//XCERA设置过程
McBSP0->SPSA = XCERA;//
McBSP0->SPSD = 0;
//XCERB设置过程
McBSP0->SPSA = XCERB;//
McBSP0->SPSD = 0;
//XCR1设置过程
McBSP0->SPSA = XCR1;//
McBSP0->SPSD = (0x00 << XCR1_XFRLEN1) //每帧1个字(每帧中断的次数1!!!)
// | (0x02 << XCR1_XWDLEN1);//每字16位长(每次中断的字节数2!!!)
| (0x00 << XCR1_XWDLEN1);//每字8位长(每次中断的字节数2!!!)
//XCR2设置过程
McBSP0->SPSA = XCR2;
McBSP0->SPSD = (0 << XCR2_XPHASE) //单相帧(其他设置都为0)
| (0x00 << XCR2_XCOMPAND)//发送数据从最高位(MSB)开始
| (0x00 << XCR2_XDATDLY);//同步后延迟0位数据
//RCR1设置过程
McBSP0->SPSA = RCR1;
McBSP0->SPSD = (0x00 << RCR1_RFRLEN1) //每帧1个字(每帧中断的次数1!!!)
// | (0x02 << RCR1_RWDLEN1);//每字16位长(每次中断的字节数2!!!)
| (0x00 << RCR1_RWDLEN1);//每字8位长(每次中断的字节数2!!!)
//RCR2设置过程
McBSP0->SPSA = RCR2;
McBSP0->SPSD = (0 << RCR2_RPHASE) //单相帧(其他设置都为0)
| (0x00 << RCR2_RCOMPAND)//接收数据从最高位(MSB)开始
| (0x00 << RCR2_RDATDLY);//同步后延迟0位数据
//SRGR1设置过程
McBSP0->SPSA = SRGR1;
McBSP0->SPSD = (0x00 << SRGR1_CLKGDV);//1
//SRGR2设置过程
McBSP0->SPSA = SRGR2;
McBSP0->SPSD = (0 << SRGR2_FSGM)
| (1 << SRGR2_CLKSM)//由CPU时钟产生的采样率时钟1
| (0 << SRGR2_CLKSP)//0
| (1 << SRGR2_GSYNC)//
| (0x0f << SRGR2_FPER);//0x0f
//SPCR1设置过程(CLKSTP=1Xb,RINTM=00b)
McBSP0->SPSA = SPCR1;
McBSP0->SPSD = (0x00 << SPCR1_RINTM) //接收中断模式00(每帧接收1次中?
| (0 << SPCR1_DLB) //禁止回送
| (1 << SPCR1_DXENA) //DX使能
| (0x00 << SPCR1_RJUST) //接收符号不扩展
| (0x02 << SPCR1_CLKSTP);//SPI模式时钟开始于上升沿(无延迟)
//SPCR2设置过程(XINTM=02b)
McBSP0->SPSA = SPCR2;
McBSP0->SPSD = (0x02 << SPCR2_XINTM)//发送中断模式02
| (1 << SPCR2_XEMPTY) //发送移位寄存器空
| (1 << SPCR2_XRDY); //发送准备好
//SPCR1复位过程
McBSP0->SPSA = SPCR1;
McBSP0->SPSD|= (1 << SPCR1_RRST);//接收器复位
//SPCR2复位过程
McBSP0->SPSA = SPCR2;
McBSP0->SPSD|= (1 << SPCR2_XRST)//发送器复位
| (1 << SPCR2_GRST)//采样率发生器复位
| (1 << SPCR2_FRST);//帧同步发生器复位
//清除允许BXINT0中断过程
// SREG->IFR = (1 << IFR_BXINT0);//清除BXINT0中断标志
// SREG->IMR |= (1 << IMR_BXINT0);//允许BXINT0中断
//清除允许BRINT0中断过程
SREG->IFR = (1 << IFR_BRINT0);//清除BRINT0中断标志
SREG->IMR |= (1 << IMR_BRINT0);//允许BRINT0中断
}
void McBSPObj::McBSP1Init(void)//GPIO配置
{
McBSP1->SPSA = SPCR1;
McBSP1->SPSD = 0;
McBSP1->SPSA = SPCR2;
McBSP1->SPSD = 0;
McBSP1->SPSA = PCR;
//设置收发为IO接口,DX输出,DR,CLKS输入
McBSP1->SPSD = (1 << PCR_RIOEN) //通用I/O模式位
//硬件RDDOG喂狗信号(BDX1)管脚输出模式默认I/O设置
| (1 << PCR_XIOEN) //通用I/O模式位
//硬件RD SIA信号(BFSR1)管脚输入模式设置
| (0 << PCR_FSRM) //FSR为输入IO
//硬件FM CE信号(BFSX1)管脚输出模式设置
| (1 << PCR_FSXM) //FSR为输出IO,FLASH的片选信号
//硬件FM CE信号(BFSX1)管脚高电平输出控制
| (1 << PCR_FSXP) //关闭FLASH的片选信号(FSX=1)
| (0 << PCR_CLKRM) //CLKR为输入IO
| (0 << PCR_CLKXM); //CLKX为输入IO,CLKX信号
} |