cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with write and read FT24C16A with STM32F103C8T6

Indu
Associate II

Hello everyone

So I'm trying to read and write 64 byte long list from FT24C16A. I'm using STM32F103C8T6. So first picture displays I2C init for uC. Not problem here. I'm using 3.3 V.

//---I2C_init---//
static void MX_I2C1_Init(void)
{
 
  /* USER CODE BEGIN I2C1_Init 0 */
 
  /* USER CODE END I2C1_Init 0 */
 
  /* USER CODE BEGIN I2C1_Init 1 */
 
  /* USER CODE END I2C1_Init 1 */
  hi2c1.Instance = I2C1;
  hi2c1.Init.ClockSpeed = 400000;
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c1.Init.OwnAddress1 = 0;
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c1.Init.OwnAddress2 = 0;
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
  {
	  HAL_UART_Transmit(&huart3,"HAL_I2C_Init: ",14,0xFFFF);
	  HAL_UART_Transmit(&huart3,"HAL_ERROR",9,0xFFFF);
	  HAL_UART_Transmit(&huart3,"\r\n",2,0xFFFF);
	  //Error_Handler();
  }
  else
  {
	  HAL_UART_Transmit(&huart3,"HAL_I2C_Init: ",14,0xFFFF);
	  HAL_UART_Transmit(&huart3,"HAL_OK",6,0xFFFF);
	  HAL_UART_Transmit(&huart3,"\r\n",2,0xFFFF);
  }
  /* USER CODE BEGIN I2C1_Init 2 */
 
  /* USER CODE END I2C1_Init 2 */
 
}

So, I wrote simple code to test write and read sequence between uC and EXT_EEPROM FT24C16A.

 //---Check_external_memory_status---//
  BJ_FT24C16A_MEM_Status(&hi2c1);
  HAL_Delay(1);
  
  //---Write_list---//
  BJ_FT24C16A_Write_Byte(&hi2c1,"0hello there, This is a test",28,1);
  HAL_Delay(10);
  
  //---Set_address_for_read---//
  BJ_FT24C16A_Write_Byte(&hi2c1,(uint8_t *)User_array_value2,1, 1);
  
  //---Read_data_from_EXT_EEPROM---//
  BJ_FT24C16A_Read_Byte(&hi2c1,(uint8_t *)User_Buffer,27);
  
  //---Transmit_data_to_PC---//
  HAL_UART_Transmit(&huart3,(uint8_t *)User_Buffer,27,0xFFFF);

Code in line 2. will check if FT24C16A is present. It will return TRUE for ok.

Code in line 6. will send simple sentence to write in EEPROM. You will see that the first byte is '0'(hex 0x30), which for FT24C16 will be start address for write sequence.

Then with 10ms delay, uC will send byte (0x30) to set read address. Code in line 10.

For read, code in line 13 is used. After stop reading data from EEPROM FT24C16A, the data in buffer "User_Buffer" is send trough UART to PC.

The problem is, reading same send data to EEPROM. I send "0hello there, This is a test" but I read back this "0693W000001pL90QAE.jpg

I also check this with logic analyses. It's same: 0693W000001pL9FQAU.png

And I check SCL, SDA and power 3.3 Vpp ripple. Its all in good. I also try with 100kHz speed. Same result.

Here are my functions for read and write sequence.

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
/////////////////////////////////////////////////////////////////////////////////////
//------------------------------Write_data_in_FT24C16A-----------------------------//
//------------------------------Write_data_single_byte-----------------------------//
void BJ_FT24C16A_Write_Byte(I2C_HandleTypeDef *hi2c, uint8_t *pData,uint16_t data_count, int stop)
{
//---Send_data_to_EXT_memory---//
EXT_Memory_Variable.Status_Write_Flag_MEM_FT24C16A = HAL_I2C_Master_Transmit(hi2c,(uint16_t) FT24C16A_WRITE_ADDRESS,(uint8_t *)pData,(uint16_t) data_count,(uint32_t) 0xFFFF, stop);
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
/////////////////////////////////////////////////////////////////////////////////////
//------------------------------Read_data_in_FT24C16A------------------------------//
//-------------------------------Read_data_single_byte-----------------------------//
void BJ_FT24C16A_Read_Byte(I2C_HandleTypeDef *hi2c, uint8_t *pData,uint16_t data_count)
{
//---Send_data_to_EXT_memory---//
EXT_Memory_Variable.Status_Read_Flag_MEM_FT24C16A = HAL_I2C_Master_Receive(hi2c,(uint16_t) FT24C16A_READ_ADDRESS,(uint8_t *)pData,(uint16_t) data_count,(uint32_t) 0xFFFF);
}

But funny is, when I send just "0hello there", a get correct sentence back.

0693W000001pL9oQAE.jpg

Only when I send more that 16 bytes to EEPROM, I do not get correct sentence back from it.

So, what can I do here. Am I sending or reading data in wrong sequence.

Regards

1 ACCEPTED SOLUTION

Accepted Solutions

>>Only when I send more that 16 bytes to EEPROM, I do not get correct sentence back from it. So, what can I do here. Am I sending or reading data in wrong sequence.

Surprisingly the Data Sheet does address the 16-byte issue/wrap

https://datasheet.lcsc.com/szlcsc/Fremont-Micro-Devices-FT24C16A-ELR-T_C232875.pdf

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

>>Only when I send more that 16 bytes to EEPROM, I do not get correct sentence back from it. So, what can I do here. Am I sending or reading data in wrong sequence.

Surprisingly the Data Sheet does address the 16-byte issue/wrap

https://datasheet.lcsc.com/szlcsc/Fremont-Micro-Devices-FT24C16A-ELR-T_C232875.pdf

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Ok, I understand now. :)