赞
踩
将28335上的SPIA模块用来与AD2S1210芯片通信了,还需要另外一个SPI
这时候想到了
然后我就去TI官网找到了McBSP的参考指南
下面给出McBSP配置为SPI的具体步骤:
- GPIO初始化即 将McBSP0对应的GPIO复用为McBSP0
- void Mcbsp_SPI_Gpio(void)
- {
- //mcbspb 做spi
- EALLOW;
-
- GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; // Enable pull-up on GPIO24 (SPISIMO)
- GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0; // Enable pull-up on GPIO25 (SPISOMI)
- GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0; // Enable pull-up on GPIO26 (SPICLK)
-
- GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 3; // Asynch input GPIO24 (SPISIMO)
- GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 3; // Asynch input GPIO25 (SPISOMI)
- GpioCtrlRegs.GPAQSEL2.bit.GPIO26 = 3; // Asynch input GPIO26 (SPICLK)
- GpioCtrlRegs.GPAQSEL2.bit.GPIO27 = 3; // Asynch input GPIO27 (SPISTE)
- //下面的值是3
- GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 3; // Configure GPIO24 as SPISIMO
- GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 3; // Configure GPIO25 as SPISOMI
- GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 3; // Configure GPIO26 as SPICLK
-
-
- //Configure GPIO27 as SPISTEA
- GpioCtrlRegs.GPAPUD.bit.GPIO27 = 0;// Enable pullup
- GpioDataRegs.GPASET.bit.GPIO27 = 1; // Load output latch
- GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 0; //
- GpioCtrlRegs.GPADIR.bit.GPIO27 = 1; // GPIO27 = output
-
-
-
- EDIS;
-
- }
所以GPIO24-27 复用为 McBSP-B
2.McBSP模块相关寄存器初始化
//以下设置适用于数据回送模式,也即自发自收 void mcbsp_init() { /*---------------------------------------- 1.使帧同步逻辑、采样率发生器、接收器和发送器处于复位状态,即FRST=GRST=XRST=RRST=0 ----------------------------------------*/ McbspbRegs.SPCR2.bit.FRST=0; McbspbRegs.SPCR2.bit.GRST=0; McbspbRegs.SPCR2.bit.XRST=0; McbspbRegs.SPCR1.bit.RRST=0; /*---------------------------------------- 2. 控制寄存器配置 a.串行端口控制寄存器SPCR1&SPCR2 b.接收控制寄存器RCR1&RCR2 c.发送控制寄存器XCR1&XCR2 d.采样率发生寄存器SRGR1&SRGR2:采样率发生寄存器用于产生时钟信号CLKG和帧同步信号FSG 1).SRGR2.bit.CLKSM+PCR.bit.SCLKME共同确定输入时钟源,本次为01内部输入时钟LSPCLK 2). f clkg=f 输入时钟/(SRGR1.bit.CLKGDV+1) FSG周期:每(SRGR2.bit.FPER+1 )个CLKG周期 输出一个FSG脉冲 ----------------------------------------*/ McbspbRegs.SPCR2.all=0x0000; McbspbRegs.SPCR1.all=0x9000; //DLB=1,表示数字回环测试 10启用时钟停止模式兼容SPI McbspbRegs.RCR2.all=0x0001; McbspbRegs.RCR1.all=0x0040;//设置接收数据位数为16位 McbspbRegs.XCR2.all=0x0001; McbspbRegs.XCR1.all=0x0040; //收发都是单向帧,每帧1个字,16位字长,不压扩,1位数据延迟 McbspbRegs.SRGR2.all=0x3140;//0011 0001 0100 0000 McbspbRegs.SRGR1.all=0x0003;//0000 0000 0000 0011 CLKG = LSPCLK / (3+1) = 9.375Mhz McbspbRegs.MCR2.all=0x0; McbspbRegs.MCR1.all=0x0; McbspbRegs.PCR.all=0x0A00;//由采样率发生器提供发送时钟和发送帧同步,照样上面。另外后4位对极性进行了配置 //SPI模式下 XPHASE=RPHASE=XFRLEN1=RFRLEN1=0 XWDLEN1=RWDLEN1 // McbspbRegs /*----------------------------------------- 添注:采用中断时,SPCR1.bit.RINTM或者SPCR2.bit.XINTM+MFFINT.bit.RINT(XINT)要设置好,进入中断后读DRR或写DXR -----------------------------------------*/ McbspbRegs.MFFINT.bit.XINT = 1; McbspbRegs.MFFINT.bit.RINT = 1; /*---------------------------------------- 3. 等待2个时钟周期及以上,保证内部的同步 a.设置GRST=1,采样率发生器工作 等待2个时钟周期及以上,保证内部的同步 b.设置RRST=XRST=1,允许发送和接收数据 c.若使用内部帧同步逻辑,则需将FRST=1 ----------------------------------------*/ delay_us(1); //省略delay_loop(); // Wait at least 2 SRG clock cycles McbspbRegs.SPCR2.bit.GRST=1; //省略delay_loop(); // Wait at least 2 SRG clock cycles McbspbRegs.SPCR2.bit.XRST=1; McbspbRegs.SPCR1.bit.RRST=1; McbspbRegs.SPCR2.bit.FRST=1; }3.编写McBSP收发函数
McBSP采用双缓存发送和三缓存接收数据寄存器,以支持连续传送
SPI收发程序如下:
Uint16 Mcbsp_SPI_Byte(Uint16 data) { // 等待发送寄存器为空 while(McbspbRegs.SPCR2.bit.XRDY != 1); // 向发送寄存器写入数据 McbspbRegs.DXR1.all = data; // 等待接收就绪 while(McbspbRegs.SPCR1.bit.RRDY != 1 ); return McbspbRegs.DRR1.all; }
最后仿真测试:
测试结果正确
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。