以下是McBSP的程序,以实现异步串口,主要是调试出DSP(TMS320C5410)发送数据,
但是用示波器或是串口调试助手都看不到数据,请高人指点一二,多谢!
#include <stdio.h> #include <stdlib.h> #include <csl.h> #include <csl_irq.h> #include <csl_mcbsp.h>
/*----------------------------------------------------------------------------*/ //#include <memory.h> //#include "reg.h" interrupt void myISP(void);//声明所有用到的函数原型 //void taskFunc(void); int x=1,y=0,z=0; #define N 20 Uint16 xmt[N]; /*----------------------------------------------------------------------------*/
static MCBSP_Config ConfigLoopBack16= { MCBSP_SPCR1_RMK( MCBSP_SPCR1_DLB_OFF, /* DLB = 1 */ MCBSP_SPCR1_RJUST_RZF, /* RJUST = 0 */ MCBSP_SPCR1_CLKSTP_NODELAY, /* CLKSTP = 0 */ MCBSP_SPCR1_DXENA_OFF, /* DXENA = 0 */ MCBSP_SPCR1_ABIS_DEFAULT, /* ABIS = 0 */ MCBSP_SPCR1_RINTM_RRDY, /* RINTM = 0 */ MCBSP_SPCR1_RRST_DISABLE /* RRST = 0 */ ), MCBSP_SPCR2_RMK( MCBSP_SPCR2_FREE_YES, /* FREE = 0 */ MCBSP_SPCR2_SOFT_YES, /* SOFT = 0 */ MCBSP_SPCR2_FRST_RESET, /* FRST = 1 */ MCBSP_SPCR2_GRST_RESET, /* GRST = 1 */ MCBSP_SPCR2_XINTM_XRDY, /* XINTM = 0 */ MCBSP_SPCR2_XRST_ENABLE /* XRST = 1 */ ), MCBSP_RCR1_RMK( 0, /* RFRLEN1 = 0 */ 2 /* RWDLEN1 = 5 */ ), MCBSP_RCR2_RMK( MCBSP_RCR2_RPHASE_SINGLE, /* RPHASE = 0 */ MCBSP_RCR2_RFRLEN2_OF(0), /* RFRLEN2 = 0 */ MCBSP_RCR2_RWDLEN2_8BIT, /* RWDLEN2 = 2 */ MCBSP_RCR2_RCOMPAND_MSB, /* RCOMPAND = 0 */ MCBSP_RCR2_RFIG_NO, /* RFIG = 0 */ MCBSP_RCR2_RDATDLY_0BIT /* RDATDxmt = (((Uint16)(i+1)<<8) + (i+1));LY = 0 */ ), MCBSP_XCR1_RMK( MCBSP_XCR1_XFRLEN1_OF(20), /* XFRLEN1 = 0 */ MCBSP_XCR1_XWDLEN1_8BIT /* XWDLEN1 = 5 */ ), MCBSP_XCR2_RMK( MCBSP_XCR2_XPHASE_SINGLE, /* XPHASE = 0 */ MCBSP_XCR2_XFRLEN2_OF(20), /* XFRLEN2 = 0 */ MCBSP_XCR2_XWDLEN2_8BIT, /* XWDLEN2 = 2 */ MCBSP_XCR2_XCOMPAND_MSB, /* XCOMPAND = 0 */ MCBSP_XCR2_XFIG_NO, /* XFIG = 0 */ MCBSP_XCR2_XDATDLY_1BIT /* XDATDLY = 0 */ ), MCBSP_SRGR1_RMK( MCBSP_SRGR1_FWID_OF(1), /* FWID = 1 */ MCBSP_SRGR1_CLKGDV_OF(1) /* CLKGDV = 1 */ ), MCBSP_SRGR2_RMK( MCBSP_SRGR2_GSYNC_FREE, /* FREE = 0 */ MCBSP_SRGR2_CLKSP_RISING, /* CLKSP = 0 */ MCBSP_SRGR2_CLKSM_INTERNAL, /* CLKSM = 1 */ MCBSP_SRGR2_FSGM_DXR2XSR, /* FSGM = 0 */ MCBSP_SRGR2_FPER_OF(15) /*?????*/ /* FPER = 15 */ ), MCBSP_MCR1_DEFAULT, MCBSP_MCR2_DEFAULT, MCBSP_PCR_RMK( MCBSP_PCR_XIOEN_SP, /* XIOEN = 0 */ MCBSP_PCR_RIOEN_SP, /* RIOEN = 0 */ MCBSP_PCR_FSXM_INTERNAL, /* FSXM = 1 */ MCBSP_PCR_FSRM_INTERNAL, /* FSRM = 0 */ MCBSP_PCR_SCLKME_NO, /* SCLKME = 0 */ MCBSP_PCR_CLKXM_OUTPUT, /* CLKXM = 1 */ MCBSP_PCR_CLKRM_INPUT, /* CLKRM = 0 */ MCBSP_PCR_FSXP_ACTIVEHIGH, /* FSXP = 0 */ MCBSP_PCR_FSRP_ACTIVEHIGH, /* FSRP = 0 */ MCBSP_PCR_CLKXP_RISING, /* CLKXP = 0 */ MCBSP_PCR_CLKRP_RISING /* CLKRP = 0 */ ), 0x0000u, /* RCERA */ 0x0000u, /* RCERB */ 0x0000u, /* RCERC */ 0x0000u, /* RCERD */ 0x0000u, /* RCERE */ 0x0000u, /* RCERF */ 0x0000u, /* RCERG */ 0x0000u, /* RCERH */ 0x00FFu, /* XCERA */ 0x00FFu, /* XCERB */ 0x0000u, /* XCERC */ 0x0000u, /* XCERD */ 0x0000u, /* XCERE */ 0x0000u, /* XCERF */ 0x0000u, /* XCERG */ 0x0000u /* XCERH */ };
interrupt void myISP() { MCBSP_Handle mhMcbsp; // int xmt[N]; int i; while (!IRQ_test(IRQ_EVT_INT0));
for(i=0;i<=N-1;i++) { xmt = (((Uint16)(i+1)<<8) + (i+1)); }
mhMcbsp = MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET); MCBSP_config(mhMcbsp, &ConfigLoopBack16); MCBSP_start(mhMcbsp, MCBSP_XMIT_START, MCBSP_SAMPLE_RATE_DELAY_DEFAULT );
while (!MCBSP_xrdy(mhMcbsp)) ;
MCBSP_write16(mhMcbsp,xmt[0]);
MCBSP_start(mhMcbsp, MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, MCBSP_SAMPLE_RATE_DELAY_DEFAULT ); for (i=1; i<=N-1;i++) { while (!MCBSP_xrdy(mhMcbsp)); MCBSP_write16(mhMcbsp,xmt); }
MCBSP_close(mhMcbsp); puts("<DONE>"); z=x+y; x=x+1; }
main() { // MCBSP_Handle mhMcbsp; // int xmt[N], rcv[N];
CSL_init(); IRQ_setVecs (0x6000); IRQ_plug(IRQ_EVT_INT0,&myISP); IRQ_enable(IRQ_EVT_INT0); printf("OK\n");
/*
while (!IRQ_test(IRQ_EVT_INT0));
for(i=0;i<=N-1;i++) { xmt = (((Uint16)(i+1)<<8) + (i+1)); }
mhMcbsp = MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET); MCBSP_config(mhMcbsp, &ConfigLoopBack16); MCBSP_start(mhMcbsp, MCBSP_XMIT_START, MCBSP_SAMPLE_RATE_DELAY_DEFAULT );
while (!MCBSP_xrdy(mhMcbsp)) ;
MCBSP_write16(mhMcbsp,xmt[0]);
MCBSP_start(mhMcbsp, MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, MCBSP_SAMPLE_RATE_DELAY_DEFAULT ); for (i=1; i<=N-1;i++) { while (!MCBSP_xrdy(mhMcbsp)); MCBSP_write16(mhMcbsp,xmt); }
MCBSP_close(mhMcbsp); // printf("%s\n",err?"TEST FAILED":"TEST PASSED"); printf("OK\n");
*/ IRQ_globalEnable(); // taskFunc(); }
//////////////////////
|