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]