2023-04-13 09:59 PM
I am trying to transmit variables via the uart2 serial port from GY-521(mpu6050) library, however, all my attempts are unsuccessful.
typedef init in the main.c:
MPU6050_t sensor_data;
main.c area to put HAL_UART_Transmit():
while (1)
{
MPU6050_Read_All(&hi2c1, &sensor_data);
HAL_Delay(100);
}
.h needed structure variables to transmit into serial port:
typedef struct
{
int16_t Accel_X_RAW;
int16_t Accel_Y_RAW;
int16_t Accel_Z_RAW;
double Ax;
double Ay;
double Az;
int16_t Gyro_X_RAW;
int16_t Gyro_Y_RAW;
int16_t Gyro_Z_RAW;
double Gx;
double Gy;
double Gz;
float Temperature;
double KalmanAngleX;
double KalmanAngleY;
} MPU6050_t;
2023-04-13 10:21 PM
It will send as a binary blob, not ASCII formatted nor synchronized.
Cast a pointer to the structure, and use sizeof() to determine length to send
2023-04-13 10:27 PM
In the form HAL_UART_Transmit(&hUart2, (uint8_t *)&sensor_data, sizeof(sensor_data), 1000);
Unsuccessful how exactly? The MCU doesn't physically send the data structure, or you can't interpret or process it on the host system?
2023-04-14 01:22 PM
In the function MPU6050_Read_All, all you need to do is to read the 14 bytes as raw values. Send those 14 bytes over UART to the receiving device. Then the device can calculate the raw values into double or float values using the same calculations that the MPU6050_Read_All function has in it.