cancel
Showing results for 
Search instead for 
Did you mean: 

M24C04-EEPROM CHIP

SRAM.11
Associate III

Hi people,

 I am using M24C04 EEPROM CHIP WHICH OPERATES (1.8 V -5.5 ).

I am checking my prototype,I found some issues.the initialization works ,I2C scan works fine but Iam unable to read or write .Can anyone help me to find what is wrong  please

 

 

 

uint8_t writeData = 0xAB; // Data to write
  uint8_t readData = 0; // Variable to store read data
  uint32_t address = 0x50; // Target address

  uint8_t write_data=0;
  uint8_t  read_data=0;
  uint16_t i=1;
int chip_ok=0;

uint16_t check_ok=0;

//   FUNCTION  FOR      CHECKING I2C SCAN    ///
void I2C_Scan()
{
 check_ok=0;
	for(i = 0; i < 128; i++)
	{ if (HAL_I2C_IsDeviceReady(&hi2c1, i << 1, 10, 100) == HAL_OK)
		{
		check_ok=1;
		}
	}
}
//     MAIN FUNCTION //
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_TIM3_Init();
  MX_RTC_Init();
  MX_TIM17_Init();
  /* USER CODE BEGIN 2 */


 if(EEPRMA2_M24_Init(EEPRMA2_M24C02_0) == BSP_ERROR_NONE)
  {
	  chip_ok=1;
	 // DOUBLEFLASH();
  }
 else
 {
	 chip_ok=0;
 }

  //do_defaults();

	HAL_TIM_Base_Start_IT(&htim17);
	HAL_Delay(100);
	HAL_ADC_Stop(&hadc1);
	DelayUS(100);
	HAL_ADCEx_Calibration_Start(&hadc1);
	DelayUS(1000);
	HAL_ADC_Start(&hadc1);
	HAL_Delay(100);




  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	
	  I2C_Scan();

	  if (EEPRMA2_M24_WriteByte(EEPRMA2_M24C02_0, &writeData, address) == BSP_ERROR_NONE)
	  {

	  	write_data=1;

	  	if (EEPRMA2_M24_ReadByte(EEPRMA2_M24C02_0, &readData, address) == BSP_ERROR_NONE)
	  	{
	  		read_data=1;
	  	} else
	  	{
	  		read_data=0;
	  	}
	  }
	  else
	  {
	  	write_data=0;
	  }

  }
  /* USER CODE END 3 */
}
//  READ AND WRITE FUNCTION//
int ReadByte(int selectd)
{
	uint8_t readdata = 0;
	EEPRMA2_M24_ReadData(M24_INSTANCE,&readdata,selectd,1);
		return readdata;
}
int ProgramByte(uint16_t location,uint8_t writedata)
{
	EEPRMA2_M24_WriteData(M24_INSTANCE,&writedata,location,1);
	
}

//     HEADER FILE DEFINITION USED  //
#ifndef INC_EEPROM_H_
#define INC_EEPROM_H_


#define M24_INSTANCE EEPRMA2_M24C02_0











int ProgramByte(uint16_t location, uint8_t writedata);
#endif /* INC_EEPROM_H_ */

 

 

 

 

1 REPLY 1
SRAM.11
Associate III

Please help whats wrong