/*
* Copyright (C) 2003 Texas Instruments Incorporated
* All Rights Reserved
*/
/*
*---------main_mcbsp1.c---------
* In this example, the MCBSP is configured in digital loopback
* mode, with 32 bit data transfer, in multi-frame mode, using
* sample rate generator to sync frames
*/
#include <stdio.h>
#include <csl.h>
#include <csl_mcbsp.h>
#include <csl_pll.h>
//---------Global constants---------
#define N 20
//---------Global data definition---------
/* Create a MCBSP configuration structure */
MCBSP_Config ConfigLoopBack32= {
MCBSP_SPCR1_RMK(
MCBSP_SPCR1_RRST_ENABLE,
MCBSP_SPCR1_RRDY_YES,
MCBSP_SPCR1_RFULL_NO,
MCBSP_SPCR1_RSYNCERR_NO,
MCBSP_SPCR1_RINTM_RRDY,
MCBSP_SPCR1_ABIS_DISABLE,
MCBSP_SPCR1_DXENA_NA,
MCBSP_SPCR1_CLKSTP_DISABLE,
MCBSP_SPCR1_RJUST_RZF,
MCBSP_SPCR1_DLB_ON
),
MCBSP_SPCR2_RMK(
MCBSP_SPCR2_XRST_ENABLE,
MCBSP_SPCR2_XRDY_YES,
MCBSP_SPCR2_XEMPTY_NO,
MCBSP_SPCR2_XSYNCERR_NO,
MCBSP_SPCR2_XINTM_XRDY,
MCBSP_SPCR2_GRST_CLKG,
MCBSP_SPCR2_FRST_FSG,
MCBSP_SPCR2_SOFT_NO,
MCBSP_SPCR2_FREE_NO
),
MCBSP_RCR1_RMK(
MCBSP_RCR1_RWDLEN1_16BIT,
MCBSP_RCR1_RFRLEN1_OF(0)
),
MCBSP_RCR2_RMK(
MCBSP_RCR2_RDATDLY_2BIT,
MCBSP_RCR2_RFIG_YES,
MCBSP_RCR2_RCOMPAND_MSB,
MCBSP_RCR2_RWDLEN2_8BIT,
MCBSP_RCR2_RFRLEN2_OF(0),
MCBSP_RCR2_RPHASE_SINGLE
),
MCBSP_XCR1_RMK(
MCBSP_XCR1_XWDLEN1_16BIT,
MCBSP_XCR1_XFRLEN1_OF(0)
),
MCBSP_XCR2_RMK(
MCBSP_XCR2_XDATDLY_2B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ers for transfer */
Uint16 xmt[N], rcv[N];
//---------Function prototypes---------
void taskFunc(void);
//---------main routine---------
void main() {
Uint16 i;
/* Initialize CSL library, this step is required */
CSL_init();
PLL_setFreq(1, 0xF, 0, 1, 3, 3, 0);
/* Initilize data buffers. xmt will be 32 bit value */
/* with element number in lower 16 bits and 2 * element */
/* in upper 16 bits. i.e. 0x00020001, 0x00040002, etc. */
for(i=0;i<=N-1;i++) {
xmt[i] = i;
rcv[i] = 0;
}
/* Call example function to perform task */
taskFunc();
}
void taskFunc(void) {
MCBSP_Handle mhMcbsp;
Uint16 i;
Uint16 err = 0;
/* Open MCBSP Port 0, this will return a MCBSP handle that will */
/* be used in calls to other CSl functions. */
mhMcbsp = MCBSP_open(MCBSP_PORT0, MCBSP_OPEN_RESET);
/* Write configuration structure values to MCBSP control */
/* registers */
MCBSP_config(mhMcbsp, &ConfigLoopBack32);
/* Start Sample Rate Generator and Frame Sync */
MCBSP_start(mhMcbsp,
MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC,
0x300
);
/* Enable MCBSP transmit and receive */
MCBSP_start(mhMcbsp,
MCBSP_RCV_START | MCBSP_XMIT_START,
0
);
/* Begin data transfer loop. We will loop thru to transmit */
/* and receive the data. */
for (i=0; i<=N-1;i++) {
/* Wait for XRDY signal before writing data to DXR */
while (!MCBSP_xrdy(mhMcbsp));
/* Write 32 bit data value to DXR */
MCBSP_write16(mhMcbsp,xmt[i]);
/* Wait for RRDY signal to read data from DRR */
while (!MCBSP_rrdy(mhMcbsp));
/* Read 32 bit value from DRR */
rcv[i] = MCBSP_read16(mhMcbsp);
}
/* Check data to make sure transfer was successful */
for(i=0; i<= N-1;i++) {
if (xmt[i] != rcv[i]) {
++err;
break;
}
}
/* We are done with MCBSP, so close it */
MCBSP_close(mhMcbsp);
printf("%s\n",err?"TEST FAILED\n":"TEST PASSED\n");
}
在运行程序时,程序指针一直停在 while (!MCBSP_rrdy(mhMcbsp));请问,为什么接收不到数据呢?谢谢! |