完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
本帖最后由 一只耳朵怪 于 2018-5-25 14:42 编辑
现在在调试一个程序,把DM642的MCBSP0接口配置成SPI接口,与带spi接口的存储器进行通讯,发送没有问题,以查询的方式接收数据时SPI_CLK上没有信号,片选也没有信号。请大家帮忙分析下,代码如下: static MCBSP_Config ConfigSPI = [ MCBSP_SPCR_RMK //Serial Port Control Register (SPCR) ( MCBSP_SPCR_FREE_NO, // FREE RUNNING DISABLED //MCBSP_SPCR_FREE_YES, // 1Serial clock free running mode(FREE) MCBSP_SPCR_SOFT_NO, // SOFT DISABLED //MCBSP_SPCR_SOFT_YES, // 1Serial clock emulation mode(SOFT) MCBSP_SPCR_FRST_YES, // 0Frame sync generator reset(FRST) MCBSP_SPCR_GRST_YES, // 0Sample rate generator reset(GRST) MCBSP_SPCR_XINTM_DEFAULT,//MCBSP_SPCR_XINTM_XRDY, // 0;Transmit interrupt mode(XINTM) MCBSP_SPCR_XSYNCERR_NO, // 0Transmit synchronization error MCBSP_SPCR_XRST_YES, // 0Transmitter reset(XRST) MCBSP_SPCR_DLB_OFF, // 0Digital loopback(DLB) mode MCBSP_SPCR_RJUST_RZF, // 0Receive data sign-extension and // justification mode(RJUST) MCBSP_SPCR_CLKSTP_NODELAY,//MCBSP_SPCR_CLKSTP_DELAY,//MCBSP_SPCR_CLKSTP_DISABLE, //0Clock stop(CLKSTP) mode //CLKSTP=11b with CLKXP=0, clock starts with MCBSP_SPCR_DXENA_OFF, // 0DX Enabler(DXENA) -Extra delay for // DX turn-on time. MCBSP_SPCR_RINTM_RRDY, //0Receive interrupt(RINT) mode MCBSP_SPCR_RSYNCERR_NO, //0Receive synchronization error(RSYNCERR) MCBSP_SPCR_RRST_YES //0Receiver reset(RRST) ), MCBSP_RCR_RMK // Receive Control Register (RCR) ( MCBSP_RCR_RPHASE_SINGLE, //0 Receive phases //MCBSP_RCR_RFRLEN2_OF(0), // Receive frame length // in phase 2(RFRLEN2) MCBSP_RCR_RFRLEN2_DEFAULT, //0 MCBSP_RCR_RWDLEN2_8BIT, //0 Receive element length // in phase 2(RWDLEN2) MCBSP_RCR_RCOMPAND_MSB, //0 Receive companding mode (RCOMPAND) // MCBSP_RCR_RFIG_NO, //1 Receive frame ignore(RFIG) MCBSP_RCR_RFIG_YES, //0 MCBSP_RCR_RDATDLY_1BIT, //0 Receive data delay(RDATDLY) // MCBSP_RCR_RDATDLY_DEFAULT,//MCBSP_RCR_RDATDLY_0BIT, //1 MCBSP_RCR_RFRLEN1_DEFAULT,//MCBSP_RCR_RFRLEN1_OF(0), // Receive frame length // in phase 1(RFRLEN1) // MCBSP_RCR_RFRLEN1_DEFAULT, //MCBSP_RCR_RWDLEN1_32BIT, // Receive element length // in phase 1(RWDLEN1) MCBSP_RCR_RWDLEN1_8BIT, MCBSP_RCR_RWDREVRS_DISABLE // Receive 8-bit bit reversal // feature.(RWDREVRS) ), MCBSP_XCR_RMK //Transmit Control Register (XCR) ( MCBSP_XCR_XPHASE_SINGLE, // 0Transmit phases单相帧 // in phase 2(XFRLEN2) MCBSP_XCR_XFRLEN2_DEFAULT, //0 MCBSP_XCR_XWDLEN2_8BIT, //0Transmit element length // in phase 2 MCBSP_XCR_XCOMPAND_MSB, //0 Transmit companding mode(XCOMPAND) // MCBSP_XCR_XFIG_YES, // Transmit frame ignore(XFIG) MCBSP_XCR_XFIG_YES, MCBSP_XCR_XDATDLY_1BIT, // Transmit data delay(XDATDLY) MCBSP_XCR_XFRLEN1_DEFAULT, //0 帧长度为一个数据包 MCBSP_XCR_XWDLEN1_8BIT, // Transmit element length in phase 1(XWDLEN1) MCBSP_XCR_XWDREVRS_DISABLE // Transmit 8-bit bit reversal feature ), MCBSP_SRGR_RMK //serial port sample rate generator register(SRGR) ( MCBSP_SRGR_GSYNC_FREE, // 0Sample rate generator clock // synchronization(GSYNC). MCBSP_SRGR_CLKSP_RISING, //0 CLKS polarity clock edge select(CLKSP) MCBSP_SRGR_CLKSM_INTERNAL, //1 MCBSP sample rate generator clock // mode(CLKSM) MCBSP_SRGR_FSGM_DEFAULT,//MCBSP_SRGR_FSGM_DXR2XSR, //0 Sample rate generator transmit frame // synchronization // MCBSP_SRGR_FPER_OF(63), // Frame period(FPER) MCBSP_SRGR_FPER_DEFAULT, //0 // MCBSP_SRGR_FWID_OF(31), // Frame width(FWID) MCBSP_SRGR_FWID_DEFAULT, //0 MCBSP_SRGR_CLKGDV_OF(149) // SPI_clk 3MHz// Sample rate generator clock,DM642为4分频 // divider(CLKGDV) ), MCBSP_MCR_DEFAULT, // Using default value of MCR register MCBSP_RCERE0_DEFAULT, // Using default value of RCERE registers MCBSP_RCERE1_DEFAULT, MCBSP_RCERE2_DEFAULT, MCBSP_RCERE3_DEFAULT, MCBSP_XCERE0_DEFAULT, // Using default value of XCERE registers MCBSP_XCERE1_DEFAULT, MCBSP_XCERE2_DEFAULT, MCBSP_XCERE3_DEFAULT, MCBSP_PCR_RMK //serial port pin control register(PCR) ( MCBSP_PCR_XIOEN_SP, // Transmitter in general-purpose I/O mode MCBSP_PCR_RIOEN_SP, // Receiver in general-purpose I/O mode MCBSP_PCR_FSXM_INTERNAL, //1 Transmit frame synchronization mode MCBSP_PCR_FSRM_EXTERNAL, // Receive frame synchronization mode // MCBSP_PCR_FSRM_INTERNAL, //1 MCBSP_PCR_CLKXM_OUTPUT, //1Transmitter clock mode (CLKXM) MCBSP_PCR_CLKRM_OUTPUT, //1 MCBSP_PCR_CLKSSTAT_0, //0 CLKS pin status(CLKSSTAT) MCBSP_PCR_DXSTAT_0, //0 DX pin status(DXSTAT) MCBSP_PCR_FSXP_ACTIVELOW, //1 //MCBSP_PCR_FSRP_ACTIVEHIGH, MCBSP_PCR_FSRP_ACTIVELOW, //0 Receive frame synchronization polarity(FSRP) MCBSP_PCR_CLKXP_RISING, //0 Transmit clock polarity(CLKXP) MCBSP_PCR_CLKRP_FALLING //0 Receive clock polarity(CLKRP) ) ]; void init_mcbsp_spi() [ unsigned char i; //Open up serial port 1 hMcbsp = MCBSP_open(MCBSP_DEV0, MCBSP_OPEN_RESET); if(hMcbsp == INV) [ exit(1); ] //Configure McBSP for digital loopback, 8bit mode // and setup the sample rate generator to allow self clocking MCBSP_config(hMcbsp, &ConfigSPI); for(i = 0;i < 10;i++); //Enable McBSP in steps MCBSP_start(hMcbsp, MCBSP_RCV_START | //MCBSP_SPCR_XRST_NO | MCBSP_SPCR_RRST_NO | MCBSP_SPCR_GRST_NO | MCBSP_XMIT_START | MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, MCBSP_SRGR_DEFAULT_DELAY); delay(10); for(i = 0;i < 10;i++); ] Uint8 spi_rec_byte(void) [ Uint8 x; Uint32 y; unsigned int i; while (!MCBSP_rrdy(hMcbsp))[]; x = (unsigned char )DRR0; /* y =MCBSP_read(hMcbsp); for(i = 100;i > 0;i--); x=(Uint8)y; */ return(x); /* 读取收到的字节 read the byte received */ ] |
|
相关推荐
5个回答
|
|
在接收之前, 试试先往DXR寄存器写一个dummy数来产生FSX信号. 具体见下面文档第60页上的说明"9.1 McBSP Operation as the SPI Master".
http://www.ti.com/lit/ug/spru580g/spru580g.pdf |
|
|
|
vuywsdfwf 发表于 2018-5-25 04:43 感谢回复。我这样试过了,可以的。谢谢。 还有个问题:上电后,通过spi读取数据时,前2次读的都不正确,以后再读是正确的,这是什么原因?我用示波器抓了一下,显示的数据是没有问题的。 |
|
|
|
yukichen 发表于 2018-5-25 04:49 用EDMA模式了么? |
|
|
|
|
|
|
|
不需要预读取, 除了数据线, 片选, clock信号都正确吗? |
|
|
|
只有小组成员才能发言,加入小组>>
336 浏览 1 评论
529 浏览 2 评论
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
774 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
651 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1130 浏览 1 评论
AT32F407在USART2 DMA发送数据时,接包接到了要发送的数据,程序还是处于等待传输完成的标识判断中,为什么?
58浏览 29评论
147浏览 23评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
252浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
202浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
59浏览 13评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 13:51 , Processed in 0.836050 second(s), Total 58, Slave 51 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号