Consider this code portion:
...
typedef struct gyro_s
{
int16_t x;
int16_t y;
int16_t z;
} gyro_t;
...
/*
Configuration of:
- Gyroscopes' Full Scale Range.
- Deactivated Sleep Mode
*/
...
int main()
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_I2C2_Init();
MX_USART3_UART_Init();
gyro_t gyro = {0};
int hal_ret = 0;
while (1)
{
hal_ret = HAL_I2C_Mem_Read(&hi2c2, (MPU6050_ADDR << 1) | 0x1, 0x43, 6, (uint8_t *) (&gyro), sizeof(gyro), 1000);
printf("%d %d %d %d %d %ld \n\r", gyro.x, gyro.y, gyro.z, hal_ret, hi2c2.ErrorCode);
HAL_Delay(1000);
}
}
...
So basically, what I'm trying to do is read a bunch of bytes at once from the gyroscope registers of my MPU6050 device located at the address MPU6050_ADDR << 0x1
. The registers start at the address 0x43
and take the amount of 6 bytes that should be stored in the struct gyro_t
.
I preconfigured the gyroscopes' full scale range and deactivated the sleep mode. The individual reading of these registers is done without any issue. I've read something about the BURST READING but I don't seem to understand how to activate it and work with it.
If anyone used to work with the MPU6050 burst read mode and can help it would be much appreciated.
Here is the prototype for HAL_I2C_Mem_Read()
:
HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress,
uint16_t MemAddress, uint16_t MemAddSize,
uint8_t *pData, uint16_t Size, uint32_t Timeout);
The fourth parameter, MemAddSize
, should be the size, in bytes, of the register address that you want to read from. For this device, the address is a single byte. Therefore you should pass 1
(or sizeof(uint8_t)
) for the MemAddSize
parameter.