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 receiving problem

I am working on code of McBSP as UART provided in SPRA633. It transmits well, but during reception first character is received correctly, second and onward characters are not received correctly.

I am using external crystal of 3.6864 MHz, to generate exact baud rate of 9600.

If I am receiving 10 characters and send 10 characters consecutively, not all characters are received well. If  I send 10 characters  not consecutively but each time a single character is send to make 10 characters all character are received well. I am using hyper terminal to send characters to DSK6713 board.

I think after receiving first character processor is busy in processing of first character, when second and onwards character are received.

 my code for receiving

 

/*******************************************************************/
/* 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*/
/* 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;
 } /* end for I */
} /* end ProcessReceiveData() function */

 

 

Code for McBSP initialization is

void ConfigMcBSP(void)
{

 MCBSP_Config mcbspCfg1 = {
  
  /* SPCR Setup */
 
 
   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  */
   ),
 
  
  /* RCR Setup */ 
 
 
   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  */ // 0 delay
      MCBSP_RCR_RFRLEN1_OF(8),   /* 01000 */
       MCBSP_RCR_RWDLEN1_16BIT,  /* 010  */
       MCBSP_RCR_RWDREVRS_DISABLE   /* 0     */ 
      ),
 
   
    /* XCR Setup */
   
    
    MCBSP_XCR_RMK(
            MCBSP_XCR_XPHASE_DUAL,   /* 1     */
        MCBSP_XCR_XFRLEN2_OF(1),  /* 00010 */ 
      MCBSP_XCR_XWDLEN2_8BIT,   /* 000  */
      MCBSP_XCR_XCOMPAND_MSB,   /* 00  */
      MCBSP_XCR_XFIG_YES,   /* 1  */
      MCBSP_XCR_XDATDLY_0BIT,   /* 00  */
     MCBSP_XCR_XFRLEN1_OF(8),  /* 01000 */
      MCBSP_XCR_XWDLEN1_16BIT,  /* 010  */
      MCBSP_XCR_XWDREVRS_DISABLE  /* 0  */
   ),
  
    
  /* SRGR Setup */   
     MCBSP_SRGR_RMK(
      MCBSP_SRGR_GSYNC_FREE,    /* 0   */
      MCBSP_SRGR_CLKSP_RISING,   /* 0   */  
      MCBSP_SRGR_CLKSM_CLKS,   /* 1   */
      MCBSP_SRGR_FSGM_DXR2XSR,   /* 0    */
      MCBSP_SRGR_FPER_DEFAULT,   /* 0   */
      MCBSP_SRGR_FWID_DEFAULT,   /* 0   */
     MCBSP_SRGR_CLKGDV_OF(23)   /* CLKGDV for (baud rate 57600=122, cpuClk=112.5MHz) */       
    ),
  
  /* MCR Setup */
    MCBSP_MCR_DEFAULT,       /* default values */

  /* RCER Setup */
   
     MCBSP_RCER_DEFAULT,      /* default values */
  
  
  /* XCER Setup */
 
     MCBSP_XCER_DEFAULT,      /* default values */
  
  
  /* 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) */

 

 

Code for EDMA Initialization is

void ConfigEDMA(void)

 EDMA_configArgs(hEdma14,
 
     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  */
     ),    
   
  
  /* 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 */
 
      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  */
     ),
       
    /* SRC Setup */
    EDMA_SRC_RMK(MCBSP_getRcvAddr(hMcbsp1)),
    
    /* CNT Setup */
    EDMA_CNT_RMK(
 EDMA_CNT_FRMCNT_DEFAULT,
 EDMA_CNT_ELECNT_OF(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() */


 

  • Try increasing the number of stop bits in HyperTerm and see if that helps.

    Regards,
    RandyP

  • Thanks for reply.

    I cant incease number of stop bits. I have to communicate with other system, and RS232 protocol with one stop bit is finalized.

    I have changed McBSP and EDMA settings to decrease element size from 16 bits to 8 bits , but it also does not give me any help.

    Please try to give me another idea.

    Thanks,

    Zeeshan

  • Zeeshan,

    Try increasing the number of stop bits in HyperTerm. This is a debug methodology, not a system specification change. It should have a similar effect to the decreased element size, but it could be different. If it works in that case, then you have a lot of information to help with a solution to your real problem; if it does not help, then you have closed one possible problem path.

    The other idea is to figure out a way to follow your code and the EDMA data capture and correlate it to the McBSP waveform on the pins. That may have to be done anyway, but the other steps are easier and can help narrow the range of debug.

    To debug, you may want to do experiements with different element sizes, data patterns, comparison with the CPU method, etc.

    Regards,
    RandyP

  • Thanks for reply.

    Sorry for late from my side actually I was busy.

    When I increased the number of stop bits to 2 it really helps me a lot all characters are received correctly. But increasing stop bits to 1.5 does not help me.

    Kindly guide me more that what should I do to improve my code so that code will receive all characters even with One stop bit.

    Regards,

    Zeeshan

  • Guidance:

    The app note explains how the code works, and you have the source code. Study it to learn how the code works in detail, how it uses the resources to use a GPIO pin as a UART data line.

    Identify what processing the code is doing on received data once the data has been received.

    Consider the ways that an asynchronous communications channel can have problems in sharing data with no clock line.

    Determine if resources can be started sooner. EDMA, GPIO, interrupt. It may not make sense, but look at it from that point-of-view for better understanding.

    Examine why the fix you did with the stop bits affected the results. Find which part of the code improved from this, and see if you can change that code.

    Good luck with your project.

    Regards,
    RandyP

  • Thanks,

    I have tried a lot to fix the problem, but I am not successful.

    I have understand the whole code and tried a lot to find the solution.

    Kindly guide me more.

    Regards,

    Zeeshan

  • Zeeshan,

    From your understanding of the code, would you agree that there are two major components to the operation: EDMA capture and DSP processing? Or what other major component would you add to those? I am thinking only of the received data, not the transmit data.

    EDMA Capture:

    What event on the receive serial data line causes the EDMA capture to begin?
    What will be captured into the destination memory? How many words? What part of the UART protocol do they represent?
    What event on the receive serial data line causes the EDMA interrupt to be generated?
    Can you draw out a timeline of the serial data stream that allows you to point to where these events are on the data stream for successive bytes?
    What allows the EDMA to start capturing the next byte? Is it automatically searching or is there DSP code required to start the EDMA searching again?

    DSP processing:

    When the DSP gets an interrupt from the EDMA to tell it data has arrived, does it copy that data or work with it in place?
    How much time does the DSP spend on each data bit as it builds the data byte?
    What does the DSP do in its analysis, if any, of the start and stop bits?
    What does the DSP do, if anything, to prepare the EDMA for capturing the next byte? Does the DSP start that capture or is it automatic?

    I do not know the answer to these questions. Your answers to these will guide you through the code to find where a solution might be possible, and your answers will help me to find the next questions to ask you as we look into this.

    Regards,
    RandyP