This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

FPB-RA2E1 - I2C Slave is not working

Hi,

I am using the FPB-RA2E1 prototyping board as an I2C slave.

The open and read operations run successfully without any errors. However, the FPB-RA2E1 is not responding to the master's requests, nor am I receiving any callbacks.

Could you please check the following configuration and code.

I2c.c

#include "i2c.h"
#include <stdio.h>

// Receive buffer
static uint8_t g_slave_rx_buffer[I2C_SLAVE_RX_BUFFER_SIZE];
#define I2C_SLAVE_CHANNEL_0 0
#define I2C_7BIT_ADDR_IIC_SLAVE 0x48
int var = 0;


iic_slave_instance_ctrl_t g_i2c_slave_ctrl;
i2c_slave_cfg_t           g_i2c_slave_cfg =
{
    .channel    = I2C_SLAVE_CHANNEL_0,
    .rate       = I2C_SLAVE_RATE_STANDARD,
    .slave      = I2C_7BIT_ADDR_IIC_SLAVE,
    .addr_mode  = I2C_SLAVE_ADDR_MODE_7BIT,
    .p_callback = i2c_slave_callback,  // Callback
    .p_context  = &g_i2c_slave_ctrl,
//    .p_extend   = NULL
};
static uint8_t rx_data[DATA_LEN] = {RESET_VAL};

i2c_slave_event_t g_i2c_slave_callback_event;

void i2c_slave_callback(i2c_slave_callback_args_t *p_args)
{
    fsp_err_t err;
    var++;

    if ((p_args->event == I2C_SLAVE_EVENT_RX_COMPLETE) || (p_args->event == I2C_SLAVE_EVENT_TX_COMPLETE))
    {
        /* Transaction Successful */
    }
    else if ((p_args->event == I2C_SLAVE_EVENT_RX_REQUEST) || (p_args->event == I2C_SLAVE_EVENT_RX_MORE_REQUEST))
    {
        /* Read from Master */
        err = R_IIC_SLAVE_Read(&g_i2c_slave_ctrl, g_slave_rx_buffer, I2C_SLAVE_RX_BUFFER_SIZE);
        assert(FSP_SUCCESS == err);
    }
    else if ((p_args->event == I2C_SLAVE_EVENT_TX_REQUEST) || (p_args->event == I2C_SLAVE_EVENT_TX_MORE_REQUEST))
    {
        /* Write to master */
        err = R_IIC_SLAVE_Write(&g_i2c_slave_ctrl, g_slave_rx_buffer, I2C_SLAVE_RX_BUFFER_SIZE);
        assert(FSP_SUCCESS == err);
    }
    else
    {
        /* Error Event - reported through g_i2c_slave_callback_event */
    }
}

void i2c_slave_init(void)
{

    // Open the I2C slave driver
    fsp_err_t err = R_IIC_SLAVE_Open(&g_i2c_slave_ctrl, &g_i2c_slave_cfg);
    assert(FSP_SUCCESS == err);

    // Enable the I2C slave to receive data
     err = R_IIC_SLAVE_Read(&g_i2c_slave_ctrl, g_slave_rx_buffer, I2C_SLAVE_RX_BUFFER_SIZE);
     if (FSP_SUCCESS != err)
     {
         printf("I2C Slave Read Error: %d\n", err);
     }
     printf("I2C Slave Init done\n");


}

hal_entry.c

/*******************************************************************************************************************//**
 * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used.  This function
 * is called by main() when no RTOS is used.
 **********************************************************************************************************************/
void hal_entry(void)
{
    /* TODO: add your own code here */
    i2c_slave_init();

    while (1)
    {
        ;
    }

#if BSP_TZ_SECURE_BUILD
    /* Enter non-secure code */
    R_BSP_NonSecureEnter();
#endif

}

Please let me know, where I am missing something.




[locked by: GN_Renesas at 9:44 (GMT 0) on 2 Sep 2024]
  • Hi Ramesh,

    Thank you for reaching out about your issue. I’ve shared a sample code for slave write and read operations that has been tested with the master and is working correctly. Please refer to that.

    Best regards,

    Gaurav N

    ekra2e1_slave_write.zip

    ra2e1slaveread.zip

  • Hi Gaurav N,

    Thank you for your response. The code works for the devkit, but I’m having issues with my custom board from the same family (R7FA2E1A72DFJ). I’ve updated the necessary pins and board name in your project, but it’s still not working.

    Any suggestions would be appreciated.

    Regards,

    Ramesh

  • Hey Ramesh,

    Can you please kindly share schematic of custom board and the pins your using . and also make sure your selecting correct part number in below . and also suggest you to check on logic analyzer .

  • Hi Gaurav N / GN_Renesas,

    I was facing an issue related to the hardware where SDA and SCL lines are swapped on the PCB now it got resolved.

    But I2C master is consistently showing a successful write, but on the Renesas I2C slave side, I only observe one callback. After resetting the Renesas device, I receive the first callback, but no continuous data is received.

    Could you please advise if I might be missing something?

    Regards,

    Ramesh

  • Hi Ramesh,

    Did you use pull-up resistors, and if so, what values did you choose? Also, is there a possibility that the internal pull-ups on the SDA and SCL pins are active along with an external pull-up? To help us verify your schematics, could you please create a ticket in our private ticketing system, Team Support, at https://en-support.renesas.com/createticket and share your schematics there?

    Regards,

    GN_Renesas.