DM642,用McBSP模拟SPI接口,配置成从模式,SPI_CLK=20kHz,
按照数据手册的说明是要先等到XRDY寄存器变1才能写数据,其发送代码应为
while(!MCBSP_xrdy(hMcbspSlave));
MCBSP_write(hMcbspSlave, data);
while( !MCBSP_rrdy(hMcbspSlave) );
arcvarray[j] = ( MCBSP_read(hMcbspSlave));
但是这样时发出去的数据出错了,然后下面这段代码却可以成功
MCBSP_write(hMcbspSlave, data);
while(!MCBSP_xrdy(hMcbspSlave));
while( !MCBSP_rrdy(hMcbspSlave) );
arcvarray[j] = ( MCBSP_read(hMcbspSlave));
但这个明显不符合数据手册的要求,请求大神帮忙指出问题所在。
以下为McBSP的配置参数:
MCBSP_Config mcbspSlaveCfg = {
MCBSP_SPCR_RMK( //串口控制寄存器
MCBSP_SPCR_FREE_DEFAULT,
MCBSP_SPCR_SOFT_DEFAULT,
MCBSP_SPCR_FRST_DEFAULT,
MCBSP_SPCR_GRST_YES,
MCBSP_SPCR_XINTM_DEFAULT,
MCBSP_SPCR_XSYNCERR_DEFAULT,
MCBSP_SPCR_XRST_DEFAULT,
MCBSP_SPCR_DLB_DEFAULT,
MCBSP_SPCR_RJUST_DEFAULT,
MCBSP_SPCR_CLKSTP_OF(2), /* CLKSTP=11b with CLKXP=1, clock starts with */
MCBSP_SPCR_DXENA_OFF, /* rising edge with delay */
MCBSP_SPCR_RINTM_RRDY,
MCBSP_SPCR_RSYNCERR_DEFAULT,
MCBSP_SPCR_RRST_DEFAULT
),
MCBSP_RCR_RMK(//接收控制
MCBSP_RCR_RPHASE_SINGLE,
MCBSP_RCR_RFRLEN2_DEFAULT,
MCBSP_RCR_RWDLEN2_DEFAULT,
MCBSP_RCR_RCOMPAND_DEFAULT,
MCBSP_RCR_RFIG_NO,
MCBSP_RCR_RDATDLY_0BIT,
MCBSP_RCR_RFRLEN1_DEFAULT,
MCBSP_RCR_RWDLEN1_16BIT, /* modi2 receive element length phase 1 is 32 bits */
MCBSP_RCR_RWDREVRS_DISABLE
),
MCBSP_XCR_RMK(//发送控制
MCBSP_XCR_XPHASE_DEFAULT,
MCBSP_XCR_XFRLEN2_DEFAULT,
MCBSP_XCR_XWDLEN2_DEFAULT,
MCBSP_XCR_XCOMPAND_DEFAULT,
MCBSP_XCR_XFIG_DEFAULT,
MCBSP_XCR_XDATDLY_0BIT, /* 1 bit data delay */
MCBSP_XCR_XFRLEN1_DEFAULT,
MCBSP_XCR_XWDLEN1_16BIT, /*modi3 transmit element phase 1 is 32 bits */
MCBSP_XCR_XWDREVRS_DISABLE
),
MCBSP_SRGR_RMK(//采样率发生
MCBSP_SRGR_GSYNC_FREE,
MCBSP_SRGR_CLKSP_RISING,
MCBSP_SRGR_CLKSM_INTERNAL, /* SRGR clock mode from internal source */
MCBSP_SRGR_FSGM_DXR2XSR,
MCBSP_SRGR_FPER_DEFAULT,
MCBSP_SRGR_FWID_DEFAULT,
MCBSP_SRGR_CLKGDV_OF(0) /* 使用最大速率 */
),
MCBSP_MCR_RMK( //多通道控制寄存器 /* only for 64x */
MCBSP_MCR_XMCME_DEFAULT, /* All fields in MCR set to default values */
MCBSP_MCR_XPBBLK_DEFAULT,
MCBSP_MCR_XPABLK_DEFAULT,
MCBSP_MCR_XMCM_DEFAULT,
MCBSP_MCR_RPBBLK_DEFAULT,
MCBSP_MCR_RMCME_DEFAULT,
MCBSP_MCR_RPABLK_DEFAULT,
MCBSP_MCR_RMCM_DEFAULT
),
//接收通道使能
MCBSP_RCERE0_RMK(0), /* Additional registers only for 64x */
MCBSP_RCERE1_RMK(0),
MCBSP_RCERE2_RMK(0),
MCBSP_RCERE3_RMK(0),
//发送通道使能
MCBSP_XCERE0_RMK(0), /* Additional registers only for 64x */
MCBSP_XCERE1_RMK(0),
MCBSP_XCERE2_RMK(0),
MCBSP_XCERE3_RMK(0),
MCBSP_PCR_RMK(//引脚控制
MCBSP_PCR_XIOEN_SP,
MCBSP_PCR_RIOEN_SP,
MCBSP_PCR_FSXM_EXTERNAL, /* frame sync generation */
MCBSP_PCR_FSRM_EXTERNAL,
MCBSP_PCR_CLKXM_INPUT, /* tans. clock mode from internal SRGR */
MCBSP_PCR_CLKRM_INPUT,
MCBSP_PCR_CLKSSTAT_0,
MCBSP_PCR_DXSTAT_0,
MCBSP_PCR_FSXP_ACTIVELOW, /*片选/帧同步信号低电平有效 */
MCBSP_PCR_FSRP_ACTIVELOW,
MCBSP_PCR_CLKXP_RISING, /* 时钟上升沿数据有效 */
MCBSP_PCR_CLKRP_FALLING
)
};
这样才合适
不是要先等待XRDY寄存器变成1,也就是数据被从DXR寄存器搬移到XSR寄存器,之后才能再写新数据吗?
而且ccs3.3安装文件夹下的例程也是这样的呀
//Wait until the transmitter is ready for a sample, then write to it
while (!MCBSP_xrdy(hMcbsp));
MCBSP_write(hMcbsp,y);
//Wait until the value is received, then read it
while (!MCBSP_rrdy(hMcbsp));
x = MCBSP_read(hMcbsp);
一周热门 更多>