cancel
Showing results for 
Search instead for 
Did you mean: 

M95M02 SPI based EEPROM Read and Write issue.

pankaj kyada
Associate II
Posted on November 17, 2017 at 05:53

i am facing the write and read issue in M95M02 EEPROM, i am follow the read write cycle as per data sheet.

but not write and read in EEPROM.

MCU: STM32F105RB.

my read write algorithm in below.

/************************************WRITE Algorithm******************************/

/**

  * @brief  Transmit a byte of data in blocking mode.

  * @param  addr: Data addresh

  * @param  ptr_dat: Pointer to data buffer

  * @retval HAL status

  */

HAL_StatusTypeDef EEPROM_Byte_Write(uint8_t *ptr_dat, uint32_t addr)

{

  HAL_StatusTypeDef status = HAL_OK;

  uint8_t temp = 0x00, *ptr_temp = '\0';

 

  /* Send Write Enable Command */

  CHIP_SEL_RESET();       // Chip select Low

  temp = (uint8_t)WREN;

  HAL_SPI_Transmit(&hspi1, &temp, 1, 10);

  HAL_Delay(10);

  CHIP_SEL_SET();         // Chip select High

 

  /* Send Write To Memory Array Command */

  CHIP_SEL_RESET();       // Chip select Low

  temp = (uint8_t)WR;

  HAL_SPI_Transmit(&hspi1, &temp, 1, 10);        

   

  /* EEPROM 24 Bit Addresh Send */    

  ptr_temp = (uint8_t *)&addr;  

  HAL_SPI_Transmit(&hspi1, ptr_temp, 3, 10);            

   

  /* Sending One Byte In EEPROM */

  status = HAL_SPI_Transmit(&hspi1, ptr_dat, 1, 10);

 

  /* Send Write Disable Command */

  temp = (uint8_t)WRDI;

  HAL_SPI_Transmit(&hspi1, &temp, 1, 10);

 

  CHIP_SEL_SET();         // Chip select High    

 

  return status;

}

/*************************************************************************************/

/************************************READ Algorithm*******************************/

/**

  * @brief  Receive a byte of data in blocking mode.

  * @param  addr: Data addresh

  * @param  ptr_dat: Pointer to data buffer

  * @retval HAL status

  */

HAL_StatusTypeDef EEPROM_Byte_Read(uint8_t *ptr_dat, uint32_t addr)

{

  HAL_StatusTypeDef status = HAL_OK;

  uint8_t temp = 0x00, *ptr_temp = '\0';

    

  /* Send Read To Memory Array Command */

  CHIP_SEL_RESET();       // Chip select Low                                          

  HAL_Delay(10);                                          

  temp = (uint8_t)RD;

  HAL_SPI_Transmit(&hspi1, &temp, 1, 10);

 

  /* EEPROM 24 Bit Addresh Send */    

  ptr_temp = (uint8_t *)&addr;  

  HAL_SPI_Transmit(&hspi1, ptr_temp, 3, 10);

 

  /* Receving One Byte From EEPROM */

  status = HAL_SPI_Receive(&hspi1, ptr_dat, 1, 50);  

  CHIP_SEL_SET();         // Chip select High                                             

 

  return status;

}

/*************************************************************************************/

1 REPLY 1
S.Ma
Principal
Posted on November 17, 2017 at 07:27

Quick guess (no time to browse the spec) : after you finish writing, let NSS goes up, wait 10 msec, disable write protect, then read (verify).