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 */ }