So, I'm trying to read the angle of a motor with this encoder, but I cant seem to get it too comunicate with the STM32 (STM32F401CEU6). It always always gives me the status "HAL_Busy" or it gets stuck on the Error_Handler().
I read the datasheet and the address of the encoder is 0x40, moreover i confirmed that with an arduino (with the arduino worked perfectly, and all the data was displayed). I've tried using this library GitHub - Violin9906/STM32_AS5048B_HAL: AS5048B Library for STM32(HAL) but it always gives me the status "HAL_Busy" or it gets stuck on the Error_Handler()
The code I wrote is identical to the one in the link. My I2C setting are:
void MX_I2C1_Init(void)
{
hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 400000;
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
}
Looking at the arduino code it occurred to me that I might need to initialize the sensor, so i tried this code (which might very well be wrong):
void sensor_init(void) {
HAL_I2C_Master_Transmit_IT(&hi2c1, (0x40 << 1), (uint8_t*) 0x16, 1);
HAL_Delay(10);
}
Can anyone please help? (i know this forum is for arduino but there are a lot of smart people here that may know about this)