Random Address Read eeprom M24256

Hi,

I am trying to read and write eeprom M24256.

I have used smart configuration but I am not able to read data in random address read.

Datasheet related eeprom said:

Random Address Read:

A dummy write is performed to load the address into the address counter. Then, without sending STOP condition, the master sends another START condition, and repeats the Device Select Code, with the RW bit set to 1. The memory acknowledges this, and outputs hte contents of the adressed byte. The master must not acknowledge the byte output, and terminates the transfer with stop condition.

Could you indicate to me how can manage this situation ?

Br,

  • Hi, Thank you for posting on the Renesas community.
    Could you please share your MCU part number and the smart configuration setup of I2C unit? sharing more information about your code also can be beneficial. 

    Regards, 
    Hossein.

    If this or any other user's response answers your concern, kindly verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    en-support.renesas.com/.../

  • To address that kind of communication you need to write customized code based on registers. unfortunately, the prewritten functions and smart configuration setup don't allow for that kind of sequence, as it automatically sends stop and start conditions. and you might get into trouble if modify the smart code generator codes.

    I recommend studying the hardware user's manual and reviewing the "R_Config_SCI1_IIC_Master_Send" and related functions. Rewrite these functions to gain direct control of stop conditions and eliminate automatic stop conditions. 

    meanwhile, if you have questions don't hesitate to reach out here. 
     

    Regards, 
    Hossein.

    If this or any other user's response answers your concern, kindly verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    en-support.renesas.com/.../

  • Hi,

    could you suggest I can modify the code used with smart configuration ?

    Br,

  • Hi,

    what is the correct baudrate that I need to use with M24256 chip.
    It seems slow the wrinting and the reading.

    Now I have 

    /* Set bit rate */

    SCI1.BRR = 0x19U;

    I modified the code inserting  this flag flag_e2read_pippuz and I set it to 1 when I need to write and put it to 0 when I need to read. The other part of the code is the code generated from Smart Configuration.

    The system seems slow.

    Please let me know if I am wrong or not.

     

    void r_Config_SCI1_receive_interrupt(void)

    {

    volatile uint8_t dummy;

    if (0U == SCI1.SISR.BIT.IICACKR)

    {

    if (_80_SCI_IIC_TRANSMISSION == g_sci1_iic_transmit_receive_flag)

    {

    if (g_sci1_tx_count > 0U)

    {

    SCI1.TDR = *gp_sci1_tx_address;

    gp_sci1_tx_address++;

    g_sci1_tx_count--;

    }

    else

    {

    if(flag_e2read_pippuz == 1)

    {

    /* Generate stop condition */

    g_sci1_iic_cycle_flag = _00_SCI_IIC_STOP_CYCLE;

    R_Config_SCI1_IIC_StopCondition();

    }

    }

    }

    else if (_00_SCI_IIC_RECEPTION == g_sci1_iic_transmit_receive_flag)

    {

    if (0U == SCI1.SIMR2.BIT.IICACKT)

    {

    if (g_sci1_rx_length > g_sci1_rx_count)

    {

    *gp_sci1_rx_address = SCI1.RDR;

    gp_sci1_rx_address++;

    g_sci1_rx_count++;

    }

    }

    else

    {

    dummy = SCI1.RDR;

    }

    if (0U == g_sci1_rx_count)

    {

    if(1U == g_sci1_rx_length)

    {

    SCI1.SIMR2.BIT.IICACKT = 1U;

    }

    else

    {

    SCI1.SIMR2.BIT.IICACKT = 0U;

    SCI1.SCR.BIT.RIE = 1U;

    }

    }

    else if (g_sci1_rx_length == (g_sci1_rx_count + 1))

    {

    SCI1.SIMR2.BIT.IICACKT = 1U;

    }

    else

    {

    /* Do nothing */

    }

    /* Write dummy */

    SCI1.TDR = 0xFFU;

    }

    else

    {

    /* Do nothing */

    }

    }

    else

    {

    /* Generate stop condition */

    g_sci1_iic_cycle_flag = _00_SCI_IIC_STOP_CYCLE;

    R_Config_SCI1_IIC_StopCondition();

    }

    }

    Br,

  • Hi, I recommend using 100Kbps, although it supports 400Kbps and 1Mbps. 
    Regarding your code, I found out the SCI unit isn't compatible with your needs, but you can configure the RIIC0 instead of SCI, as it inherently supports restart conditions and has the no_stop send APIs. 

    Thanks for your patience, I'm working on it, and I share that as soon as possible.

  • Dear Lucaodex, I investigated that, and here's the result:
    Please follow the below project and test if it works on M24256. 

    - When adding I2C master mode, use RIIC0 


    -In the "Config_RIIC0_user.c" file,  declare an extern volatile _Bool flag, and make the below changes to the file. 

    -Main.c file: 

    /***********************************************************************
    *
    *  FILE        : RX66N_IIC_EEPROM_Interfacing.c
    *  DATE        : 2024-03-28
    *  DESCRIPTION : Main Program
    *
    *  NOTE:THIS IS A TYPICAL EXAMPLE.
    *
    ***********************************************************************/
    #include "r_smc_entry.h"
    
    //Define the chip's address
    #define E1 0 //E1 pin logic
    #define E2 0 //E2 pin logic
    #define E3 0 //E3 pin logic
    #define B7_4_ADDR 0xA //Memory access address
    
    void M24xx_read_byte_random(uint8_t const device_address,uint16_t* const address, uint8_t* byte_buffer);
    void M24xx_write_byte_random(uint8_t const device_address,uint16_t* const address, uint8_t* const byte_data);
    void main(void);
    
    volatile _Bool IIC_transmission_end;//IIC bus busy state indicator
    
    uint8_t rx_buffer[10];
    uint8_t tx_buffer[10] = {0xAA};
    uint16_t memory_address = 0xFF;//An arbitrary address of the memory
    
    void main(void)
    {
    
    	const uint8_t device_address = (B7_4_ADDR<<3 | E3<<2 | E2<<1 |E1);//Calculate and store the address of the chip
    
    	R_Config_RIIC0_Start();//RIIC0 Initialization
    
        while (1) {
    
            M24xx_write_byte_random(device_address,&memory_address,&tx_buffer[0]);//save a byte to corresponding memory address
            R_BSP_SoftwareDelay(10, BSP_DELAY_MILLISECS);
            M24xx_read_byte_random(device_address,&memory_address,rx_buffer);//Fetch a byte from corresponding memory address
            R_BSP_SoftwareDelay(10, BSP_DELAY_MILLISECS);
    
        }
    }
    
    
    /*
     * Function: read a single byte from an arbitrary address
     * inputs: Device's address ,16bit address of the memory to be read,Function pointer to the data buffer
     * output: nothing
    */
    void M24xx_read_byte_random(uint8_t const device_address,uint16_t* const address, uint8_t* byte_buffer){
    
    	//Divide 16bit address into two bytes
    	uint8_t addr[2];
    	addr[0] = (uint8_t) ((*address) >> 8);
    	addr[1] = *address;
    	IIC_transmission_end = 0;//Reset IIC bus free flag
    	R_Config_RIIC0_Master_Send_Without_Stop(device_address,(uint8_t*)addr, 2);//Send address to chip
    	while(IIC_transmission_end == 0);//Wait for the data to be sent
    
    	IIC_transmission_end = 0;//Reset IIC bus free flag
    	R_Config_RIIC0_Master_Receive(device_address, byte_buffer, 1);//Retrieve the byte from the memory
    	while(IIC_transmission_end == 0);//Wait for the bus to be free
    
    }
    
    /*
     * Function: write a single byte on an arbitrary address
     * inputs: Device address ,16bit address of the memory to be written,Function pointer to the data buffer
     * output: nothing
    */
    void M24xx_write_byte_random(uint8_t const device_address,uint16_t* const address, uint8_t* const byte_data){
    
    	//Combine address and data to be send to the IC
    	uint8_t data[3];
    	data[0] = (uint8_t) ((*address) >> 8);
    	data[1] = *address;
    	data[2] = *byte_data;
    
    	R_Config_RIIC0_Master_Send(device_address,(uint8_t*)data, 3);//Send address and corresponding data to the chip
    
    }
    



    Now you probably can communicate with the chip properly. it obeys the Read/Write Sequence provided by the M24256 datasheet. 
    The 0xAA value will be written to the 0xFF address of the chip, then you should be able to retrieve that data with the Random Read function.

    I hope you'll find it useful. don't hesitate to ask for clarification if you need it. 

    Kind regards, 
    Hossien. 

    If this or any other user's response answers your concern, kindly verify the answer. Thank you!

    Renesas Engineering Community Moderator
    https://community.renesas.com/
    https://academy.renesas.com/
    en-support.renesas.com/.../


     

  • Hi,

    I have this configuration for the RX64M, so I have different pin.
    Can I use your suggestion changing the port or it is not possible ?

     

  • Hi,

    I have changed these conf inside:

    void R_Config_RIIC01_Create(void)

    {

    ....

    /* Set SCL0 pin */

    MPC.P30PFS.BYTE = 0x0FU;

    PORT3.PMR.BYTE |= 0x01U;

    /* Set SDA0 pin */

    MPC.P26PFS.BYTE = 0x0FU;

    PORT2.PMR.BYTE |= 0x40U;

    .....

    }

  • Feel free to switch to another channel of RIIC, and make sure you have signal on them when application is running. I used RX66N on RCII0 but there might not be a problem to switch on RX64N RIIC1. eventually try not edit smart code generator codes as much as possible.