RX62T SCI(UART) can't transmit strings

I'm now using the RX62T 100-pin LQFP to do the SCI(UART) transmission.

I don't want to use the interrupt function,so I just use the flags to do the polling.

Though I'm able to transmit byte by byte now, but somehow, I just can't transmit strings successfully.

No matter how I tried,I just can't write the data into transmit data buffer.

Can anyone help me with this problem? I'd really appreciated.

Below is my code so far:

====================================================================

void SCI2_Asyn_initial(void)
{
// Cancel the module stop state.

    MSTP(SCI2) = 0;

// TXD0 is output
PORTB.DDR.BIT.B6 = 1;
// RxD0 is input
PORTB.DDR.BIT.B5 = 0;
// Enable Input Buffer on RXD0
PORTB.ICR.BIT.B5 = 1;

// Disable SCI
SCI2.SCR.BYTE = 0x00;

SCI2.SMR.BYTE = 0x00;
/*  Set mode register
-Asynchronous Mode
-8 bits
-no parity
-1 stop bit
-PCLK clock (n = 0)
*/
   
// Enable RXI and TXI first to enable IR bits for checking as flags

SCI2.SCR.BIT.RIE = 1;
SCI2.SCR.BIT.TIE = 1;

    // Clear IR bits for TIE and RIE
IR(SCI2,RXI2)=0;
IR(SCI2,TXI2)=0;
  

    /* RXI and TXI interrupts in ICU. Disable (0) if polling. */
    IEN(SCI2, RXI2) = 0;
    IEN(SCI2, TXI2) = 0;
   
/* Set interrupt prio for SCI. */
IPR(SCI2, TXI2) = 2;
IPR(SCI2, RXI2) = 2;

SCI2.SEMR.BIT.NFEN = 1;

SCI2.BRR = 80;

// Enable SCI2
SCI2.SCR.BYTE |= 0x30;
}

void SCI2_PullString( char * msg_string)    //transmit strings
{   
unsigned char i;
       
/* This loop reads in the text string and puts it in the SCI2 transmit buffer */
for (i=0; msg_string[i]; i++)

        /* Wait for transmit buffer to be empty */
  while(IR(SCI2, TXI2) == 0);
       
        /* Clear TXI IR bit */
        IR(SCI2, TXI2) = 0;

  /* Write the character out */
  SCI2.TDR = msg_string[i];
}
}

void SCI2_PullChar( char MSG )   //transmit byte
{
/* Wait for transmit buffer to be empty */
while (SCI2.SSR.BIT.TEND == 0) {;}
    //while(IR(SCI2, TXI2) == 0);
       
/* Clear TXI IR bit */
IR(SCI2, TXI2) = 0;

/* Write the character out */
SCI2.TDR = MSG;
}

void main(void)
{
int j=0;
unsigned long cnt;

//set a serial array with data in it
for(cnt=0; cnt<30; cnt++)
{
  MstTrmBuff[cnt] = cnt;
}

//Transmit serial single byte 
for(j=0;j<10;j++)
{
  SCI2_PullChar(j);
}

//Transmit string
  SCI2_PullString(MstTrmBuff);

while(1)
{
  nop();
}
}

====================================================================

SCI2_PullString is the function I used to transmit strings,but somehow it just won't work.

Can anyone give me some advice that can solve this problem?

Thx a lot!!!

  • Have you tried debugging, e.g. check contents of MstTrmBuff or single step through SCI2_PullString()?

    Why should it send anything if the first element in MstTrmBuff is already 0x00?

  • Thx Frank!!!

    After I changed the setting of MstTrmBuff into :

    for(cnt=0; cnt
    {
      MstTrmBuff[cnt] = 255-cnt;
    }

    The data in MstTrmBuff can now be written into the transmit data buffer.

    but still I'm not quite understand about :

    "Why should it send anything if the first element in MstTrmBuff is already 0x00?"

    Does it means that when the first byte of the strings is 0x00,it won't transfer the data into transmit buffer?or does it means something else?

    If you have time, can you explain more precisely for me?

    Anyway,thx for your answer,it truly helps!!!

     

  • Very simple, in a string 0x00 is the end character. That's why the end condition for the transmit loop is simply msg_string[i]. Data is transmit as long as the buffer value is not 0x00.

    for (i=0; msg_string[i]; i++)

            /* Wait for transmit buffer to be empty */
      while(IR(SCI2, TXI2) == 0);
           
            /* Clear TXI IR bit */
            IR(SCI2, TXI2) = 0;  /* Write the character out */
      SCI2.TDR = msg_string[i];
    }

  • Thx for the explaination,now I understand what do you mean.

    Thx again!!!