Receiving first character as null in received string in RL78/F13

Hello All,

I am making a command line interpreter which will take input from the user using UART and execute the code related to the command received. I am using Renesas R5F10BMG MCU. When I send the command $CMD INIT, I am getting the received string as shown in the image . I am using RealTerm

software for UART communication. It automatically append '\r' character at the end of the string. Why the 0th index is '0' instead of '$'? The print function could transmit the string properly but problem occurs during reception of string.

 

/*********************serial.c file ***************/
void uart1_p_init (void)
{
   /***** Configure UART0 *****/
   /* Supply clock to serial array unit 1 */
   SAU1EN = 1;

    /* >=4 cycle delay required by manual */
    NOP();
    NOP();
    NOP();
    NOP();
    NOP();

    /***** Set input clock (CK00 and CK01) to Fclk *****/
    /* ck00 - fCLK/2^4 */
    SPS1 = 0x0004U;
    /* ck01 - fCLK */
    SPS1 |= 0x0000U ;

    /***** Setup operation mode for transmitter (channel 1) *****/
    /* SMR10 initial value */
    SMR10 = 0x0020U;
    /* operation clock CK0 set by PRS register */
    SMR10 |= 0x0000U;
    /* only software trigger is valid */
    SMR10 |= 0x0000U;
    /* UART mode */
    SMR10 |= 0x0002U;
    /* transfer end interrupt */
    SMR10 |= 0x0000U;

    /* transmission only */
    SCR10 = 0x8000U;
    /* none parity */
    SCR10 |= 0x0000U;
    /* LSB */
    SCR10 |= 0x0080U;
    /* 1 stop bit */
    SCR10 |= 0x0010U;
    /* 08-bit data length */
    SCR10 |= 0x0007U;


    SDR10 = 0xCE00U; //_CE00_UART1_TRANSMIT_DIVISOR;

    /* noise filter on */
    NFEN0 = 0x04U;

    SIR11 = 0x0004 | 0x0002 | 0x0001;    /* clear error flag */

    SMR11 = 0x0020 | 0x0000 | 0x0100 | 0x0000 | 0x0002 | 0x0000;
    SCR11 = 0x4000 | 0x0000 | 0x0080 | 0x0010 | 0x0007;
    SDR11 = 0xCE00;

    /* Output is not inverted */
    SO1 |= 0x01U;

    /* Initial output level is 1(normal level) */
    SO1 |= 0x01U;

    /* Enable UART1 output */
    SOE1 |= 0x01U;

    /* Set RxD1 pin */
    PM1 |= 0x02U; //P11 as RxD1

    /* Set TxD1 pin */
    P1 |= 0x04U;
    PM1 &= 0xFBU; //P12 as TxD1

    /* Enable UART1 transmit and receive operation (channel 1) */
    SS1 = 0x02U | 0x01U;

    /* Enable INTST1 interrupt flag */
    STIF1 = 1;
    SRIF1 = 1;
}

/* Receive the character */
UInt8 uart1_getchar(void)
{
    while (0U == SRIF1);
    SRIF1 = 0U;
    return (UInt8)SDR11L;
}

void uart1_gets(UInt8 *string)
{
    UInt8 i=0,j=0;
    do
    {
        *(string+i)= uart1_getchar();
        j = *(string+i);
        i++;
    }while((j!='\n') && (j!='\r'));
    i++;
    *(string+i) = '\0';
}

/**************main.c file******************/
int main(void)
{
	print("CMD Initialized!");
    while(1U)
    {
    	exec_cmd();
    }
	return 0;
}

/****************cmd.c file*******************/
unsigned char RxBuf[12];
void exec_cmd()
{
	uart1_gets(RxBuf);
	/* compare the input buffer with command string */
	if((strncmp("$CMD INIT",(const unsigned char *)RxBuf,9) == 0) && (RxBuf[9]=='\r'))
	{
		 print("$CMD INIT OK\n");

	}
}