Skip to content
Snippets Groups Projects
Commit 8d52c964 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Updated the imu module to the new firmware. Testing needed.

parent 94747be0
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ TARGET_FILES+=src/time.c ...@@ -11,6 +11,7 @@ TARGET_FILES+=src/time.c
TARGET_FILES+=src/eeprom.c TARGET_FILES+=src/eeprom.c
TARGET_FILES+=src/comm.c TARGET_FILES+=src/comm.c
TARGET_FILES+=src/adc_dma.c TARGET_FILES+=src/adc_dma.c
TARGET_FILES+=src/imu.c
TARGET_FILES+=src/dynamixel_slave_uart_dma.c TARGET_FILES+=src/dynamixel_slave_uart_dma.c
TARGET_FILES+=src/stm32f1xx_hal_msp.c TARGET_FILES+=src/stm32f1xx_hal_msp.c
TARGET_PROCESSOR=STM32F103RE TARGET_PROCESSOR=STM32F103RE
...@@ -65,6 +66,7 @@ TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal_flash.c ...@@ -65,6 +66,7 @@ TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal_flash.c
TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal_flash_ex.c TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal_flash_ex.c
TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal_adc.c TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal_adc.c
TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal_adc_ex.c TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal_adc_ex.c
TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal_spi.c
TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal.c TARGET_FILES+=$(HAL_PATH)/src/stm32f1xx_hal.c
DARWIN_OBJS_TMP = $(notdir $(TARGET_FILES:.c=.o)) DARWIN_OBJS_TMP = $(notdir $(TARGET_FILES:.c=.o))
......
#ifndef _IMU_H #ifndef _IMU_H
#define _IMU_H #define _IMU_H
#include "stm32f10x.h" #include "stm32f1xx_hal.h"
//public functions //public functions
void imu_init(void); void imu_init(void);
......
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
//#define HAL_RTC_MODULE_ENABLED //#define HAL_RTC_MODULE_ENABLED
//#define HAL_SD_MODULE_ENABLED //#define HAL_SD_MODULE_ENABLED
//#define HAL_SMARTCARD_MODULE_ENABLED //#define HAL_SMARTCARD_MODULE_ENABLED
//#define HAL_SPI_MODULE_ENABLED #define HAL_SPI_MODULE_ENABLED
//#define HAL_SRAM_MODULE_ENABLED //#define HAL_SRAM_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED #define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED
......
...@@ -2,33 +2,32 @@ ...@@ -2,33 +2,32 @@
#include "ram.h" #include "ram.h"
#include "gpio.h" #include "gpio.h"
#define IMU_SPI SPI2 #define IMU_SPI SPI2
#define IMU_SPI_CLK RCC_APB1Periph_SPI2 #define IMU_ENABEL_SPI_CLK __SPI2_CLK_ENABLE()
#define IMU_SPI_CLK_INIT RCC_APB1PeriphClockCmd #define IMU_SPI_IRQn SPI2_IRQn
#define IMU_SPI_IRQn SPI2_IRQn #define IMU_SPI_IRQHANDLER SPI2_IRQHandler
#define IMU_SPI_IRQHANDLER SPI2_IRQHandler
#define IMU_ACCEL_CS_PIN GPIO_PIN_10
#define IMU_ACCEL_CS_PIN GPIO_Pin_10 #define IMU_ACCEL_CS_PORT GPIOC
#define IMU_ACCEL_CS_PORT GPIOC #define IMU_ENABLE_ACCEL_CS_CLK __HAL_RCC_GPIOC_CLK_ENABLE()
#define IMU_ACCEL_CS_CLK RCC_APB2Periph_GPIOC #define IMU_GYRO_CS_PIN GPIO_PIN_11
#define IMU_GYRO_CS_PIN GPIO_Pin_11 #define IMU_GYRO_CS_PORT GPIOC
#define IMU_GYRO_CS_PORT GPIOC #define IMU_ENABLE_GYRO_CS_CLK __HAL_RCC_GPIOC_CLK_ENABLE()
#define IMU_GYRO_CS_CLK RCC_APB2Periph_GPIOC
#define IMU_SCK_PIN GPIO_PIN_13
#define IMU_SCK_PIN GPIO_Pin_13 #define IMU_SCK_PORT GPIOB
#define IMU_SCK_PORT GPIOB #define IMU_ENABLE_SCK_CLK __HAL_RCC_GPIOB_CLK_ENABLE()
#define IMU_SCK_CLK RCC_APB2Periph_GPIOB #define IMU_MISO_PIN GPIO_PIN_14
#define IMU_MISO_PIN GPIO_Pin_14 #define IMU_MISO_PORT GPIOB
#define IMU_MISO_PORT GPIOB #define IMU_ENABLE_MISO_CLK __HAL_RCC_GPIOB_CLK_ENABLE()
#define IMU_MISO_CLK RCC_APB2Periph_GPIOB #define IMU_MOSI_PIN GPIO_PIN_15
#define IMU_MOSI_PIN GPIO_Pin_15 #define IMU_MOSI_PORT GPIOB
#define IMU_MOSI_PORT GPIOB #define IMU_ENABLE_MOSI_CLK __HAL_RCC_GPIOB_CLK_ENABLE()
#define IMU_MOSI_CLK RCC_APB2Periph_GPIOB
#define IMU_TIMER TIM6
#define IMU_TIMER TIM6 #define IMU_TIMER_IRQn TIM6_IRQn
#define IMU_TIMER_IRQn TIM6_IRQn #define IMU_TIMER_IRQHandler TIM6_IRQHandler
#define IMU_TIMER_IRQHandler TIM6_IRQHandler #define IMU_ENABLE_TIMER_CLK __HAL_RCC_TIM6_CLK_ENABLE()
#define IMU_TIMER_CLK RCC_APB1Periph_TIM6
// accelerometer registers // accelerometer registers
#define ACCEL_ID 0x32 #define ACCEL_ID 0x32
...@@ -115,6 +114,9 @@ uint8_t accel_conf_data[5]; ...@@ -115,6 +114,9 @@ uint8_t accel_conf_data[5];
const uint8_t accel_data_reg=ACCEL_OUT_X_L; const uint8_t accel_data_reg=ACCEL_OUT_X_L;
const uint8_t accel_data_len=6; const uint8_t accel_data_len=6;
SPI_HandleTypeDef hspi2;
TIM_HandleTypeDef htim;
// private functions // private functions
inline void imu_wait_op_done(void) inline void imu_wait_op_done(void)
{ {
...@@ -132,18 +134,18 @@ uint8_t imu_is_op_done(void) ...@@ -132,18 +134,18 @@ uint8_t imu_is_op_done(void)
void imu_enable_device(uint8_t device_id) void imu_enable_device(uint8_t device_id)
{ {
if(device_id==ACCEL_ID) if(device_id==ACCEL_ID)
GPIO_ResetBits(IMU_ACCEL_CS_PORT,IMU_ACCEL_CS_PIN); HAL_GPIO_WritePin(IMU_ACCEL_CS_PORT,IMU_ACCEL_CS_PIN,GPIO_PIN_RESET);
else if(device_id==GYRO_ID) else if(device_id==GYRO_ID)
GPIO_ResetBits(IMU_GYRO_CS_PORT,IMU_GYRO_CS_PIN); HAL_GPIO_WritePin(IMU_GYRO_CS_PORT,IMU_GYRO_CS_PIN,GPIO_PIN_RESET);
imu_current_device_id=device_id; imu_current_device_id=device_id;
} }
void imu_disable_device(void) void imu_disable_device(void)
{ {
if(imu_current_device_id==ACCEL_ID) if(imu_current_device_id==ACCEL_ID)
GPIO_SetBits(IMU_ACCEL_CS_PORT,IMU_ACCEL_CS_PIN); HAL_GPIO_WritePin(IMU_ACCEL_CS_PORT,IMU_ACCEL_CS_PIN,GPIO_PIN_SET);
else if(imu_current_device_id==GYRO_ID) else if(imu_current_device_id==GYRO_ID)
GPIO_SetBits(IMU_GYRO_CS_PORT,IMU_GYRO_CS_PIN); HAL_GPIO_WritePin(IMU_GYRO_CS_PORT,IMU_GYRO_CS_PIN,GPIO_PIN_SET);
imu_current_device_id=0x00; imu_current_device_id=0x00;
} }
...@@ -163,7 +165,8 @@ void imu_spi_start_read(uint8_t address,uint8_t length) ...@@ -163,7 +165,8 @@ void imu_spi_start_read(uint8_t address,uint8_t length)
} }
imu_op_state=IMU_BUSY; imu_op_state=IMU_BUSY;
// start the read operation // start the read operation
SPI_I2S_ITConfig(IMU_SPI, SPI_I2S_IT_TXE, ENABLE); __HAL_SPI_ENABLE_IT(&hspi2, SPI_IT_TXE);
__HAL_SPI_ENABLE(&hspi2);
} }
void imu_spi_get_data(uint8_t *data) void imu_spi_get_data(uint8_t *data)
...@@ -190,7 +193,8 @@ void imu_spi_start_write(uint8_t address,uint8_t *data,uint8_t length) ...@@ -190,7 +193,8 @@ void imu_spi_start_write(uint8_t address,uint8_t *data,uint8_t length)
} }
imu_op_state=IMU_BUSY; imu_op_state=IMU_BUSY;
// start the read operation // start the read operation
SPI_I2S_ITConfig(IMU_SPI, SPI_I2S_IT_TXE, ENABLE); __HAL_SPI_ENABLE_IT(&hspi2, SPI_IT_TXE);
__HAL_SPI_ENABLE(&hspi2);
} }
// accelerometer private functions // accelerometer private functions
...@@ -333,10 +337,10 @@ void IMU_SPI_IRQHANDLER(void) ...@@ -333,10 +337,10 @@ void IMU_SPI_IRQHANDLER(void)
{ {
static uint8_t num_wr=0,num_rd=0; static uint8_t num_wr=0,num_rd=0;
/* SPI in Receiver mode */ /* SPI in mode Receiver and Overrun not occurred ---------------------------*/
if(SPI_I2S_GetITStatus(IMU_SPI,SPI_I2S_IT_RXNE)==SET) if((__HAL_SPI_GET_IT_SOURCE(&hspi2, SPI_IT_RXNE) != RESET) && (__HAL_SPI_GET_FLAG(&hspi2, SPI_FLAG_RXNE) != RESET) && (__HAL_SPI_GET_FLAG(&hspi2, SPI_FLAG_OVR) == RESET))
{ {
imu_spi_rd_data[num_rd]=SPI_I2S_ReceiveData(IMU_SPI); imu_spi_rd_data[num_rd]=hspi2.Instance->DR;
num_rd++; num_rd++;
if(num_rd >= imu_spi_num_rd_data) if(num_rd >= imu_spi_num_rd_data)
{ {
...@@ -346,16 +350,20 @@ void IMU_SPI_IRQHANDLER(void) ...@@ -346,16 +350,20 @@ void IMU_SPI_IRQHANDLER(void)
num_wr=0; num_wr=0;
} }
} }
/* SPI in Tramitter mode */
if(SPI_I2S_GetITStatus(IMU_SPI,SPI_I2S_IT_TXE)==SET) /* SPI in mode Tramitter ---------------------------------------------------*/
if((__HAL_SPI_GET_IT_SOURCE(&hspi2, SPI_IT_TXE) != RESET) && (__HAL_SPI_GET_FLAG(&hspi2, SPI_FLAG_TXE) != RESET))
{ {
if(num_wr < imu_spi_num_wr_data) if(num_wr < imu_spi_num_wr_data)
{ {
SPI_I2S_SendData(IMU_SPI,imu_spi_wr_data[num_wr]); hspi2.Instance->DR=imu_spi_wr_data[num_wr];
num_wr++; num_wr++;
} }
else else
SPI_I2S_ITConfig(IMU_SPI,SPI_I2S_IT_TXE,DISABLE); {
// SPI_WaitOnFlagUntilTimeout(&hspi2,SPI_FLAG_TXE,RESET,SPI_TIMEOUT_VALUE);
__HAL_SPI_DISABLE_IT(&hspi2, SPI_IT_TXE);
}
} }
} }
...@@ -366,64 +374,68 @@ void IMU_TIMER_IRQHandler(void) ...@@ -366,64 +374,68 @@ void IMU_TIMER_IRQHandler(void)
static int16_t num_samples=0; static int16_t num_samples=0;
uint8_t data[6]; uint8_t data[6];
TIM_ClearITPendingBit(IMU_TIMER,TIM_IT_Update); if(__HAL_TIM_GET_FLAG(&htim, TIM_FLAG_UPDATE) != RESET)
if(imu_is_op_done())
{ {
if(imu_stop_flag==0x01) if(__HAL_TIM_GET_IT_SOURCE(&htim, TIM_IT_UPDATE) !=RESET)
{ {
// stop the timer to get the imu data __HAL_TIM_CLEAR_IT(&htim, TIM_IT_UPDATE);
TIM_Cmd(IMU_TIMER, DISABLE); if(imu_is_op_done())
TIM_ITConfig(IMU_TIMER, TIM_IT_Update, DISABLE);
ram_clear_bit(DARWIN_IMU_STATUS,2);
imu_stop_flag=0x00;
imu_stopped=0x01;
}
else
{
switch(state)
{ {
case IMU_GET_ACCEL: if(ram_data[DARWIN_IMU_STATUS]&0x02) if(imu_stop_flag==0x01)
{ {
imu_spi_get_data(data); // stop the timer to get the imu data
imu_gyro_convert_data(data,&ram_data[DARWIN_IMU_GYRO_X_L]); HAL_TIM_Base_Stop_IT(&htim);
if(gyro_calibration)
{ ram_clear_bit(DARWIN_IMU_STATUS,2);
gyro_accum[0]+=gyro_data[0]; imu_stop_flag=0x00;
gyro_accum[1]+=gyro_data[1]; imu_stopped=0x01;
gyro_accum[2]+=gyro_data[2]; }
num_samples++; else
if(num_samples==gyro_cal_num_samples) {
switch(state)
{
case IMU_GET_ACCEL: if(ram_data[DARWIN_IMU_STATUS]&0x02)
{ {
num_samples=0; imu_spi_get_data(data);
gyro_center[0]=gyro_accum[0]/gyro_cal_num_samples; imu_gyro_convert_data(data,&ram_data[DARWIN_IMU_GYRO_X_L]);
gyro_center[1]=gyro_accum[1]/gyro_cal_num_samples; if(gyro_calibration)
gyro_center[2]=gyro_accum[2]/gyro_cal_num_samples; {
gyro_accum[0]=0; gyro_accum[0]+=gyro_data[0];
gyro_accum[1]=0; gyro_accum[1]+=gyro_data[1];
gyro_accum[2]=0; gyro_accum[2]+=gyro_data[2];
ram_set_bit(DARWIN_IMU_STATUS,3); num_samples++;
ram_clear_bit(DARWIN_IMU_CONTROL,1); if(num_samples==gyro_cal_num_samples)
if((ram_data[DARWIN_IMU_STATUS]&0x04)==0x00) {
imu_stop_flag=0x01; num_samples=0;
gyro_calibration=0x00; gyro_center[0]=gyro_accum[0]/gyro_cal_num_samples;
gyro_center[1]=gyro_accum[1]/gyro_cal_num_samples;
gyro_center[2]=gyro_accum[2]/gyro_cal_num_samples;
gyro_accum[0]=0;
gyro_accum[1]=0;
gyro_accum[2]=0;
ram_set_bit(DARWIN_IMU_STATUS,3);
ram_clear_bit(DARWIN_IMU_CONTROL,1);
if((ram_data[DARWIN_IMU_STATUS]&0x04)==0x00)
imu_stop_flag=0x01;
gyro_calibration=0x00;
}
}
} }
} if(ram_data[DARWIN_IMU_STATUS]&0x01)
} imu_accel_get_data();
if(ram_data[DARWIN_IMU_STATUS]&0x01) state=IMU_GET_GYRO;
imu_accel_get_data(); break;
state=IMU_GET_GYRO; case IMU_GET_GYRO: if(ram_data[DARWIN_IMU_STATUS]&0x01)
break; {
case IMU_GET_GYRO: if(ram_data[DARWIN_IMU_STATUS]&0x01) imu_spi_get_data(data);
{ imu_accel_convert_data(data,&ram_data[DARWIN_IMU_ACCEL_X_L]);
imu_spi_get_data(data); }
imu_accel_convert_data(data,&ram_data[DARWIN_IMU_ACCEL_X_L]); if(ram_data[DARWIN_IMU_STATUS]&0x02)
} imu_gyro_get_data();
if(ram_data[DARWIN_IMU_STATUS]&0x02) state=IMU_GET_ACCEL;
imu_gyro_get_data(); break;
state=IMU_GET_ACCEL; }
break; }
} }
} }
} }
...@@ -433,44 +445,39 @@ void IMU_TIMER_IRQHandler(void) ...@@ -433,44 +445,39 @@ void IMU_TIMER_IRQHandler(void)
// public functions // public functions
void imu_init(void) void imu_init(void)
{ {
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
uint8_t i; uint8_t i;
GPIO_StructInit(&GPIO_InitStructure);
// enable the clocks // enable the clocks
IMU_SPI_CLK_INIT(IMU_SPI_CLK, ENABLE); IMU_ENABLE_ACCEL_CS_CLK;
RCC_APB2PeriphClockCmd(IMU_MOSI_CLK | IMU_MISO_CLK | IMU_SCK_CLK | IMU_ACCEL_CS_CLK | IMU_GYRO_CS_CLK, ENABLE); IMU_ENABLE_GYRO_CS_CLK;
/* Enable the IMU timer clock */ IMU_ENABLE_SCK_CLK;
RCC_APB1PeriphClockCmd(IMU_TIMER_CLK,ENABLE); IMU_ENABLE_MISO_CLK;
IMU_ENABLE_MOSI_CLK;
IMU_ENABEL_SPI_CLK;
// initialize the input output ports // initialize the input output ports
GPIO_InitStructure.GPIO_Pin = IMU_ACCEL_CS_PIN; GPIO_InitStructure.Pin = IMU_SCK_PIN|IMU_MOSI_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
GPIO_Init(IMU_ACCEL_CS_PORT, &GPIO_InitStructure); HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(IMU_ACCEL_CS_PORT,IMU_ACCEL_CS_PIN);
GPIO_InitStructure.Pin = IMU_MISO_PIN;
GPIO_InitStructure.GPIO_Pin = IMU_GYRO_CS_PIN; GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_Init(IMU_GYRO_CS_PORT, &GPIO_InitStructure); GPIO_InitStructure.Pull = GPIO_NOPULL;
// disable both sensors HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(IMU_GYRO_CS_PORT,IMU_GYRO_CS_PIN);
GPIO_InitStructure.Pin = IMU_ACCEL_CS_PIN;
// initliaze the SPI peripheral GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
GPIO_InitStructure.GPIO_Pin = IMU_SCK_PIN; GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; HAL_GPIO_Init(IMU_ACCEL_CS_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(IMU_SCK_PORT, &GPIO_InitStructure); GPIO_InitStructure.Pin = IMU_GYRO_CS_PIN;
HAL_GPIO_Init(IMU_GYRO_CS_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = IMU_MOSI_PIN;
GPIO_Init(IMU_MOSI_PORT, &GPIO_InitStructure); HAL_GPIO_WritePin(IMU_ACCEL_CS_PORT,IMU_ACCEL_CS_PIN,GPIO_PIN_SET);
HAL_GPIO_WritePin(IMU_GYRO_CS_PORT,IMU_GYRO_CS_PIN,GPIO_PIN_SET);
GPIO_InitStructure.GPIO_Pin = IMU_MISO_PIN;
GPIO_Init(IMU_MISO_PORT, &GPIO_InitStructure);
/* initialize variables */ /* initialize variables */
imu_spi_num_wr_data=0x00; imu_spi_num_wr_data=0x00;
...@@ -488,41 +495,37 @@ void imu_init(void) ...@@ -488,41 +495,37 @@ void imu_init(void)
gyro_calibration=0x00; gyro_calibration=0x00;
// configure the SPI module // configure the SPI module
SPI_StructInit(&SPI_InitStructure); hspi2.Instance = IMU_SPI;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; hspi2.Init.Mode = SPI_MODE_MASTER;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; hspi2.Init.Direction = SPI_DIRECTION_2LINES;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; hspi2.Init.NSS = SPI_NSS_SOFT;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7; hspi2.Init.TIMode = SPI_TIMODE_DISABLED;
SPI_Init(IMU_SPI, &SPI_InitStructure); hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
HAL_SPI_Init(&hspi2);
/* Configure the SPI interrupt priority */ /* Configure the SPI interrupt priority */
NVIC_InitStructure.NVIC_IRQChannel = IMU_SPI_IRQn; HAL_NVIC_SetPriority(IMU_SPI_IRQn, 2, 1);
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; HAL_NVIC_EnableIRQ(IMU_SPI_IRQn);
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
SPI_I2S_ITConfig(IMU_SPI, SPI_I2S_IT_RXNE , ENABLE);
/* Enable SPI2 */
SPI_Cmd(IMU_SPI, ENABLE);
/* imu timer configuration */ /* imu timer configuration */
TIM_TimeBaseStructure.TIM_Period = 1000; htim.Instance=IMU_TIMER;
TIM_TimeBaseStructure.TIM_Prescaler = 72; htim.Init.Period = 1000;
TIM_TimeBaseStructure.TIM_ClockDivision = 0; htim.Init.Prescaler = 72;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; htim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
TIM_TimeBaseInit(IMU_TIMER,&TIM_TimeBaseStructure); htim.Init.CounterMode = TIM_COUNTERMODE_UP;
htim.Init.RepetitionCounter=0;
NVIC_InitStructure.NVIC_IRQChannel = IMU_TIMER_IRQn; HAL_TIM_Base_Init(&htim);
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; IMU_ENABLE_TIMER_CLK;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; HAL_NVIC_SetPriority(IMU_TIMER_IRQn, 2, 0);
NVIC_Init(&NVIC_InitStructure); HAL_NVIC_EnableIRQ(IMU_TIMER_IRQn);
__HAL_SPI_ENABLE_IT(&hspi2, SPI_IT_RXNE);
if(imu_gyro_detect()) if(imu_gyro_detect())
{ {
...@@ -546,8 +549,7 @@ void imu_start(void) ...@@ -546,8 +549,7 @@ void imu_start(void)
imu_gyro_start(); imu_gyro_start();
// start the timer to get the imu data // start the timer to get the imu data
TIM_Cmd(IMU_TIMER, ENABLE); HAL_TIM_Base_Start_IT(&htim);
TIM_ITConfig(IMU_TIMER, TIM_IT_Update, ENABLE);
ram_set_bit(DARWIN_IMU_STATUS,2); ram_set_bit(DARWIN_IMU_STATUS,2);
ram_set_bit(DARWIN_IMU_CONTROL,0); ram_set_bit(DARWIN_IMU_CONTROL,0);
} }
...@@ -575,8 +577,7 @@ void imu_start_gyro_cal(void) ...@@ -575,8 +577,7 @@ void imu_start_gyro_cal(void)
imu_gyro_start(); imu_gyro_start();
// start the timer to get the imu data // start the timer to get the imu data
TIM_Cmd(IMU_TIMER, ENABLE); HAL_TIM_Base_Start_IT(&htim);
TIM_ITConfig(IMU_TIMER, TIM_IT_Update, ENABLE);
} }
ram_clear_bit(DARWIN_IMU_STATUS,3); ram_clear_bit(DARWIN_IMU_STATUS,3);
gyro_center[0]=0; gyro_center[0]=0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment