TMS320VC5509的MCBSP配置成SPI模式通信

1. 首先是把MCBSP的配置

TMS320VC5509的MCBSP配置成SPI模式通信

其次是时钟停止模式的配置,关闭大同小异

TMS320VC5509的MCBSP配置成SPI模式通信

SPI有4中模式,怎么根据上面的寄存器选择哪种模式?下面展示了其中两种,CLKXP=1的时候有另外两种,暂时不整出来了

TMS320VC5509的MCBSP配置成SPI模式通信

2. 代码总结如下,需要注意的是不同版本的CSL库,MCBSP_PCR_RMK有点区别,一定要注意哈

#include <csl.h>
#include <csl_i2c.h>
#include <stdio.h>
#include <csl_pll.h>
#include <csl_mcbsp.h>
#include <csl_gpio.h> //共阳极数码管值
char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
/*锁相环的设置*/
PLL_Config myConfig = {
, //IAI: the PLL locks using the same process that was underway
//before the idle mode was entered
, //IOB: If the PLL indicates a break in the phase lock,
//it switches to its bypass mode and restarts the PLL phase-locking
//sequence
, //PLL multiply value; multiply 24 times
//Divide by 2 PLL divide value; it can be either PLL divide value
//(when PLL is enabled), or Bypass-mode divide value
//(PLL in bypass mode, if PLL multiply value is set to 1)
}; MCBSP_Config Mcbsptest; /*McBSP set,we use mcbsp0 to send and recieve the data between DSP and 74HC595*/
MCBSP_Config Mcbsp0Config = {
MCBSP_SPCR1_RMK(
MCBSP_SPCR1_DLB_OFF, /* DLB = 0,禁止自闭环方式 */
MCBSP_SPCR1_RJUST_RZF, /* RJUST = 2 */
//MCBSP_SPCR1_CLKSTP_DISABLE, /* CLKSTP = 0 */
MCBSP_SPCR1_CLKSTP_NODELAY,
MCBSP_SPCR1_DXENA_NA, /* DXENA = 1 */
, /* ABIS = 0 */
MCBSP_SPCR1_RINTM_RRDY, /* RINTM = 0 */
, /* RSYNCER = 0 */
MCBSP_SPCR1_RRST_DISABLE /* RRST = 0 */
),
MCBSP_SPCR2_RMK(
MCBSP_SPCR2_FREE_NO, /* FREE = 0 */
MCBSP_SPCR2_SOFT_NO, /* SOFT = 0 */
MCBSP_SPCR2_FRST_RESET, //帧同步关闭
//MCBSP_SPCR2_FRST_FSG, /* FRST = 0 */
MCBSP_SPCR2_GRST_RESET, /* GRST = 0 */
MCBSP_SPCR2_XINTM_XRDY, /* XINTM = 0 */
, /* XSYNCER = N/A */
MCBSP_SPCR2_XRST_DISABLE /* XRST = 0 */
),
/*单数据相,接受数据长度为16位,每相2个数据*/
MCBSP_RCR1_RMK(
MCBSP_RCR1_RFRLEN1_OF(), /* RFRLEN1 = 1 */
MCBSP_RCR1_RWDLEN1_16BIT /* RWDLEN1 = 2 */
),
MCBSP_RCR2_RMK(
MCBSP_RCR2_RPHASE_SINGLE, /* RPHASE = 0 */
MCBSP_RCR2_RFRLEN2_OF(), /* RFRLEN2 = 0 */
MCBSP_RCR2_RWDLEN2_8BIT, /* RWDLEN2 = 0 */
MCBSP_RCR2_RCOMPAND_MSB, /* RCOMPAND = 0 */
MCBSP_RCR2_RFIG_YES, /* RFIG = 0 */
MCBSP_RCR2_RDATDLY_1BIT /* RDATDLY = 1 */
),
MCBSP_XCR1_RMK(
MCBSP_XCR1_XFRLEN1_OF(), /* XFRLEN1 = 1 */
MCBSP_XCR1_XWDLEN1_16BIT /* XWDLEN1 = 2 */ ),
MCBSP_XCR2_RMK(
MCBSP_XCR2_XPHASE_SINGLE, /* XPHASE = 0 */
MCBSP_XCR2_XFRLEN2_OF(), /* XFRLEN2 = 0 */
MCBSP_XCR2_XWDLEN2_8BIT, /* XWDLEN2 = 0 */
MCBSP_XCR2_XCOMPAND_MSB, /* XCOMPAND = 0 */
MCBSP_XCR2_XFIG_YES, /* XFIG = 0 */
MCBSP_XCR2_XDATDLY_1BIT /* XDATDLY = 1 */
),
MCBSP_SRGR1_RMK(
MCBSP_SRGR1_FWID_OF(), /* 停止模式无效**重要FWID = 0 帧同步信号的脉宽周期数*/
MCBSP_SRGR1_CLKGDV_OF() /* 停止模式无效**重要CLKGDV =9 CLKG时钟频率*/
),
MCBSP_SRGR2_RMK(
,//MCBSP_SRGR2_GSYNC_FREE, /* FREE = 0 内部时钟帧同步 */
MCBSP_SRGR2_CLKSP_RISING, /* 重要CLKSP = 0 CLKS 引脚极性*/
MCBSP_SRGR2_CLKSM_INTERNAL, /* 重要CLKSM = 1 cpu时钟*/
MCBSP_SRGR2_FSGM_DXR2XSR, /* FSGM = 0 发送帧同步模式,如果FXSM=1,当DXR->XSR时,McBSP产生帧同步信号*/
MCBSP_SRGR2_FPER_OF() /*重要 FPER = 0 FSG信号帧同步时钟周期数,应该是7*/
),
MCBSP_MCR1_DEFAULT,
MCBSP_MCR2_DEFAULT,
MCBSP_PCR_RMK(
MCBSP_PCR_IDLEEN_RESET, /* IDLEEN = 0 */
MCBSP_PCR_XIOEN_SP, /* XIOEN = 0 */
MCBSP_PCR_RIOEN_SP, /* RIOEN = 0 */
MCBSP_PCR_FSXM_INTERNAL, /* FSXM = 0 */
MCBSP_PCR_FSXM_INTERNAL, /* FSRM = 0 */
/* DXSTAT = N/A */
MCBSP_PCR_CLKXM_OUTPUT, /* CLKXM = 0 */
MCBSP_PCR_CLKRM_INPUT, /* CLKRM = 0 */
MCBSP_PCR_SCLKME_NO, /* SCLKME = 0 */
,
MCBSP_PCR_FSXP_ACTIVELOW, /* FSXP = 0 */
MCBSP_PCR_FSXP_ACTIVELOW, /* FSRP = 1 */
MCBSP_PCR_CLKXP_RISING, /* CLKXP = 1 */
MCBSP_PCR_CLKRP_RISING /* CLKRP = 1 */
),
MCBSP_RCERA_DEFAULT,
MCBSP_RCERB_DEFAULT,
MCBSP_RCERC_DEFAULT,
MCBSP_RCERD_DEFAULT,
MCBSP_RCERE_DEFAULT,
MCBSP_RCERF_DEFAULT,
MCBSP_RCERG_DEFAULT,
MCBSP_RCERH_DEFAULT,
MCBSP_XCERA_DEFAULT,
MCBSP_XCERB_DEFAULT,
MCBSP_XCERC_DEFAULT,
MCBSP_XCERD_DEFAULT,
MCBSP_XCERE_DEFAULT,
MCBSP_XCERF_DEFAULT,
MCBSP_XCERG_DEFAULT,
MCBSP_XCERH_DEFAULT
}; /*定义McBSP的句柄*/
MCBSP_Handle hMcbsp; Uint16 i2c_status;
Uint16 i,temp; void delay(Uint32 k)
{
while(k--);
} void main(void)
{
Uint16 shumaguan_value = ;
/* Initialize CSL library - This is REQUIRED !!! */
/*初始化CSL库*/
CSL_init(); /*设置系统的运行速度为140MHz*/
PLL_config(&myConfig);
/*确定方向为输出*/
GPIO_RSET(IODIR,0xFF);
GPIO_RSET(IODATA,0xFC); /*初始化McBSP0*/ hMcbsp = MCBSP_open(MCBSP_PORT1,MCBSP_OPEN_RESET);
/*设置McBSP0*/
MCBSP_config(hMcbsp,&Mcbsp0Config); /*启动McBSP0*/
// MCBSP_start(hMcbsp,
// MCBSP_RCV_START | MCBSP_XMIT_START,
// 0);
MCBSP_start(hMcbsp,
MCBSP_SRGR_START | MCBSP_XMIT_START | MCBSP_RCV_START,
); //MCBSP_getConfig(hMcbsp,&Mcbsptest);
delay(); /*回放音频*/
while(TRUE)
{
for(i=;i<;i++)
{ shumaguan_value = table[i] + (table[i] << );
while(!MCBSP_xrdy(hMcbsp)){};
MCBSP_write16(hMcbsp,0x0055);
delay();
// while(!MCBSP_xrdy(hMcbsp)){};
// MCBSP_write16(hMcbsp,shumaguan_value);
delay();
GPIO_RSET(IODATA,0xFE);
delay();
GPIO_RSET(IODATA,0xFC); //使能74HC595片选
delay();
}
}
}

3. 通信波形如下,徐国想改变SPI的频率,修改MCBSP_SRGR1_CLKGDV_OF(11)

TMS320VC5509的MCBSP配置成SPI模式通信

上一篇:FPGA作为从机与STM32进行SPI协议通信---Verilog实现


下一篇:JS for循环 闭包