2019-10-14 07:59 AM
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();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_USART3_UART_Init();
/* USER CODE BEGIN 2 */
if(HAL_I2C_IsDeviceReady(&hi2c1,0xD0,5,10)==HAL_OK)
{
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
HAL_Delay(300);
}
unsigned int raw;
float AccX;
/* USER CODE END 2 */
uint8_t i2cdata[4];
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
i2cdata[0]=0x3B;
HAL_I2C_Master_Transmit(&hi2c1,0xD0,i2cdata,1,10);
HAL_Delay(500);
HAL_I2C_Master_Receive(&hi2c1,0xD0,&i2cdata[1],2,10);
raw = (i2cdata[1]<<8|i2cdata[2]);
AccX=((float)raw/16384.0);
HAL_UART_Transmit(&huart2,(unsigned char*)&AccX,5,100);
HAL_Delay(1000);
//HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_5);
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2019-10-14 08:14 AM
Perhaps print the values as ASCII numbers you can read?
Try reading the WHO AM I register, confirm you can do that correctly.
I'd perhaps use the memory read form to pull register content:
uint8_t Value[2]; // XOUT
status = HAL_I2C_Mem_Read(&I2CHandle, 0xD0, 0x3B, I2C_MEMADD_SIZE_8BIT, &Value, 2, 100);
2019-10-14 09:44 AM
Thank you that worked.