Skip to main content
passafabio2
Associate II
October 14, 2017
Solved

I2C_TransferHandling() for 24c04 A8 set in select devices

  • October 14, 2017
  • 4 replies
  • 1540 views
Posted on October 14, 2017 at 22:18

How to manage: I2C_TransferHandling() for accessing high sector (>255 bit) of a 24c04 eeprom?

In a selecting device I'm not capable to modify 0xA0 to 0xA1 for settings A8=1 and access to 256..512 bytes of eeprom.

I'm using stm32f051 and fwlib 1.0.0.

I know is an old firmware library but I need to manage an old board with added a eeprom memory.

Thanks

Fabio

    This topic has been closed for replies.
    Best answer by passafabio2
    Posted on October 17, 2017 at 08:15

    Thanks KiC.

    Fixed writing 0xA2(+1 for reading) instead of 0xA1.

    Bye

    4 replies

    S.Ma
    Principal
    October 15, 2017
    Posted on October 15, 2017 at 11:30

    The slave address should not be a constant, it should be defined as global variable, predefined with 0xA0, when passing the eeprom 9 bit address, crop the most significant bit and adjust the slave address bit before calling the function. 2404=4 kbit = 512 bytes = 9 bit address, 1 msb put within the slave address.

    //#define EEP_24C256 //#define EEP_24C08

    #define EEP_24512

    #ifdef EEP_24512

    #define EEPSIZE 480 // last 1024 bytes will be in fact the MCU internal 1 kb EEPROM. 61440 bytes external (60kb)

    #define EEPPAGESIZE 32 // up to 128 is possible

    //#define EEP_SLAVEADR 0xAE

    //#define EEP_SLAVEADR 0xAC // hybrid FROG on board EEPROM

    #define EEP_SLAVEADR 0xA2 // Draco STM8L on board EEPROM

    #endif

    #ifdef EEP_24C256

    #define EEPSIZE 256

    #define EEPPAGESIZE 32

    #define EEP_SLAVEADR 0xA0

    #endif

    #ifdef EEP_24C08

    #define EEPSIZE 8

    #define EEPPAGESIZE 16

    #define EEP_SLAVEADR 0xA0

    #endif

    #ifdef EEP_24C16

    #define EEPSIZE 16

    #define EEPPAGESIZE 16

    #define EEP_SLAVEADR 0xA0

    #endif

    #define I2C_Start I2CIO_Start

    #define I2C_Stop I2CIO_Stop

    #define I2C_ReadByte I2CIO_Receive

    #define I2C_SendByte I2CIO_Transmit

    #define I2C_SlaveDetected I2CIO_SlaveDetected

    u8 I2C_Errors;

    // Eeprom size in kilobit (64kBit = 24C64 = 4kbyte), its physical page write size, and its sub address

    // These define the used EEPROM (SubAdr may be used for 24C16 encoding sub adress MSBs in Slave Address LSBs

    #ifdef EEP_24512

    #define EEP_WRITE(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR);I2C_SendByte(SubAdr>>8);I2C_SendByte(SubAdr);

    #define EEP_READ(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR | 0x01 )

    #endif

    #ifdef EEP_24C256

    #define EEP_WRITE(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR & 0xFE);I2C_SendByte(SubAdr>>8);I2C_SendByte(SubAdr);

    #define EEP_READ(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR | 0x01)

    #endif

    #ifdef EEP_24C08

    #define EEP_WRITE(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR & 0xFE);I2C_SendByte(SubAdr&0x00FF);

    //#define EEP_WRITE(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR & 0xFE /*| ((SubAdr>>7)&0x06))*/;I2C_SendByte(SubAdr&0x00FF);

    #define EEP_READ(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR | 0x01)

    //#define EEP_READ(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR /*| ((SubAdr>>7)&0x06)*/ | 0x01)

    #endif

    #ifdef EEP_24C16

    #define EEP_WRITE(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR | ((SubAdr>>7)&0x0E));I2C_SendByte(SubAdr);

    #define EEP_READ(SubAdr) I2C_Errors = I2C_Start(EEP_SLAVEADR | ((SubAdr>>7)&0x0E) | 0x01)

    #endif

    #define BLANKBYTE 0xFF

    #define EEP_MAXWRITETIME_MS 16

    // This define any mcu IO controlling WE signal for better protection

    #define WE_ENABLE //PADDR.BIT.6 = 1;PADR.BIT.6 = 1;Delay_ms(1)

    #define WE_DISABLE //PADDR.BIT.6 = 1;PADR.BIT.6 = 0

    // This define the number of retrials in case of communication errors

    #define NB_OF_RETRIALS 0

    // The EEPROM memory check results

    #define EEP_OK 0

    #define EEP_NOACK 0x01

    #define EEP_BLANK 0x02

    // adapted for this project

    //#define Delay_ms(x) Wait_us( (x)*1000L )

    #define BOOL u8

    u8 Is_EEP_Detected(void)

    {

    return I2CIO_IsSlaveDetected(EEP_SLAVEADR);

    }
    passafabio2
    Associate II
    October 16, 2017
    Posted on October 16, 2017 at 08:49

    void I2C_TransferHandling(I2C_TypeDef* I2Cx, uint16_t Address, uint8_t Number_Bytes, uint32_t ReloadEndMode, uint32_t StartStopMode)

    Is a ruotines inside STM32F0xx_1_2c.c file, in STM32F0xx_StdPeriph_Lib_V1.X.X file, downloaded from st web site.

    I try to force  uint16_t Address in I2C_TransferHandling() with 0xA1 instead of 0xA0 declared in Init structure but the oscilloscope show me always 0xA0...

    Any example/info to manage this ?

    Thanks Fabio

    S.Ma
    Principal
    October 16, 2017
    Posted on October 16, 2017 at 09:58

    If it is A0 for write, it's A1 for read. The extra address bit in this case it A0/A2 for write, A1/A3 for read. 

    Some write the slave address in 7 bit, some do in 8 bit hence the confusion.

    Same issue for UART RX/TX, people screw up because it's not clear if we are talking host or device... and then both wires needs to be crossed to work things out...