高手帮忙看看,mcbsp配置成SPI主动模式读取串行AD采样数据。谢谢
void InitMcbsp(void)
{
EALLOW;
McbspaRegs.SPCR2.all=0x0000; // Reset FS generator, sample rate generator & transmitter
McbspaRegs.SPCR1.all=0x0000; // Reset Receiver, Right justify word
McbspaRegs.MFFINT.all=0x0; // Disable all interrupts
McbspaRegs.MFFST.all=0x0; // Clear all status bits
McbspaRegs.SPCR1.bit.CLKSTP=2;
McbspaRegs.PCR.bit.CLKXP=0; //发送数据在上升沿
McbspaRegs.PCR.bit.CLKRP=0; //接收数据在下降沿
McbspaRegs.PCR.bit.CLKXM=1; //CLKX设置为输出,SPI工作在主动模式
delay_loop();
McbspaRegs.PCR.bit.SCLKME=0;
McbspaRegs.SRGR2.bit.CLKSM=1; //选择采样速率发生器输入时钟源
McbspaRegs.SRGR1.bit.CLKGDV=0x03;
McbspaRegs.PCR.bit.FSXM=1; //FSX为输出引脚
McbspaRegs.SRGR2.bit.FSGM=0;//采样速率器帧同步信号驱动发送帧同步信号
McbspaRegs.PCR.bit.FSXP=1; //FSX低电平有效
McbspaRegs.XCR2.bit.XDATDLY=1; //发送一位延时
McbspaRegs.RCR2.bit.RDATDLY=1; //接收一位延时
McbspaRegs.XCR2.bit.XPHASE=0; //发送使用单相位帧
McbspaRegs.RCR2.bit.RPHASE=0; //接收使用单相位帧
McbspaRegs.XCR1.bit.XFRLEN1=0; //发送帧长度为一个串行字
McbspaRegs.RCR1.bit.RWDLEN1=0; //接收帧长度为一个串行字
McbspaRegs.XCR1.bit.XWDLEN1=2; //发送字长度为16位
McbspaRegs.RCR1.bit.RWDLEN1=2; //接收字长度为16位
McbspaRegs.SPCR2.bit.GRST=1; //复位采样速率生成器
clkg_delay_loop(); // Wait at least 2 CLKG cycles
McbspaRegs.SPCR2.bit.XRST=1; // Release TX from Reset
McbspaRegs.SPCR1.bit.RRST=1; // Release RX from Reset
clkg_delay_loop(); // Wait at least 2 CLKG cycles
McbspaRegs.SPCR2.bit.FRST=1; // Frame Sync Generator reset
}
void InitAdc(void)
{
InitMcbsp();
while(McbspaRegs.SPCR2.bit.XRDY!=1);
McbspaRegs.DXR1.all=0xA000;
while(McbspaRegs.SPCR1.bit.RRDY!=1);
Adcresult[0]=McbspaRegs.DRR1.all;
while(McbspaRegs.SPCR2.bit.XRDY!=1);
McbspaRegs.DXR1.all=0xC000;;
while(McbspaRegs.SPCR1.bit.RRDY!=1);
Adcresult[0]=McbspaRegs.DRR1.all;
while(McbspaRegs.SPCR2.bit.XRDY!=1);
McbspaRegs.DXR1.all=0x9C18;;
while(McbspaRegs.SPCR1.bit.RRDY!=1);
Adcresult[0]=McbspaRegs.DRR1.all;
}
void delay_loop(void) // Delay function used while initializing the registers
{
long i;
for (i = 0; i<4; i++);
}
void clkg_delay_loop(void)
{
long i;
for (i = 0; i<16; i++); //delay in McBsp init. must be at least 2 SRG cycles
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我想问下你的AD片选信号时用帧同步信号来控制的么
用个模拟的spi容易找到问题的。
一周热门 更多>