Rh850 d1m1 UART transmission and reception not working properly

  • #include "dr7f701441.dvf.h"
    #include "r_typedefs.h"
    //#include "r_rlin3_api.h"

    //#include "my_input_sense.h"
    #include "my_UART0.h"

    //--------------------------------------------------------------------------------------------------------
    #define RLIN3_UNIT 2//0

    #define MY_UART2_ENABLE 1

    #define protected_write(preg,pstatus,reg,value) do { \
    (preg)=0xa5u; \
    (reg)=(value); \
    (reg)=~(value); \
    (reg)=(value); \
    }while((pstatus)==1u)

    unsigned char uart_rx_flag;
    unsigned char uart_tx_flag;
    unsigned char uart_err_flag;

    //#pragma alignvar(128)
    unsigned char my_rx_arr_uart[100];

    unsigned char my_rx_data_uart;

    uint64_t tick_count;

    volatile uint16_t g_uartf0_rx_len; /* uartf0 receive data length */
    volatile uint16_t g_uartf0_rx_cnt; /* uartf0 receive data number */
    volatile uint8_t * gp_uartf0_rx_address; /* uartf0 receive data address */

    //--------------------------------------------------------------------------------------------------------
    uint8_t my_tx_arr_uart[] = "OK";
    //--------------------------------------------------------------------------------------------------------

    void my_UART2_send_byte(unsigned char data)
    {
    while((RLN32LST & 0x10) != 0U);
    RLN32.LUTDR.UINT8[L] = data;
    }

    unsigned char my_UART2_polling_receive(unsigned char *Rx_Data)
    {
    /* wait for a byte to arrive */
    while (( 0 == INTC2EIRF216 ) && ( tick_count ))
    {
    tick_count--;
    }

    if ( 0 == tick_count )
    {
    *Rx_Data = '0';
    return FALSE;
    }

    *Rx_Data = RLN32.LURDR.UINT8[L];
    INTC2EIRF216 = 0;

    return TRUE;

    }

    //--------------------------------------------------------------------------------------------------------
    #if 1
    #pragma ghs interrupt
    void INTRLIN32UR0 (void)
    {
    uart_tx_flag = 1;
    INTC2EIRF217 = 0; // clear interrupt flag

    }

    void r_uartf0_callback_receiveend(void)
    {
    /* if(enable_frame)
    {
    my_frame_received = 1;
    }
    uart_rx_flag = 1;
    phone_connected = 1;*/

    }
    #endif
    //--------------------------------------------------------------------------------------------------------
    #if 1
    #pragma ghs interrupt
    void INTRLIN32UR1(void)
    {

    INTC2EIRF216 = 0; // clear interrupt flag

    if (g_uartf0_rx_len > g_uartf0_rx_cnt)
    {
    //*gp_uartf0_rx_address = rx_data_8;
    //gp_uartf0_rx_address++;
    my_rx_arr_uart[g_uartf0_rx_cnt] = RLN32.LURDR.UINT8[L];
    g_uartf0_rx_cnt++;

    if (g_uartf0_rx_len == g_uartf0_rx_cnt)
    {
    r_uartf0_callback_receiveend();
    g_uartf0_rx_cnt = 0;
    }
    }
    else
    {

    }
    }
    #endif
    //--------------------------------------------------------------------------------------------------------
    #if 1
    #pragma ghs interrupt
    void INTRLIN32UR2(void)
    {
    uart_err_flag = 1;
    INTC2EIRF215 = 0; // clear interrupt flag
    RLN32LEST = 0x00;
    }
    #endif
    //--------------------------------------------------------------------------------------------------------

    void my_UART2_init(void)
    {

    // P0_2 --> TX
    // P0_3 --> RX

    PORT_AWO.PMC0.UINT16 |= 0x000C;
    PORT_AWO.PM0.UINT16 &= 0xFFFB;
    PORT_AWO.PM0.UINT16 |= 0x0008;


    protected_write(SYSPROTCMDD1, SYSPROTSD1, SYSCKSC_IRLINS_CTL, (uint8_t)0x01); //LIN clock -> 48MHz
    while(SYSCKSC_IRLINS_ACT!=0x01);

    RLN32LUOER = 0x00;
    RLN32LCUC = 0x00; // disable RLIN30


    RLN32LBFC = 0x00; // Tx & RX data are normal polrity, NO Parity, 1 STOP bit, LSB first, 8-bit

    //RLN32.LEDE = 0x0D; // Framing error, Overrun error & bit error detection enabled

    RLN32LWBR = 0xC0; // sampling bit count 13, prescalar 1:1

    //RLN32.LBRP01.UINT16 = 3; // for 921600 bps
    RLN30.LBRP01.UINT16 = 31; // Baudrate = (LIN30 CLK * Prescalar) / (BRP value + 1)/(sample bit count)
    // 48MHZ/((31+1)*13)= 115200 baud
    RLN32LMD = 0x01; // 0x01 UART mode selected, Noise filter is enabled
    // 0x21 UART mode, noise filter disabled

    //RLN32.LDFC = 0x01; // only for testimg

    RLN32LCUC = 0x01; // cancel LIN reset mode
    while(RLN32LMST==0); // wait until LIN reset mode is cancelled

    //RLN32.LUOER = 0x03; // Enable Transmission & Reception

    //----------------------------------------------------------------------

    // Transmission interrupt configuration
    INTC2EITB217 = 1; // 0--> Direct jump method
    // 1--> Vector table
    INTC2EIP217 = 0; // highest priority


    // Reception interrupt configuration
    INTC2EITB216 = 1; // 0--> Direct jump method
    // 1--> Vector table
    INTC2EIP216 = 0; // highest priority


    // Status interrupt configuration
    INTC2EITB215 = 1; // 0--> Direct jump method
    // 1--> Vector table
    INTC2EIP215 = 0; // highest priority

    //-------------------- RLIN3 related --------------------------------------------------------
    /*
    R_DEV_ClkSelection(my_rlin3_ClkSelectionCfg);

    R_DEV_PinInit(my_rlin3_PinConfig);

    my_rlin3_config.Parity = R_RLIN3_NONE_PARITY;
    my_rlin3_config.Stopbit = R_RLIN3_ONE_STOPBIT;
    my_rlin3_config.Direction = R_RLIN3_LSB_FIRST;
    my_rlin3_config.Baudrate = 19200;
    my_rlin3_config.CharLength = R_RLIN3_CHARLEN_8BIT;
    my_rlin3_config.Detection = R_RLIN3_DET_BIT_ERROR | R_RLIN3_DET_BIT_OVR | R_RLIN3_DET_BIT_FRAMING;
    my_rlin3_config.TxDataLevel = R_RLIN3_TDL_NOT_INVERTED;
    my_rlin3_config.RxDataLevel = R_RLIN3_RDL_NOT_INVERTED;
    my_rlin3_config.TxEnable = R_RLIN3_TX_ENABLED;
    my_rlin3_config.RxEnable = R_RLIN3_RX_ENABLED;


    my_rlin3_err = R_RLIN3_Init(RLIN3_UNIT, &my_rlin3_config);
    if(my_rlin3_err != R_RLIN3_ERR_OK)
    {
    while(1);
    }
    */

    //---------------------------- Interrupt config ------------------------------------------
    #if 0
    my_rlin3_err = R_RLIN3_SetIsrCallback(RLIN3_UNIT,R_RLIN3_INT_RX, &my_rlin30_rx_isr);
    if(my_rlin3_err != R_RLIN3_ERR_OK)
    {
    while(1);
    }
    my_rlin3_err = R_RLIN3_SetIsrCallback(RLIN3_UNIT,R_RLIN3_INT_TX, &my_rlin30_tx_isr);
    if(my_rlin3_err != R_RLIN3_ERR_OK)
    {
    while(1);
    }
    my_rlin3_err = R_RLIN3_SetIsrCallback(RLIN3_UNIT,R_RLIN3_INT_RE, &my_rlin30_error_isr);
    if(my_rlin3_err != R_RLIN3_ERR_OK)
    {
    while(1);
    }
    R_RLIN3_EnableInt(RLIN3_UNIT,R_RLIN3_INT_RX);
    R_RLIN3_EnableInt(RLIN3_UNIT,R_RLIN3_INT_TX);
    R_RLIN3_EnableInt(RLIN3_UNIT,R_RLIN3_INT_RE);
    #endif

    }
    //--------------------------------------------------------------------------------------------------------

    void my_UART2_start(void)
    {
    // enable tranmission interrupt
    INTC2EIRF217 = 0; // clear interrupt flag
    INTC2EIMK217 = 0; // enable interrupt

    // enable reception interrupt
    INTC2EIRF216 = 0; // clear interrupt flag
    INTC2EIMK216 = 0; // enable interrupt

    // enable status interrupt
    INTC2EIRF215 = 0; // clear interrupt flag
    INTC2EIMK215 = 0; // enable interrupt

    RLN32LUOER = 0x03; // Enable Transmission & Reception

    g_uartf0_rx_len = 2;

    }

    //--------------------------------------------------------------------------------------------------------

    void my_UART2_stop(void)
    {
    // disable tranmission interrupt
    INTC2EIRF217 = 0; // clear interrupt flag
    INTC2EIMK217 = 1; // disable interrupt

    // disable reception interrupt
    INTC2EIRF216 = 0; // clear interrupt flag
    INTC2EIMK216 = 1; // disable interrupt

    // disable status interrupt
    INTC2EIRF215 = 0; // clear interrupt flag
    INTC2EIMK215 = 1; // disable interrupt

    RLN32LUOER = 0x00; // Enable Transmission & Reception
    }
    //--------------------------------------------------------------------------------------------------------


    void my_UART2_Send_String( unsigned char *buffer)
    {
    unsigned char i;

    for ( i = 0; buffer[i] != 0; i++ )
    {
    my_UART2_send_byte(buffer[i]);
    }
    }
    // To receive one byte.
    uint8_t UART_Receive_Byte(void)
    {
    while (!(RLN32LEST & (1 << 1))); // Check reception status , wait till the data is received.

    return (uint8_t)(RLN32LURDR); // read the data from receive data register.
    }

    // To receive a string.
    void UART_Receive_String(char *buffer, uint32_t max_length)
    {
    uint32_t index = 0;
    char received_char;

    while (index < max_length - 1) // one space for null character
    {
    received_char = UART_ReceiveByte(); // Receive a character
    if (received_char == '\n' || received_char == '\r') // End of string
    {
    break;
    }
    buffer[index++] = received_char; // Store received character
    }
    buffer[index] = '\0'; // Null-terminate the string
    }

    I have done this UART driver for RH850/D1M1 R7F701441 but it is not working 

    i am not receiving proper data, i am using GHS IDE to debug my driver but am unable to receive the data in the dock light

    Parents Reply Children
    No Data