cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot get I2C to work

wfd
Associate II

Greetings,

I am trying to read register 0x00 through 0x0F on an I2C enabled Chip (Si4703) I have got the reset set up and working but my I2C is not working as I am unfamiliar with the HAL protocols 

I have created a number of variable pointers to store data

 

 

 

/* USER CODE BEGIN PV */
int16_t *DeviceID_ptr;
int16_t *ChipID_ptr;
int16_t *PowerCFG_ptr;
int16_t *Channel_ptr;
int16_t *SYSConfig1_ptr;
int16_t *SYSConfig2_ptr;
int16_t *ReadChan_ptr;
int16_t *StatusRSSI_ptr;
/* USER CODE END PV */

 

 

 

Fruther on in the main loop I am trying to get to read the data at just register 0x00

 

 

 

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

	  buf[0] = DeviceID_ptr;
      /* USER CODE END WHILE */
  	  // pass buffer as a character pointer

  	  //strcpy((char*)buf, "Hello!\r\n");
  	  //HAL_UART_Transmit(&hlpuart1, buf, strlen((char*)buf), HAL_MAX_DELAY);
  	  //HAL_Delay(1000);
  	  // save return values of errors
  	  // transmit I2C values
  	  ret = HAL_I2C_Master_Transmit(&hi2c2, SI4703_ADR, DeviceID_ptr, 1, HAL_MAX_DELAY );
  	  if(ret != HAL_OK){
			  strcpy((char*)buf, "Error_Tx\r\n");
		  }
  	  else
  	  {
  		ret = HAL_I2C_Master_Receive(&hi2c2, SI4703_ADR, DeviceID_ptr, 2, HAL_MAX_DELAY );
  		if(ret != HAL_OK){
  		  	 strcpy((char*)buf, "Error_Tx\r\n");
  		}

  	  }

 

 

 

I am getting a lot of very weird errors I think my pointers are screwed up
Thanks for your help
W Dussault
University of Wisconsin Milwaukee
1 ACCEPTED SOLUTION

Accepted Solutions
Foued_KH
ST Employee

Hello @wfd , 

It's recommended to use the HAL_I2C_Mem_Read() function

HAL_I2C_Mem_Read(&hi2c1, uint16_t DevAddress , uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData , uint16_t Size, 1uint32_t Timeout);
  • uint16_t DevAddress: The 7-bit slave device address.

  • uint16_t MemAddress: The memory address to read from on the slave device. This can be a 16-bit value if the slave device supports 16-bit addressing.

  • uint16_t MemAddSize: The size of the memory address. This can be either I2C_MEMADD_SIZE_8BIT or I2C_MEMADD_SIZE_16BIT.

  • uint8_t *pData: A pointer to the buffer where the read data will be stored.

  • uint16_t Size: The number of bytes to read from the slave device.

  • uint32_t Timeout: The timeout value in milliseconds.

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
Foued_KH
ST Employee

Hello @wfd , 

It's recommended to use the HAL_I2C_Mem_Read() function

HAL_I2C_Mem_Read(&hi2c1, uint16_t DevAddress , uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData , uint16_t Size, 1uint32_t Timeout);
  • uint16_t DevAddress: The 7-bit slave device address.

  • uint16_t MemAddress: The memory address to read from on the slave device. This can be a 16-bit value if the slave device supports 16-bit addressing.

  • uint16_t MemAddSize: The size of the memory address. This can be either I2C_MEMADD_SIZE_8BIT or I2C_MEMADD_SIZE_16BIT.

  • uint8_t *pData: A pointer to the buffer where the read data will be stored.

  • uint16_t Size: The number of bytes to read from the slave device.

  • uint32_t Timeout: The timeout value in milliseconds.

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.