Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

INA229: INA229 current sensor reading wrong manufacturer ID

Part Number: INA229

I hope you are doing well. I want to use INA229 sensor with the STM324F mcu. My main code section is as below. I am trying to read the manufacturer ID which should be 'TI' as mentioned in the datasheet. However, the value that I read is 42 and 36 in decimal (first byte and second byte, respectively).  My circuit design is given below. 

Thanks in advance.

/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi2;

/* USER CODE BEGIN PV */
uint8_t config = 0x00;
uint16_t config_write = 0xC000;
const uint8_t INA229_DeviceID_address = 0b11111101;
const uint8_t INA229_Current_address = 0b00011101;
const uint8_t INA229_Vshunt_address = 0x11;
const uint8_t INA229_ManufacturerID_address = 0xF9U;

uint32_t INA229_Vshunt_result;
uint16_t INA229_Current_result;
uint8_t ManufacturerID[3];

uint16_t INA229_DeviceID;




/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI2_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_USB_DEVICE_Init();
  MX_SPI2_Init();
  /* USER CODE BEGIN 2 */
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET);
  HAL_SPI_Transmit(&hspi2, (uint8_t *)&config, 1, 100);
  HAL_SPI_Transmit(&hspi2, (uint8_t *)&config_write, 2, 100);
  //HAL_SPI_Receive(&hspi2, (uint8_t *) config, 3, 100);
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);

  while (1)
  {

    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

	  ManufacturerID[0] = 0;
	  ManufacturerID[1] = 0;

	  // SPI Current Value Read
	  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET);
	  HAL_SPI_Transmit(&hspi2, (uint8_t *)&INA229_ManufacturerID_address, 1, 100);
	  HAL_SPI_Receive(&hspi2, (uint8_t *) ManufacturerID, 2, 100);
	  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);
	  // SPI Current Value read finished

	  CDC_Transmit_FS(ManufacturerID, 3);
	  //HAL_Delay(100);

  }
  /* USER CODE END 3 */
}

  • Hello Nurlan,

    Thank you for using the TI forum. It looks like all the variables you are using for the register addresses are all wrong.  Here are the register addresses from the datasheet:

    Specifically, for the manufacturer id register, you have 0xF9U, but it should be 0x3E.  The other variables you have would also need similar corrections.

  • The name of INA229_ManufacturerID_address is a bit unfortunate, should be INA229_ManufacturerID_read_command:
      0xf9 == (0x3e << 2) | 0x01
    That is, the code is reading register 0x3e indeed. I guess the SPI mode is wrong. In STM32CubeIDE, configure
      Clock Polarity (CPOL): Low
      Clock Phase (CPHA): 2 Edge

  • Ah, yes, I see what you meant now....  Ya, the INA229 uses SPI MODE 1 (CPOL = 0, CPHA = 1)

  • (I'm not the original poster.) BTW, I had to add a 100 ohms series resistor in the MOSI line to the INA229 or set the speed of the STM32's MOSI pin to "low" to make the INA229 work for me. Otherwise I had interference between MISO and MOSI: some combinations of old value (which is sent by the INA229 while receiving the new value) and new value just didn't work, e.g., it was not possible to change the ADC_CONFIG register directly from FB68h to AFFFh without travlling via 0000h. Hope this helps others who have trouble making an STM32 talk to an INA229.