This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MCBSP as uart transmission problem

sir, i am working in tms320c6211 dsp. I wrote the code for mcbsp as uart as per the ti data sheet spra633c. Receive is working properly, but transmission is not working. here i am attaching my code. can you please help me?

     /* Chip definition - Please change this accordingly */

    #define CHIP_6211 1
    
    /* Include files */

    #include <csl.h>
    #include <csl_mcbsp.h>
    #include <csl_edma.h>
    #include <csl_irq.h>
    #include <stdio.h>
    #include "LED.h"
    
    /* Create buffers and aligning them on an L2 cache line boundary. */

    #pragma DATA_SECTION(xmitbuf,"xmit_buf");

    unsigned short xmitbuf[0x0400];

    #pragma DATA_SECTION(recvbuf,"recv_buf");

    unsigned short recvbuf[0x0400];
    
    /* Definitions */

    #define BUFFER_SIZE 3 /* total number of UART data words*/
    #define TRUE 1
    #define FALSE 0
    
    /* Declare CSL objects */

    MCBSP_Handle hMcbsp1; /* handle for McBSP1 */
    
    #if (EDMA_SUPPORT)
    EDMA_Handle hEdma14; /* handle for EDMA 14 */
    EDMA_Handle hEdma15; /* handle for EDMA 15 */
    #endif
    
    /* Global Variables */

    volatile int receive_done = FALSE;
    volatile int transmit_done = TRUE;
    char xmit_msg[] = "RAKESH";
    char recv_msg[BUFFER_SIZE],temp=0;    

    
    /* Include the vector table to call the IRQ ISRs hookup */

    extern far void vectors();
    
    /* Prototypes */

    void ConfigMcBSP(void);
    void ConfigEDMA(void);
    void ProcessTransmitData(void);
    void ProcessReceiveData(void);
    short VoteLogic(unsigned short);
    int CheckTestCase(void);
    interrupt void c_int08(void);
    
/*******************************************************************/
/* void main(void) */
/*******************************************************************/

void main(void)
{
    int waittime = 0;
    int works = FALSE;

    /* initialize the CSL library */

    CSL_init();

    /* enable NMI and GI */

    IRQ_nmiEnable();
    IRQ_globalEnable();

    /* point to the IRQ vector table */

    IRQ_setVecs(vectors);

    #if (EDMA_SUPPORT)

    /* disable and clear the event interrupt */

    IRQ_reset(IRQ_EVT_EDMAINT);

    /* clear Parameter RAM of EDMA */

    EDMA_clearPram(0x00000000);

    #endif

    /* process transmit data */

    printf("Processing Transmit string...\n");
    ProcessTransmitData();
    printf("String transmitted: %s \n", xmit_msg);

    #if (EDMA_SUPPORT)

    /* Open the EDMA channels - EDMA 14 for transmit, */
    /* EDMA 15 for receive */

    hEdma14 = EDMA_open(EDMA_CHA_XEVT1, EDMA_OPEN_RESET);
    hEdma15 = EDMA_open(EDMA_CHA_REVT1, EDMA_OPEN_RESET);

    #endif

    /* Open the McBSP channel 1 */

    hMcbsp1 = MCBSP_open(MCBSP_DEV1, MCBSP_OPEN_RESET);

    #if (EDMA_SUPPORT)

    /* Configure the EDMA channels */

    ConfigEDMA();

    /* enable EDMA-CPU interrupt tied to McBSP */

    IRQ_enable(IRQ_EVT_EDMAINT);

    /* enable EDMA channel interrupt to CPU */

    EDMA_intEnable(14);
    EDMA_intEnable(15);

    /* Enable EDMA channels */

    EDMA_enableChannel(hEdma14);
    EDMA_enableChannel(hEdma15);

    #endif

    /* Setup for McBSP */

    ConfigMcBSP();

    /* Start Sample Rate Generator: set /GRST = 1 */

     MCBSP_enableSrgr(hMcbsp1);

    /* inserted wait time for McBSP to get ready */

    for (waittime=0; waittime<0xF; waittime++);

    /* Wake up the McBSP as transmitter and receiver */
    
    MCBSP_enableXmt(hMcbsp1);
    MCBSP_enableRcv(hMcbsp1);
    
    
    /* Enable Frame Sync Generator for McBSP 1: set /FRST = 1 */

    MCBSP_enableFsync(hMcbsp1);

    /* To flag an interrupt to the CPU when EDMA transfer/receive is done */

    while (!receive_done || !transmit_done);
    //while (!receive_done);

    /* Check to make sure the test case works */

/*    works = CheckTestCase();
        
    printf("works=%d\n",works);

    if (works != 0)
    printf("Transmission Error....\n\n");

    else
    printf("Received data matched transmitted data!\n\n"); */

    /* process received data */

    printf("Processing Receive string...\n");
    ProcessReceiveData();
    printf("String received: %s \n", recv_msg);
    

    #if (EDMA_SUPPORT)

    IRQ_disable(IRQ_EVT_EDMAINT);
    EDMA_RSET(CIER, 0x0);

    #endif

    MCBSP_close(hMcbsp1); /* close McBSP 1 */

    #if (EDMA_SUPPORT)

    EDMA_close(hEdma14); /* close EDMA 14 */
    EDMA_close(hEdma15); /* close EDMA 15 */

    #endif

} /* End of main() */
    
/*******************************************************************/
/* void ConfigEDMA(void): set up EDMA channel 14/15 for UART Xmit */
/*******************************************************************/

    #if (EDMA_SUPPORT)
    void ConfigEDMA(void)
    {
        EDMA_configArgs(hEdma14,

        /* OPT Setup */

        #if (C64_SUPPORT)

        EDMA_OPT_RMK(
        EDMA_OPT_PRI_HIGH, /* 1 */
        EDMA_OPT_ESIZE_16BIT, /* 01 */
        EDMA_OPT_2DS_NO, /* 0 */
        EDMA_OPT_SUM_INC, /* 01 */
        EDMA_OPT_2DD_NO, /* 0 */
        EDMA_OPT_DUM_NONE, /* 00 */
        EDMA_OPT_TCINT_YES, /* 1 */
        EDMA_OPT_TCC_OF(14), /* 14 */
        EDMA_OPT_TCCM_DEFAULT, /* 0 */
        EDMA_OPT_ATCINT_DEFAULT /* 0 */
        EDMA_OPT_ATCC_DEFAULT, /* 0 */
        EDMA_OPT_PDTS_DEFAULT, /* 0 */
        EDMA_OPT_PDTD_DEFAULT, /* 0 */
        EDMA_OPT_LINK_NO, /* 0 */
        EDMA_OPT_FS_NO /* 0 */
        ),

        #else

        EDMA_OPT_RMK(
        EDMA_OPT_PRI_HIGH, /* 1 */
        EDMA_OPT_ESIZE_16BIT, /* 01 */
        EDMA_OPT_2DS_NO, /* 0 */
        EDMA_OPT_SUM_INC, /* 01 */
        EDMA_OPT_2DD_NO, /* 0 */
        EDMA_OPT_DUM_NONE, /* 00 */
        EDMA_OPT_TCINT_YES, /* 1 */
        EDMA_OPT_TCC_OF(14), /* 14 */
        EDMA_OPT_LINK_NO, /* 0 */
        EDMA_OPT_FS_NO /* 0 */
        ),

        #endif

        /* SRC Setup */

        EDMA_SRC_RMK((Uint32) xmitbuf), /*xmitbuf address*/

        /* CNT Setup */

        EDMA_CNT_RMK(
        EDMA_CNT_FRMCNT_DEFAULT,
        EDMA_CNT_ELECNT_OF(BUFFER_SIZE*11)
        ),

        /* DST Setup */

        EDMA_DST_RMK(MCBSP_getXmtAddr(hMcbsp1)),

        /* IDX Setup */

        EDMA_IDX_RMK(0,0),

        /* RLD Setup */

        EDMA_RLD_RMK(0,0)
        );

        EDMA_configArgs(hEdma15,

        /* OPT Setup */

        #if (C64_SUPPORT)

        EDMA_OPT_RMK(
        EDMA_OPT_PRI_HIGH, /* 1 */
        EDMA_OPT_ESIZE_16BIT, /* 01 */
        EDMA_OPT_2DS_NO, /* 0 */
        EDMA_OPT_SUM_NONE, /* 00 */
        EDMA_OPT_2DD_NO, /* 0 */
        EDMA_OPT_DUM_INC, /* 01 */
        EDMA_OPT_TCINT_YES, /* 1 */
        EDMA_OPT_TCC_OF(15), /* 15 */
        EDMA_OPT_TCCM_DEFAULT, /* 0 */
        EDMA_OPT_ATCINT_DEFAULT /* 0 */
        EDMA_OPT_ATCC_DEFAULT, /* 0 */
        EDMA_OPT_PDTS_DEFAULT, /* 0 */
        EDMA_OPT_PDTD_DEFAULT, /* 0 */
        EDMA_OPT_LINK_NO, /* 0 */
        EDMA_OPT_FS_NO /* 0 */
        ),

        #else

        EDMA_OPT_RMK(
        EDMA_OPT_PRI_HIGH, /* 1 */
        EDMA_OPT_ESIZE_16BIT, /* 01 */
        EDMA_OPT_2DS_NO, /* 0 */
        EDMA_OPT_SUM_NONE, /* 00 */
        EDMA_OPT_2DD_NO, /* 0 */
        EDMA_OPT_DUM_INC, /* 01 */
        EDMA_OPT_TCINT_YES, /* 1 */
        EDMA_OPT_TCC_OF(15), /* 15 */
        EDMA_OPT_LINK_NO, /* 0 */
        EDMA_OPT_FS_NO /* 0 */
        ),

        #endif

        /* SRC Setup */

        EDMA_SRC_RMK(MCBSP_getRcvAddr(hMcbsp1)),

        /* CNT Setup */

        EDMA_CNT_RMK(0, (BUFFER_SIZE * 11)),

        /* DST Setup */

        EDMA_DST_RMK((Uint32) recvbuf), /*recvbuf address*/

        /* IDX Setup */

        EDMA_IDX_RMK(0,0),

        /* RLD Setup */

        EDMA_RLD_RMK(0,0)
        );

    } /* End of ConfigEDMA() */

    #endif
    
    void ConfigMcBSP(void)
    {
        MCBSP_Config mcbspCfg1 = {

        /* SPCR Setup */

        #if (EDMA_SUPPORT)

        MCBSP_SPCR_RMK(
        MCBSP_SPCR_FREE_YES, /* 1 */
        MCBSP_SPCR_SOFT_DEFAULT, /* 0 */
        MCBSP_SPCR_FRST_DEFAULT, /* 0 */
        MCBSP_SPCR_GRST_DEFAULT, /* 0 */
        MCBSP_SPCR_XINTM_XRDY, /* 00 */
        MCBSP_SPCR_XSYNCERR_DEFAULT, /* 0 */
        MCBSP_SPCR_XRST_DEFAULT, /* 0 */
        MCBSP_SPCR_DLB_OFF, /* 0 */
        MCBSP_SPCR_RJUST_RZF, /* 00 */
        MCBSP_SPCR_CLKSTP_DISABLE, /* 0 */
        MCBSP_SPCR_DXENA_OFF, /* 0 */
        MCBSP_SPCR_RINTM_RRDY, /* 00 */
        MCBSP_SPCR_RSYNCERR_DEFAULT, /* 0 */
        MCBSP_SPCR_RRST_DEFAULT /* 0 */
        ),

        #endif

        /* RCR Setup */

        #if (EDMA_SUPPORT)

        MCBSP_RCR_RMK(
        MCBSP_RCR_RPHASE_DUAL, /* 1 */
        MCBSP_RCR_RFRLEN2_OF(1), /* 00010 */
        MCBSP_RCR_RWDLEN2_8BIT, /* 000 */
        MCBSP_RCR_RCOMPAND_MSB, /* 00 */
        MCBSP_RCR_RFIG_YES, /* 1 */
        MCBSP_RCR_RDATDLY_1BIT, /* 01 */
        MCBSP_RCR_RFRLEN1_OF(8), /* 01000 */
        MCBSP_RCR_RWDLEN1_16BIT, /* 010 */
        MCBSP_RCR_RWDREVRS_DISABLE /* 0 */
        ),

        #endif

        /* XCR Setup */

        #if (EDMA_SUPPORT)

        MCBSP_XCR_RMK(
        MCBSP_XCR_XPHASE_DUAL,
        MCBSP_XCR_XFRLEN2_OF(1),
        MCBSP_XCR_XWDLEN2_8BIT,
        MCBSP_XCR_XCOMPAND_MSB,
        MCBSP_XCR_XFIG_YES,
        MCBSP_XCR_XDATDLY_0BIT,
        MCBSP_XCR_XFRLEN1_OF(8),
        MCBSP_XCR_XWDLEN1_16BIT,
        MCBSP_XCR_XWDREVRS_DISABLE
        ),

        #endif

        /* SRGR Setup */

        MCBSP_SRGR_RMK(
        MCBSP_SRGR_GSYNC_FREE, /* 0 */
        MCBSP_SRGR_CLKSP_RISING, /* 0 */
        MCBSP_SRGR_CLKSM_INTERNAL, /* 1 */
        MCBSP_SRGR_FSGM_DXR2XSR, /* 0 */
        MCBSP_SRGR_FPER_DEFAULT, /* 0 */
        MCBSP_SRGR_FWID_DEFAULT, /* 0 */
        MCBSP_SRGR_CLKGDV_OF(243) /* CLKGDV */
        ),

        /* MCR Setup */

        MCBSP_MCR_DEFAULT, /* default values */

        /* RCER Setup */

        #if (C64_SUPPORT)

        MCBSP_RCERE0_DEFAULT, /* default values */
        MCBSP_RCERE1_DEFAULT, /* default values */
        MCBSP_RCERE2_DEFAULT /* default values */
        MCBSP_RCERE3_DEFAULT, /* default values */

        #else
        MCBSP_RCER_DEFAULT, /* default values */

        #endif

        /* XCER Setup */

        #if (C64_SUPPORT)

        MCBSP_XCERE0_DEFAULT, /* default values */
        MCBSP_XCERE1_DEFAULT, /* default values */
        MCBSP_XCERE2_DEFAULT, /* default values */
        MCBSP_XCERE3_DEFAULT, /* default values */

        #else

        MCBSP_XCER_DEFAULT, /* default values */
        #endif

        /* PCR Setup */

        MCBSP_PCR_RMK(
            MCBSP_PCR_XIOEN_SP,                    /* 0 */
            MCBSP_PCR_RIOEN_SP,                    /* 0 */
            MCBSP_PCR_FSXM_INTERNAL,            /* 1 */
            MCBSP_PCR_FSRM_EXTERNAL,            /* 0 */
            MCBSP_PCR_CLKXM_OUTPUT,                /* 1 */
            MCBSP_PCR_CLKRM_OUTPUT,                /* 1 */
            MCBSP_PCR_CLKSSTAT_0,                /* 0 */
            MCBSP_PCR_DXSTAT_0,                    /* 0 */
            MCBSP_PCR_FSXP_ACTIVELOW,            /* 1 */
            MCBSP_PCR_FSRP_ACTIVELOW,            /* 1 */
            MCBSP_PCR_CLKXP_RISING,                /* 0 */
            MCBSP_PCR_CLKRP_FALLING                /* 0 */
        )
        };

        MCBSP_config(hMcbsp1, &mcbspCfg1);
    } /* end of Config_McBSP(void) */
    
/*******************************************************************/
/* void ProcessTransmitData(void) */
/* */
/* This function expands each of the 8-bit ASCII characters in the */
/* transmit string "xmit_msg" into UART transmission 16-bit word */
/* and place them in the transmit buffer "xmitbuf". In addition, */
/* 16-bit Start and 8-bit Stop framing words, respectively, are */
/* inserted before and after each of the ASCII characters in the */
/* buffer. */
/*******************************************************************/

    void ProcessTransmitData(void)
    {
        int i;
        short cnt = 1;
        unsigned char xmit_char;
        unsigned short *xmitbufptr;

        /* point to Transmit Buffer */
        xmitbufptr = (unsigned short *)xmitbuf;
        
        for (i=0; i<(sizeof(xmitbuf)/sizeof(unsigned int)); i++)
        {
            xmitbufptr[i] = 0x0000; /* zero fill buffer */
        }

        /* Process data BYTES in xmit_msg[] and put in xmit buffer */
        for (i = 0; i < BUFFER_SIZE; i++)
        {

            /* Get transmit character (one byte) from xmit_msg[] */
            /* and put in xmit buffer */
            xmit_char = xmit_msg[i];
            
            /* Process each BYTE of transmit character */
            for (cnt = -1; cnt < 10; cnt++)
            {
                if (cnt == -1)
                *xmitbufptr++ = 0x0000;

                else if (cnt == 8 || cnt ==9)
                *xmitbufptr++ = 0x00FF;

                else if (xmit_char & (1 << cnt))
                *xmitbufptr++ = 0xFFFF;

                else
                *xmitbufptr++ = 0x0000;
                
            } /* end for cnt */
        
        } /* end for I */
    //    MCBSP_write(hMcbsp1, 'a');

    } /* end ProcessTransmitData */
    
/*******************************************************************/
/* void ProcessReceiveData(void) */
/* */
/* This function decodes the data in the receive buffer, "recvbuf" */
/* and strips the framing start (0x0000) and Stop (0xFFFF) words. */
/* It calls the subroutine VoteLogic() to determine each bit of */
/* the ASCII character. It then puts the result in recv_msg. */
/*******************************************************************/

    void ProcessReceiveData(void)
    {
        int i;
        unsigned char recv_char = 0;
        short cnt = -1;
        short recv_val;
        unsigned short raw_data;
        unsigned short *recvbufptr; /*receive buffer pointer*/
    //    unsigned char c;

        /* Point to the receive buffer */

        recvbufptr = (unsigned short *)recvbuf;

    
        /* Process all data in the Receive buffer */

        for (i = 0; i < BUFFER_SIZE; i++)
        {
            recv_char = 0;

            /* Process each UART frame */

            for (cnt = -1; cnt < 10; cnt++)
            {
                if(cnt == -1 || cnt == 8 || cnt == 9)
                {
                    /* Ignore Start and Stop bits */

                    *recvbufptr++;
                }
                else
                {
                    /* Get 16-bit data from receive buffer */

                    raw_data = *recvbufptr;
                    recvbufptr++;

                    /* get the value of the majority of the bits */

                    recv_val = VoteLogic(raw_data);

                    /* put received bit into proper place */

                    recv_char += recv_val << cnt;
                }

            } /* end for cnt */

            /* A full BYTE is decoded. Put in result: recv_msg[i] */

            recv_msg[i] = recv_char;
            recv_msg[BUFFER_SIZE] = NULL;
        
        } /* end for I */
    /*    c=MCBSP_read(hMcbsp1);
        printf("mcbsp read is %c\n",c); */

    } /* end ProcessReceiveData() function */
    
/*******************************************************************/
/* void CheckTestCase(void) */
/*******************************************************************/

    int CheckTestCase(void)
    {
        unsigned short *source;
        unsigned short *result;
        unsigned int i = 0;
        short cnt = -1;
        int error = 0;
        source = (unsigned short *) xmitbuf;
        result = (unsigned short *) recvbuf;
        for (i = 0; i < BUFFER_SIZE ; i++)
        {
            for (cnt = -1; cnt < 10; cnt++)
            {
                /* Ignore the start and stop bits */
                if(cnt == -1 || cnt == 8 || cnt ==9)
                {
                    source++;
                    result++;
                }

                else
                {
                    if (*source != *result)
                    {
                        error = i + 1;
                        break;
                    }

                    source++;
                    result++;
                }

            }

        }
        return(error);

    } /* end CheckTestCase() function */

    /*******************************************************************/
    /* short VoteLogic(unsigned short) */
    /* */
    /* This function decoded the received character by testing the */
    /* center 4 bits of the baud. A majority rule is used for the */
    /* decoding. */
    /*******************************************************************/
    short VoteLogic(unsigned short value)
    {
        short returnvalue;
        switch ((value >> 6) & 0x0F)
        {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 8:
            case 9:
            case 10:
            returnvalue = 0;
            break;

            case 7:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            returnvalue = 1 ;
            break;

        } /* end switch */

        return (returnvalue);

    } /* end VoteLogic() function */

    /*******************************************************************/
    /* EDMA Data Transfer Completion ISRs */
    /*******************************************************************/
    interrupt void c_int08(void)
    {
        #if (EDMA_SUPPORT)
        if (EDMA_intTest(14))
        {
            EDMA_intClear(14);
            transmit_done = TRUE;
            printf("Transmit Completed\n");
        }

        if (EDMA_intTest(15))
        {
            EDMA_intClear(15);
            receive_done = TRUE;
            printf("Receive Completed\n\n");
        }
        #endif
    }


  • Hi Rakesh T,

    Thanks for your post.

    I think, there is an application report SPRA455A for using McBSP as high speed communication port, in which please refer Appendix A which gives you a sample code for McBSP Master Tx. and the code would be compatible for C621x/C671x. Please validate your McBSP Tx. part with this code.

    http://www.ti.com/lit/an/spra455a/spra455a.pdf

    Thanks & regards,

    Sivaraj K

    ---------------------------------------------------------------------------------
    Please click the Verify Answer button on this post if it answers your question.
    ---------------------------------------------------------------------------------

  • sir,

    Transmission also working the same code. but at that time reception is not possible. when i am power off the  board for sometime, reception is working but transmission is not. If am power off the board and start code composer studio again then transmission is working properly but reception is not. can you please help me to find out the problem behind this.

  • HI Rakesh,

    Thanks for your update.

    I would recommend you to validate your code with the sample code mentioned in Appendix A with the above doc. which i have shared in my earlier post. Kindly validate your McBSP Master Tx. configuration with SPRA455A doc. and also refer Appendix B for McBSP Slave Rx. configuration.

    Thanks & regards,

    Sivaraj K

    ---------------------------------------------------------------------------------
    Please click the Verify Answer button on this post if it answers your question.
    ---------------------------------------------------------------------------------