5509A 主机模式下以SPI方式 驱动 AD7903,
连线如下
CLKX0 — SCK
DR0 — SDO
FSX0 — CNV
配置如下(注释不一定对)
MCBSP_SPCR1_RMK(
MCBSP_SPCR1_DLB_OFF, /* DLB = 0,禁止自闭环方式 */
MCBSP_SPCR1_RJUST_LZF, /* RJUST = 2 */
MCBSP_SPCR1_CLKSTP_DELAY, /* CLKSTP = 0 */
MCBSP_SPCR1_DXENA_ON, /* DXENA = 1 */
0, /* ABIS = 0 */
MCBSP_SPCR1_RINTM_RRDY, /* RINTM = 0 */
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_FSG, /* FRST = 0 */
MCBSP_SPCR2_GRST_CLKG, /* GRST = 0 */
MCBSP_SPCR2_XINTM_XRDY, /* XINTM = 0 */
0, /* XSYNCER = N/A */
MCBSP_SPCR2_XRST_DISABLE /* XRST = 0 */
),
MCBSP_RCR1_RMK(
MCBSP_RCR1_RFRLEN1_OF(1), /* RFRLEN1 = 1 */(此次改为0)
MCBSP_RCR1_RWDLEN1_16BIT /* RWDLEN1 = 2 */(此次改为0)
),
MCBSP_RCR2_RMK(
MCBSP_RCR2_RPHASE_SINGLE, /* RPHASE = 0 */
MCBSP_RCR2_RFRLEN2_OF(0), /* 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(1), /* XFRLEN1 = 1 */
MCBSP_XCR1_XWDLEN1_16BIT /* XWDLEN1 = 2 */
),
MCBSP_XCR2_RMK(
MCBSP_XCR2_XPHASE_SINGLE, /* XPHASE = 0 */
MCBSP_XCR2_XFRLEN2_OF(0), /* 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(
20,
10
),
MCBSP_SRGR2_RMK(
MCBSP_SRGR2_GSYNC_FREE,
MCBSP_SRGR2_CLKSP_RISING,
MCBSP_SRGR2_CLKSM_INTERNAL,
MCBSP_SRGR2_FSGM_DXR2XSR,
MCBSP_SRGR2_FPER_OF(50)
),
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_FSRM_INTERNAL, /* FSRM = 0 */
MCBSP_PCR_CLKXM_OUTPUT, /* CLKXM = 0 */
MCBSP_PCR_CLKRM_OUTPUT, /* CLKRM = 0 */
MCBSP_PCR_SCLKME_NO, /* SCLKME = 0 */
MCBSP_PCR_DXSTAT_0 ,
MCBSP_PCR_FSXP_ACTIVELOW, /* FSXP = 0 */
MCBSP_PCR_FSRP_ACTIVELOW, /* FSRP = 0 */
MCBSP_PCR_CLKXP_RISING, /* CLKXP = 1 */
MCBSP_PCR_CLKRP_RISING /* CLKRP = 1 */
)
初始化部分代码如下
/*初始化McBSP0*/
hMcbsp = MCBSP_open(MCBSP_PORT0,MCBSP_OPEN_RESET);
/*设置McBSP0*/
MCBSP_config(hMcbsp,&Mcbsp1Config);
/*启动McBSP0*/
MCBSP_start(hMcbsp,
MCBSP_XMIT_START|MCBSP_RCV_START|MCBSP_SRGR_START|MCBSP_SRGR_FRAMESYNC,
0x20);
接收部分代码如下,查询模式
while(TRUE)
{
adc_vol = MCBSP_read16(hMcbsp);
if(MCBSP_rrdy(hMcbsp))
{
adc_vol = MCBSP_read16(hMcbsp);//代码卡死在这
printf("adc_vol= 0x%04X\n",adc_vol);
Delay(200);
}
}
求教大神
AD7903时序图如下
Shine:
请问vc5509A SPI端的时序如何?有clock和data么?
tuo qian:
回复 Shine:
示波器看了,好像是没有
Shine:
回复 tuo qian:
在MCBSP_config(hMcbsp,&Mcbsp1Config);之前往DXR寄存器里随便写一个数(dummy write)来产生SPI 主时钟。
tuo qian:
回复 Shine:
大神所言极是,确实是这个原因,需要执行写操作,提供时钟。
不过我是在循环中,读之前添加的。
另外配置中需要改动一下,收发字长设置应该为0(一字),否则会引起字节错位。
Shine:
回复 tuo qian:
1. 在读之前添就可以了。
2.这个是clock stop mode要求的,具体看下面的表Table 6−1. Bits Used to Enable and Configure the Clock Stop Modehttp://www.ti.com/lit/ug/spru592e/spru592e.pdf