Unable to write anything to renesas R5F10268 through UART0 using R_UART0_Receive() function.

Hi,

Device- R5F10268 

OS- Windows 10

e2 studio version - Version: 7.2.0
Build Id: R20181004-2004

Problem:-

I am trying to communicate through UART by using R_UART0_Receive()  and R_UART0_Send() function. I am able to use R_UART0_Send() function and able to get data from MCU to my serial monitor but not able to write to MCU through serial monitor. I tried many condition and comes to know that R_UART0_Receive() function not returning any value. My code is attached below. Let me know if you need more information.

 

```

/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* www.renesas.com/disclaimer
*
* Copyright (C) 2011, 2018 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/

/***********************************************************************************************************************
* File Name : r_main.c
* Version : CodeGenerator for RL78/G12 V2.04.02.04 [18 May 2018]
* Device(s) : R5F10268
* Tool-Chain : GCCRL78
* Description : This file implements main function.
* Creation Date: 12/17/2019
***********************************************************************************************************************/

/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_cgc.h"
#include "r_cg_port.h"
#include "r_cg_serial.h"
#include "r_cg_adc.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"

/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
uint8_t g_uart0_rx_buffer = 0U; /* UART0 receive buffer */
uint8_t g_uart0_rx_error = 0U; /* UART0 receive error status */
MD_STATUS g_uart0_tx_end = 0U; /* UART0 transmission end */
uint16_t g_result_buffer_a = 0U; /* AD converter result buffer */
uint16_t g_result_buffer_b = 0U;
uint16_t g_result_buffer_c = 0U;
uint8_t data_a[2] = { 97, 65 };
uint8_t data_b[2] = { 97, 65 };
uint8_t data_c[2] = { 97, 65 };

int old_var_a = 0;
int old_var_b = 0;
int old_var_c = 0;

int temp[5];

uint8_t g_messageOK[4] = {"OK\r\n"}; /* Message for "T" */
uint8_t g_messageok[4] = {"ok\r\n"}; /* Message for "t" */
uint8_t g_messageUC[4] = {"UC\r\n"}; /* Message for other */
uint8_t g_messageFE[4] = {"FE\r\n"}; /* Framing error message */
uint8_t g_messagePE[4] = {"PE\r\n"}; /* Parity error message */
uint8_t g_messageOE[4] = {"OE\r\n"}; /* Overrun error message */

//ADS = _00_AD_INPUT_CHANNEL_0;
//ADS = _15_AD_INPUT_CHANNEL_21;
//ADS = _16_AD_INPUT_CHANNEL_22;

/* End user code. Do not edit comment generated here */
void R_MAIN_UserInit(void);

/***********************************************************************************************************************
* Function Name: main
* Description : This function implements main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void td(int delay)
{
int i =0;
for(i=0;i<8*delay;i++)
NOP();
}

void main(void)
{
int RUN_FLAG = 0;
// int GAIN_FLAG = 0;
int td_delay = 100;
P2_bit.no1 = 0x00;
P2_bit.no2 = 0x01;
P2_bit.no3 = 0x00;
P1_bit.no0 = 0x00;
P1_bit.no3 = 0x01;
P1_bit.no4 = 0x00;

R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
{
volatile MD_STATUS status = 0U; /* UART Status */
int i = 0;

R_ADC_Set_OperationOn(); /* Enable comparator operation */

/* ---- stabilization wait time(about 1us) ---- */
for (i = 0U; i < 3U; i++)
{
NOP();
}

R_ADC_Start(); /* Start AD converter */


ADS = _00_AD_INPUT_CHANNEL_0;
// ADS = _15_AD_INPUT_CHANNEL_21;
// ADS = _16_AD_INPUT_CHANNEL_22;

/* UART0 receive buffer setting */
status = R_UART0_Receive(&g_uart0_rx_buffer, 1U);

/* Start the UART0 Tx/Rx operation */
R_UART0_Start();

// if(g_uart0_rx_buffer)
// RUN_FLAG = 1;

 

while (1U)
{
if(g_uart0_rx_buffer != '0')
{

switch (g_uart0_rx_buffer) /* Check Reception data */
{
case 'P': // Stop // Reception data is 'P'
RUN_FLAG = 0;
// GAIN_FLAG = 0;
break;
case 'S': // Start // Reception data is 'S' //filter_init();
RUN_FLAG = 1;
break;

case '1': // Gain 1 Selection // Reception data is '1'
P2_bit.no1 = 0x00;
P2_bit.no2 = 0x00;
P2_bit.no3 = 0x00;
P1_bit.no0 = 0x00;
P1_bit.no3 = 0x00;
P1_bit.no4 = 0x00;
ADS = _00_AD_INPUT_CHANNEL_0;
break;

case '2': // Gain 2 Selection // Reception data is '2'
P2_bit.no1 = 0x01;
P2_bit.no2 = 0x00;
P2_bit.no3 = 0x00;
P1_bit.no0 = 0x01;
P1_bit.no3 = 0x00;
P1_bit.no4 = 0x00;
ADS = _00_AD_INPUT_CHANNEL_0;
break;

case '3': // Gain 3 Selection // Reception data is '3'
P2_bit.no1 = 0x00;
P2_bit.no2 = 0x01;
P2_bit.no3 = 0x00;
P1_bit.no0 = 0x00;
P1_bit.no3 = 0x01;
P1_bit.no4 = 0x00;
ADS = _00_AD_INPUT_CHANNEL_0;
break;

case '4': // Gain 4 Selection // Reception data is '4'
P2_bit.no1 = 0x01;
P2_bit.no2 = 0x01;
P2_bit.no3 = 0x00;
P1_bit.no0 = 0x01;
P1_bit.no3 = 0x01;
P1_bit.no4 = 0x00;
ADS = _00_AD_INPUT_CHANNEL_0;
break;

case '5': // Gain 5 Selection // Reception data is '5'
P2_bit.no1 = 0x00;
P2_bit.no2 = 0x00;
P2_bit.no3 = 0x01;
P1_bit.no0 = 0x00;
P1_bit.no3 = 0x00;
P1_bit.no4 = 0x01;
ADS = _00_AD_INPUT_CHANNEL_0;
break;

case '6': // Gain 6 Selection Reception data is '6'
P2_bit.no1 = 0x01;
P2_bit.no2 = 0x00;
P2_bit.no3 = 0x01;
P1_bit.no0 = 0x01;
P1_bit.no3 = 0x00;
P1_bit.no4 = 0x01;
ADS = _00_AD_INPUT_CHANNEL_0;
break;

case '7': // Gain 7 Selection /* Reception data is '7'
P2_bit.no1 = 0x00;
P2_bit.no2 = 0x01;
P2_bit.no3 = 0x01;
P1_bit.no0 = 0x00;
P1_bit.no3 = 0x01;
P1_bit.no4 = 0x01;
ADS = _00_AD_INPUT_CHANNEL_0;
break;

case '8': // Gain 8 Selection /* Reception data is '8'
P2_bit.no1 = 0x01;
P2_bit.no2 = 0x01;
P2_bit.no3 = 0x01;
P1_bit.no0 = 0x01;
P1_bit.no3 = 0x01;
P1_bit.no4 = 0x01;
ADS = _00_AD_INPUT_CHANNEL_0;
break;

case 'a': // Sample rate ~ 1000 /* Reception data is 'a'
td_delay = 65;
break;
case 'b': // Sample rate ~ 250 /* Reception data is 'b'
td_delay = 821;
break;
case 'c': // Sample rate ~ 500 /* Reception data is 'c'
td_delay = 700;
break;
case 'd': //Sample rate ~ 125 /* Reception data is 'd'
td_delay = 1300;
break;
}
}
/* Finish Reception and check result */
SRMK0 = 1U; /* Disable Reception Interrupt */
SREMK0 = 1U; /* Disable Reception error Interrupt */

/* For next reception */
g_uart0_rx_buffer = 0;
/* Set reception buffer pointer */
status = R_UART0_Receive(&g_uart0_rx_buffer, 1U);

SRMK0 = 0U; /* Enable Reception Interrupt */
SREMK0 = 0U; /* Enable Reception error Interrupt */

if (RUN_FLAG == 1)
{
// ADS = _00_AD_INPUT_CHANNEL_0;// ANI0
R_ADC_Get_Result(&g_result_buffer_a);
old_var_a=g_result_buffer_a;
data_a[1] = old_var_a;
data_a[0] = (old_var_a >> 8);
g_uart0_tx_end = R_UART0_Send((uint8_t *) data_a, 2u);
// td(100);
// ADS = _15_AD_INPUT_CHANNEL_21;//ANI21
// R_ADC_Get_Result(&g_result_buffer_b);
// old_var_b=g_result_buffer_b;
// data_b[1] = old_var_b;
// data_b[0] = (old_var_b >> 8);
// g_uart0_tx_end = R_UART0_Send((uint8_t *) data_b, 2u);
// td(100);
// ADS = _16_AD_INPUT_CHANNEL_22;//ANI22
// R_ADC_Get_Result(&g_result_buffer_c);
// old_var_c=g_result_buffer_c;
// data_c[1] = old_var_c;
// data_c[0] = (old_var_c >> 8);
// g_uart0_tx_end = R_UART0_Send((uint8_t *) data_c, 2u);
td(165 + td_delay);
}
else
td(300);
}
}

}
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
* Function Name: R_MAIN_UserInit
* Description : This function adds user code before implementing main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_MAIN_UserInit(void)
{
/* Start user code. Do not edit comment generated here */
EI();
/* End user code. Do not edit comment generated here */
}

/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

```