Both sensors now run over interrupts in pulse mode. This still needs
tweaking as its buggy but works for now on full speed for both sensors.
This commit is contained in:
+35
-26
@@ -30,6 +30,7 @@
|
||||
#include "bmm350.h"
|
||||
#include "bmm350_defs.h"
|
||||
#include "bmm350_oor.h"
|
||||
#include "task.h"
|
||||
|
||||
// CDC functionality
|
||||
#include "usbd_cdc_if.h"
|
||||
@@ -695,6 +696,10 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIO_MAGN_INT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
@@ -716,8 +721,12 @@ void Start_DataAnalysis(void *argument)
|
||||
/* init code for USB_Device */
|
||||
MX_USB_Device_Init();
|
||||
/* USER CODE BEGIN 5 */
|
||||
|
||||
// TODO: USB/BLE Connection in beide Richtungen (MCU-PC)
|
||||
// TODO: Einstellungen setzbar durch trinity control für IMU, Magnetometer, etc.
|
||||
|
||||
// HAL_StatusTypeDef status;
|
||||
// char output_buffer[128];
|
||||
char output_buffer[128];
|
||||
ICM45686_Data imu_data;
|
||||
struct bmm350_mag_temp_data magn_data;
|
||||
// struct bmm350_raw_mag_data magn_data;
|
||||
@@ -735,12 +744,12 @@ void Start_DataAnalysis(void *argument)
|
||||
osMessageQueueGet(Q_BMMHandle, &magn_data, NULL, osWaitForever);
|
||||
osMessageQueueGet(Q_ICMHandle, &imu_data, NULL, osWaitForever);
|
||||
|
||||
// MadgwickAHRS_update(&IMUQuat, imu_data.processed_imu_data[3], imu_data.processed_imu_data[4], imu_data.processed_imu_data[5], //gx, gy, gz
|
||||
// imu_data.processed_imu_data[0], imu_data.processed_imu_data[1], imu_data.processed_imu_data[2], // ax, ay, yz
|
||||
// magn_data.x, magn_data.y, magn_data.z); // mx, my, mz
|
||||
|
||||
MadgwickAHRS_update_IMU(&IMUQuat, imu_data.processed_imu_data[3], imu_data.processed_imu_data[4], imu_data.processed_imu_data[5], //gx, gy, gz
|
||||
imu_data.processed_imu_data[0], imu_data.processed_imu_data[1], imu_data.processed_imu_data[2]); // ax, ay, yz)
|
||||
MadgwickAHRS_update(&IMUQuat, imu_data.processed_imu_data[3], imu_data.processed_imu_data[4], imu_data.processed_imu_data[5], //gx, gy, gz
|
||||
imu_data.processed_imu_data[0], imu_data.processed_imu_data[1], imu_data.processed_imu_data[2], // ax, ay, yz
|
||||
magn_data.x, magn_data.y, magn_data.z); // mx, my, mz
|
||||
//
|
||||
// MadgwickAHRS_update_IMU(&IMUQuat, imu_data.processed_imu_data[3], imu_data.processed_imu_data[4], imu_data.processed_imu_data[5], //gx, gy, gz
|
||||
// imu_data.processed_imu_data[0], imu_data.processed_imu_data[1], imu_data.processed_imu_data[2]); // ax, ay, yz)
|
||||
|
||||
|
||||
Quat_Dat.qw = IMUQuat.q[0];
|
||||
@@ -761,8 +770,8 @@ void Start_DataAnalysis(void *argument)
|
||||
// sprintf(output_buffer, "ICM:\ta_x: %.2f a_y: %.2f a_z: %.2f\t g_x: %.2f g_y: %.2f g_z: %.2f temp: %.2f \n", imu_data.processed_imu_data[0], imu_data.processed_imu_data[1], imu_data.processed_imu_data[2],
|
||||
// imu_data.processed_imu_data[3], imu_data.processed_imu_data[4], imu_data.processed_imu_data[5], imu_data.processed_imu_data[6]);
|
||||
// CDC_Transmit_FS((uint8_t*)output_buffer, (uint16_t)strlen(output_buffer));
|
||||
//
|
||||
// // compensated mag data
|
||||
////
|
||||
//// // compensated mag data
|
||||
// sprintf(output_buffer, "BMM:\tX: %.2f uT, Y: %.2f uT, Z: %.2f uT, Temp: %.2f C\n",
|
||||
// magn_data.x, magn_data.y, magn_data.z, magn_data.temperature);
|
||||
// CDC_Transmit_FS((uint8_t*)output_buffer, (uint16_t)strlen(output_buffer));
|
||||
@@ -777,7 +786,7 @@ void Start_DataAnalysis(void *argument)
|
||||
//
|
||||
// sprintf(output_buffer, "------------\n");
|
||||
// CDC_Transmit_FS((uint8_t*)output_buffer, (uint16_t)strlen(output_buffer));
|
||||
osDelay(100);
|
||||
// osDelay(100);
|
||||
}
|
||||
|
||||
/* USER CODE END 5 */
|
||||
@@ -816,14 +825,16 @@ void Start_ICM45686(void *argument)
|
||||
tx[0] = 0x00 | 0x80;
|
||||
|
||||
init_icm(&imu);
|
||||
osDelay(50);
|
||||
configure_interrupt_icm(&imu);
|
||||
enable_interrupt_icm(&imu);
|
||||
// osDelay(500);
|
||||
// calibrate_icm(&imu, 1000);
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
// imu
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_RESET);
|
||||
// status = HAL_SPI_TransmitReceive_DMA(&hspi1, tx, raw_imu_data, sizeof(raw_imu_data)); //(&hspi1, tx, raw_imu_data, sizeof(raw_imu_data), 50);
|
||||
status = read_icm_dma(&imu, tx, raw_imu_data);
|
||||
ulTaskNotifyTake(pdFALSE, osWaitForever);
|
||||
status = read_icm_dma(&imu, tx, raw_imu_data, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Reading IMU sensordata failed: %d\n", status);
|
||||
}
|
||||
@@ -854,12 +865,8 @@ void Start_ICM45686(void *argument)
|
||||
processed_data.processed_imu_data[6] -= imu.imu_bias[7];
|
||||
|
||||
}
|
||||
// printf("[0]: %.2f [3]: %.2f [6]: %.2f\n", processed_data.processed_imu_data[0], processed_data.processed_imu_data[3], processed_data.processed_imu_data[6]);
|
||||
|
||||
osMessageQueuePut(Q_ICMHandle, &processed_data, 0, 5);
|
||||
osDelay(100);
|
||||
|
||||
|
||||
}
|
||||
/* USER CODE END Start_ICM45686 */
|
||||
}
|
||||
@@ -881,21 +888,26 @@ void Start_BMM350(void *argument)
|
||||
struct bmm350_dev dev = {0x00};
|
||||
int8_t rslt;
|
||||
struct bmm350_mag_temp_data mag_data;
|
||||
osDelay(250);
|
||||
osDelay(500);
|
||||
// struct bmm350_raw_mag_data mag_data;
|
||||
|
||||
// struct bmm350_mag_temp_data mag_temp_data;
|
||||
// struct bmm350_pmu_cmd_status_0 pmu_cmd_stat_0;
|
||||
|
||||
// ODR: 200HZ, AVG:
|
||||
rslt = init_bmm(&dev);
|
||||
if (rslt != BMM350_OK) {
|
||||
printf("BMM350 initialization failed: %d\n", rslt);
|
||||
printf("Chip id: 0x%02X\n", dev.chip_id);
|
||||
}
|
||||
|
||||
rslt = bmm_configure_interrupt(&dev);
|
||||
if (rslt != BMM350_OK) {
|
||||
printf("Configuring interrupt failed: %d\n", rslt);
|
||||
}
|
||||
// osDelay(200);
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
// wait for the interrupt
|
||||
ulTaskNotifyTake(pdFALSE, osWaitForever);
|
||||
// magnetometer
|
||||
rslt = bmm350_get_compensated_mag_xyz_temp_data(&mag_data, &dev);
|
||||
// rslt = bmm350_read_uncomp_mag_temp_data(&mag_data, &dev);
|
||||
@@ -906,10 +918,7 @@ void Start_BMM350(void *argument)
|
||||
// CDC_Transmit_FS((uint8_t*)output_buffer, (uint16_t)strlen(output_buffer));
|
||||
osMessageQueuePut(Q_BMMHandle, &mag_data, 0, 5);
|
||||
}
|
||||
|
||||
osDelay(100);
|
||||
|
||||
|
||||
// osDelay(100);
|
||||
}
|
||||
/* USER CODE END Start_BMM350 */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user