cancel
Showing results for 
Search instead for 
Did you mean: 

I2C EEPROM TO WRITE AD DATA USING STM32F103C8T6 MCU

mrsmile
Associate III

Hello, 

   I am try to write the data for memory address in EEPROM using standard protocol I2C. we are trying in data write to memory Address and Driver IC read to operates the Sensorless BLDC motor. so I am working in this method. But am put in the data's for properly in the function but address was can't write properly. I attach my output waveformScreenshot (63).png.

/* USER CODE BEGIN PV */
uint8_t EE_buff[5]= {0x03,0x50};   // REG_ADD - 0X03 EECTRL , SIdata, eewrite
uint8_t DEV_BUFF[5]= {0x02,0xB6};  // REG_ADD - 0x02 devctrl, enprogkey
uint8_t phres_buff[5]= {0x20,0x39};  // REG_ADD - 0x20 motorparameter 1, phase resistance
uint8_t IS_buff[5]= {0xCF};   // REG_ADD - 0x23 ISDEN, ISDThr, rvsdren, rvsdrthr
uint8_t IPD_buff[5]= {0xF0};  // REG_ADD - 0x2A IPD_EN  IPDCURTHR[]
uint8_t OPL2_buff[5]= {0xF8}; // REG_ADD - 0x26 OPENL2CLS_THr
uint8_t Oplcur_buff[5]= {0xC0};
 
uint8_t ana_buff[5]= {0x02};  // ADD - 0x2B Analog_mode speed pin
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_I2C1_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
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_I2C1_Init();
  /* USER CODE BEGIN 2 */
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
HAL_I2C_Mem_Write(&hi2c1, 0XA4, 0x02, 2, DEV_BUFF, 2, 10);  
 
HAL_I2C_Mem_Write(&hi2c1, 0XA4, 0x03, 2, EE_buff, 2, 10);
 
HAL_I2C_Mem_Write(&hi2c1, 0XA4, 0x20, 2, phres_buff, 2, 10);
}
 
I am programmed this format to write the data. Am I attach need a output data format. I made  by mistake please correct me. How can I write the data for I2C EEPROM in the address.42544sg.PNG.
2 REPLIES 2
Bob S
Principal

1 - You do not need to include the address in your data arrays (EE_buf, DEV_BUF, etc.), just put the data there.  And if each write operation is only 1 (data) byte, you don't need arrays to store them in.

2 - You HAL_I2C_Mem_Write() is incorrect.  You correctly pass the register address, but the next param (the 4th parameter in the function call) is the SIZE of the address.  You pass "2" which HAL interprets to mean "send the address as a 16-bit value" (see the I2C_MEMADD_SIZE_8BIT and I2C_MEMADD_SIZE_16BIT).  You should be passing "I2C_MEMADD_SIZE_8BIT" (or if you insist on poor programming style, "1").

Might help to communicate which part you are using in each post. DRV10983 from prior one

https://www.ti.com/lit/ds/slvscp6h/slvscp6h.pdf?ts=1687761058949

The Register address space is 8-bit wide, registers 0x20 - 0x2B being EEPROM, and having default values you could likely read back and confirm.

// Something with some semblence of diagrammed pattern
uint8_t reg20 = 0x39;
HAL_I2C_Mem_Write(&hi2c1, 0xA4, 0x20, I2C_MEMADD_SIZE_8BIT, &reg20, sizeof(reg20), 10);  
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..