2017-10-14 01:18 PM
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
Solved! Go to Solution.
2017-10-17 01:15 AM
Thanks KiC.
Fixed writing 0xA2(+1 for reading) instead of 0xA1.
Bye
2017-10-15 02:30 AM
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_SlaveDetectedu8 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 u8u8 Is_EEP_Detected(void)
{ return I2CIO_IsSlaveDetected(EEP_SLAVEADR);}2017-10-15 11:49 PM
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
2017-10-16 02:58 AM
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...
2017-10-17 01:15 AM
Thanks KiC.
Fixed writing 0xA2(+1 for reading) instead of 0xA1.
Bye