This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

i2c eeprom with 16bit addressing

Hello everyone, I must to write and read a I2C eeprom like 24c256. I tryed to do it but all the examples with I2C protocol works with 8bit addressing. I tryed to modify mpu6050.c source code (in Nordic\nrf51822\Source\ext_sensors) for use with sd_twi_hardware_master.c without success. I think that the right way is like this code snippet:

 bool ee_mem24c256_register_write(uint16_t register_address, uint8_t value)
{
	  uint8_t w2_data[3];

	  addrH = (int8_t) (register_address>>8);
	  addrL = (int8_t) (register_address&0xFF); 
	
    w2_data[0] = addrH;
    w2_data[1] = addrL;
    w2_data[2] = value; 
	
    return twi_master_transfer(m_device_address, w2_data, 3, TWI_ISSUE_STOP);
 }

bool ee_mem24c256_register_read(uint16_t register_address, uint8_t * destination, uint8_t number_of_bytes)
{
    bool transfer_succeeded;
	
    transfer_succeeded  = twi_master_transfer(m_device_address, (uint8_t *) &register_address, 1, TWI_DONT_ISSUE_STOP);
    transfer_succeeded &= twi_master_transfer(m_device_address|TWI_READ_BIT, destination, number_of_bytes, TWI_ISSUE_STOP);
    return transfer_succeeded;
}

but doesn't works...

Can you help me?

Parents
  • Good morning to all, it is true that "the night brings advice." I solved the problem and I placed below the correct snippet code:

    bool ee_mem24c256_register_read(uint16_t register_address, uint8_t * destination, uint8_t number_of_bytes)
    {
        bool    transfer_succeeded;
    	  uint8_t w_addr[2];
    
    	  addrH = (int8_t) (register_address>>8);
    	  addrL = (int8_t) (register_address&0xFF); 
    	
        w_addr[0] = addrH;
        w_addr[1] = addrL;
    	
        transfer_succeeded  = twi_master_transfer(m_device_address, w_addr, 2, TWI_DONT_ISSUE_STOP);
        transfer_succeeded &= twi_master_transfer(m_device_address|TWI_READ_BIT, destination, number_of_bytes, TWI_ISSUE_STOP);
        return transfer_succeeded;
    }
    

    I hope this can serve .... to all developers CIAO.

Reply
  • Good morning to all, it is true that "the night brings advice." I solved the problem and I placed below the correct snippet code:

    bool ee_mem24c256_register_read(uint16_t register_address, uint8_t * destination, uint8_t number_of_bytes)
    {
        bool    transfer_succeeded;
    	  uint8_t w_addr[2];
    
    	  addrH = (int8_t) (register_address>>8);
    	  addrL = (int8_t) (register_address&0xFF); 
    	
        w_addr[0] = addrH;
        w_addr[1] = addrL;
    	
        transfer_succeeded  = twi_master_transfer(m_device_address, w_addr, 2, TWI_DONT_ISSUE_STOP);
        transfer_succeeded &= twi_master_transfer(m_device_address|TWI_READ_BIT, destination, number_of_bytes, TWI_ISSUE_STOP);
        return transfer_succeeded;
    }
    

    I hope this can serve .... to all developers CIAO.

Children
No Data
Related