From f4468b8b585ace57013080b31dd7b2769521fd6f Mon Sep 17 00:00:00 2001 From: Sundarbavan Date: Tue, 24 Sep 2024 20:22:50 +0530 Subject: [PATCH 1/7] encoder_modified --- .settings/language.settings.xml | 4 ++-- Library/Inc/encoder.h | 2 +- Library/Src/encoder.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 1639232..84455a4 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/Library/Inc/encoder.h b/Library/Inc/encoder.h index 13a7f82..3e89520 100755 --- a/Library/Inc/encoder.h +++ b/Library/Inc/encoder.h @@ -6,7 +6,7 @@ #define _ENCODER_START (u32)u32_max/1e4 #define l_position TIM2-> CNT -#define r_position (u32_max-TIM5-> CNT) +#define r_position (u32_max-TIM3-> CNT) void encoderInit(void); diff --git a/Library/Src/encoder.c b/Library/Src/encoder.c index fcc2b4c..71b0827 100755 --- a/Library/Src/encoder.c +++ b/Library/Src/encoder.c @@ -3,13 +3,13 @@ // FUCTION: INTIALIZATION OF ENCODER RELATED HARDWARE void encoderInit(void){ -// HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL); // LEFT ENCODER -// HAL_TIM_Encoder_Start(&htim5, TIM_CHANNEL_ALL); // RIGHT ENCODER -// resetEncoder(); + HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL); // LEFT ENCODER + HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); // RIGHT ENCODER + resetEncoder(); } void resetEncoder(void){ TIM2->CNT = _ENCODER_START + 1; - TIM5->CNT = u32_max-_ENCODER_START; + TIM3->CNT = u32_max-_ENCODER_START; } From 4607205842b107b28aa78ff4e8499b1ee95d681c Mon Sep 17 00:00:00 2001 From: Sundarbavan Date: Wed, 25 Sep 2024 16:36:38 +0530 Subject: [PATCH 2/7] MPU6050_created --- .settings/stm32cubeide.project.prefs | 4 +- Core/Src/main.c | 28 ++++++- Library/Inc/{L3GD20.h => MPU6050.h} | 6 +- Library/Inc/PD.h | 2 +- Library/Src/L3GD20.c | 113 --------------------------- Library/Src/MPU6050.c | 100 ++++++++++++++++++++++++ Library/Src/motor.c | 68 ++++++++-------- Program/Inc/entry.h | 3 +- Program/Src/entry.cpp | 24 ++++-- kitro Debug.launch | 22 ++++-- kitro.ioc | 6 +- platformio.ini | 2 +- 12 files changed, 201 insertions(+), 177 deletions(-) rename Library/Inc/{L3GD20.h => MPU6050.h} (84%) mode change 100755 => 100644 delete mode 100755 Library/Src/L3GD20.c create mode 100644 Library/Src/MPU6050.c diff --git a/.settings/stm32cubeide.project.prefs b/.settings/stm32cubeide.project.prefs index f72821e..e7eaf17 100644 --- a/.settings/stm32cubeide.project.prefs +++ b/.settings/stm32cubeide.project.prefs @@ -1,5 +1,5 @@ 635E684B79701B039C64EA45C3F84D30=C4495712B0C2E8A2AF8F69A17C20BF90 66BE74F758C12D739921AEA421D593D3=1 -8DF89ED150041C4CBC7CB9A9CAA90856=77372D1B316F94A23E0081AE2C8086CD -DC22A860405A8BF2F2C095E5B6529F12=77372D1B316F94A23E0081AE2C8086CD +8DF89ED150041C4CBC7CB9A9CAA90856=941708D65AE899D041E2E88BD48979ED +DC22A860405A8BF2F2C095E5B6529F12=98BEC944DEC8C5C9D4FE92706B769F46 eclipse.preferences.version=1 diff --git a/Core/Src/main.c b/Core/Src/main.c index 6e83f31..2bb24f3 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -65,14 +65,32 @@ static void MX_TIM4_Init(void); static void MX_USART1_UART_Init(void); static void MX_TIM2_Init(void); static void MX_TIM3_Init(void); -/* USER CODE BEGIN PFP */ +/* USER CODE BEGIN PFP */ +//#define PUTCHAR_PROTOTYPE int __io_putchar(int ch) /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ +int _write(int fd, char * ptr, int len) +{ + HAL_UART_Transmit(&huart1, (uint8_t *) ptr, len, HAL_MAX_DELAY); + return len; +} +/** + * @brief Retargets the C library printf function to the USART. + * None + * @retval None + */ +//PUTCHAR_PROTOTYPE +//{ +// /* Place your implementation of fputc here */ +// /* e.g. write a character to the USART1 and Loop until the end of transmission */ +// HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); +// +// return ch; +//} +/* USER CODE END 0 */ /** * @brief The application entry point. @@ -83,12 +101,14 @@ int main(void) /* USER CODE BEGIN 1 */ + /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + + HAL_Init(); /* USER CODE BEGIN Init */ diff --git a/Library/Inc/L3GD20.h b/Library/Inc/MPU6050.h old mode 100755 new mode 100644 similarity index 84% rename from Library/Inc/L3GD20.h rename to Library/Inc/MPU6050.h index f13acc8..df11e1e --- a/Library/Inc/L3GD20.h +++ b/Library/Inc/MPU6050.h @@ -1,5 +1,5 @@ -#ifndef __L3GD20_H -#define __L3GD20_H +#ifndef __MPU6050_H +#define __MPU6050_H #include "led.h" #include "typedefs.h" @@ -9,7 +9,7 @@ #include -#define BUFFER_LENGTH ((u32)1000u) // 1000u +#define BUFFER_LENGTH 1000u // 1000u extern float angle_z; extern uint8_t gyro_identity; diff --git a/Library/Inc/PD.h b/Library/Inc/PD.h index 04454d2..3baf543 100755 --- a/Library/Inc/PD.h +++ b/Library/Inc/PD.h @@ -4,12 +4,12 @@ #include "motor.h" #include "typedefs.h" #include "encoder.h" -#include "L3GD20.h" #include "parameters_.h" #include "led.h" #include "main.h" #include "read_sensors.h" #include +#include extern bool align_select; extern u32 l_start; diff --git a/Library/Src/L3GD20.c b/Library/Src/L3GD20.c deleted file mode 100755 index e10ccd6..0000000 --- a/Library/Src/L3GD20.c +++ /dev/null @@ -1,113 +0,0 @@ -//#include "L3GD20.h" -// -//const float timeDifference = 2e-3; -//const float NOISE_THRESHOLD = NOISE_THRESHOLD_; -//const float GYRO_SENSITIVITY = GYRO_SENSITIVITY_; -// -//u8 gyro_identity; -//float angle_z = 0; -//float last_angle_rate = 0, angle_rate=0; -// -//float offset; -//float noise; -// -//static u8 spiTxBuf[2]; -//static u8 spiRxBuf[2]; -// -// -//void gyroInit(void) -//{ -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); -// spiTxBuf[0] = 0x0F | 0x80; // WHO_AM_I -// HAL_SPI_Transmit(&hspi1, spiTxBuf, 1, 50); -// HAL_SPI_Receive(&hspi1, &gyro_identity, 1, 50); -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET); -// HAL_Delay(20); -// -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); -// HAL_Delay(20); -// spiTxBuf[0] = 0x20; // CTRL1: DR1 DR0 BW1 BW0 PD Zen Xen Yen -// spiTxBuf[1] = 0xfc; // 800Hz, BW-100Hz 1 1 1 1 1 1 0 0 -// HAL_SPI_Transmit(&hspi1, spiTxBuf, 2, 50); -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET); -// HAL_Delay(20); -// -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); -// HAL_Delay(20); -// spiTxBuf[0] = 0x21; // CTRL2: EXTRen LVLen HPM1 HMP0 HPCF3 HPCF2 HPCF1 HPCF0 -// spiTxBuf[1] = 0x03; // 2Hz 0 0 0 0 0 1 0 1 -// HAL_SPI_Transmit(&hspi1, spiTxBuf, 2, 50); -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET); -// HAL_Delay(20); -// -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); -// HAL_Delay(20); -// spiTxBuf[0] = 0x23; // CTRL4: BDU BLE FS1 FS0 IMPen ST2 ST1 SIM -// spiTxBuf[1] = 0x30; // 2000dps 0 0 1 1 0 0 0 0 -// HAL_SPI_Transmit(&hspi1, spiTxBuf, 2, 50); -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET); -// HAL_Delay(20); -// -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); -// HAL_Delay(20); -// spiTxBuf[0] = 0x24; // CTRL5: BOOT FIFO_EN StopOnFTH HPen IG_Sel1 IG_Sel2 Out_Sel1 Out_Sel0 -// spiTxBuf[1] = 0x00; // 0 0 0 0 0 0 0 0 -// HAL_SPI_Transmit(&hspi1, spiTxBuf, 2, 50); -// HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET); -// HAL_Delay(20); -//} -// -//int gyroUpdate(void) -//{ -// LED8_ON; -// angle_rate = (float)(readGyro() - offset) * GYRO_SENSITIVITY; -// angle_rate = (fabs(angle_rate) < noise && fabs(angle_rate) SPEED_THRESHOLD) -// l_speed = (l_speed > 0) ? SPEED_THRESHOLD : -SPEED_THRESHOLD; -// -// l_pwma = (l_speed < 0) ? (-l_speed) * u12_max : 0; -// l_pwmb = (l_speed >= 0) ? l_speed * u12_max : 0; -// -// __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, l_pwma); // LPWMA -// __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, l_pwmb); // LPWMB -//} -// -//void setRightWheel(float r_speed) -//{ -// uint16_t r_pwma, r_pwmb; -// -// if (fabs(r_speed) > SPEED_THRESHOLD) -// r_speed = (r_speed > 0) ? SPEED_THRESHOLD : -SPEED_THRESHOLD; -// r_pwma = (r_speed < 0) ? (-r_speed) * u12_max : 0; -// r_pwmb = (r_speed >= 0) ? r_speed * u12_max : 0; -// -// __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, r_pwma); // RPWMA -// __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, r_pwmb); // RPWMB -//} -// -//int setWheels() -//{ -// setRightWheel(r_speed), setLeftWheel(l_speed); -// return 0; -//} -// + +void setLeftWheel(float l_speed) +{ + uint16_t l_pwma, l_pwmb; + + if (fabs(l_speed) > SPEED_THRESHOLD) + l_speed = (l_speed > 0) ? SPEED_THRESHOLD : -SPEED_THRESHOLD; + + l_pwma = (l_speed < 0) ? (-l_speed) * u12_max : 0; + l_pwmb = (l_speed >= 0) ? l_speed * u12_max : 0; + + __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, l_pwma); // LPWMA + __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, l_pwmb); // LPWMB +} + +void setRightWheel(float r_speed) +{ + uint16_t r_pwma, r_pwmb; + + if (fabs(r_speed) > SPEED_THRESHOLD) + r_speed = (r_speed > 0) ? SPEED_THRESHOLD : -SPEED_THRESHOLD; + r_pwma = (r_speed < 0) ? (-r_speed) * u12_max : 0; + r_pwmb = (r_speed >= 0) ? r_speed * u12_max : 0; + + __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, r_pwma); // RPWMA + __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, r_pwmb); // RPWMB +} + +int setWheels() +{ + setRightWheel(r_speed), setLeftWheel(l_speed); + return 0; +} + diff --git a/Program/Inc/entry.h b/Program/Inc/entry.h index 329f009..62ed4bb 100644 --- a/Program/Inc/entry.h +++ b/Program/Inc/entry.h @@ -25,7 +25,7 @@ extern "C" { // #include "motor.h" // #include "encoder.h" // #include "display.h" -// #include "L3GD20.h" + #include // #include "read_sensors.h" @@ -57,6 +57,7 @@ int greymatter(void); extern TIM_HandleTypeDef htim2; extern TIM_HandleTypeDef htim3; extern TIM_HandleTypeDef htim4; +extern I2C_HandleTypeDef hi2c2; // INTERRUPTS // void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin); diff --git a/Program/Src/entry.cpp b/Program/Src/entry.cpp index d5fde9d..ae13cd8 100644 --- a/Program/Src/entry.cpp +++ b/Program/Src/entry.cpp @@ -42,6 +42,10 @@ // void mouseRun(); +void print(const char *str){ + printf(str); +} + int greymatter(void) { // initialization_block(); // HAL_Delay(1000); @@ -62,17 +66,23 @@ int greymatter(void) { // // XY_prev.y = 0; // XY_prev.x = 0; + gyroInit(); + gyroCalibration(); while (1) { // mouseRun(); // i++; - HAL_GPIO_TogglePin(ONB_LED_GPIO_Port, ONB_LED_Pin); - ssd1306_Fill(Black); - ssd1306_UpdateScreen(); - HAL_Delay(500); - ssd1306_Fill(White); - ssd1306_UpdateScreen(); - HAL_Delay(500); +// HAL_GPIO_TogglePin(ONB_LED_GPIO_Port, ONB_LED_Pin); +// ssd1306_Fill(Black); +// ssd1306_UpdateScreen(); +// HAL_Delay(500); +// ssd1306_Fill(White); +// ssd1306_UpdateScreen(); +// HAL_Delay(500); + print("a\n\r"); +// gyroUpdate(); + HAL_Delay(500); + } } diff --git a/kitro Debug.launch b/kitro Debug.launch index 6c59335..df6f065 100644 --- a/kitro Debug.launch +++ b/kitro Debug.launch @@ -7,11 +7,11 @@ - + - - + + @@ -20,6 +20,7 @@ + @@ -33,14 +34,23 @@ - + - + - + + + + + + + + + + diff --git a/kitro.ioc b/kitro.ioc index e8f1fd6..1ccdc91 100644 --- a/kitro.ioc +++ b/kitro.ioc @@ -93,12 +93,8 @@ PA8.Mode=I2C PA8.Signal=I2C3_SCL PA9.Mode=Asynchronous PA9.Signal=USART1_TX -PB10.GPIOParameters=GPIO_Label -PB10.GPIO_Label=GYRO_SCL PB10.Mode=I2C PB10.Signal=I2C2_SCL -PB3.GPIOParameters=GPIO_Label -PB3.GPIO_Label=GYRO_SDA PB3.Mode=I2C PB3.Signal=I2C2_SDA PB4.GPIOParameters=GPIO_Label @@ -152,7 +148,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_I2C2_Init-I2C2-false-HAL-true,5-MX_I2C3_Init-I2C3-false-HAL-true,6-MX_TIM4_Init-TIM4-false-HAL-true,7-MX_USART1_UART_Init-USART1-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_I2C2_Init-I2C2-false-HAL-true,5-MX_I2C3_Init-I2C3-false-HAL-true,6-MX_TIM4_Init-TIM4-false-HAL-true,7-MX_USART1_UART_Init-USART1-false-HAL-true,8-MX_TIM2_Init-TIM2-false-HAL-true,9-MX_TIM3_Init-TIM3-false-HAL-true RCC.AHBFreq_Value=16000000 RCC.APB1Freq_Value=16000000 RCC.APB2Freq_Value=16000000 diff --git a/platformio.ini b/platformio.ini index 4540edc..b4f91f3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,4 +1,4 @@ -# [platformio] +G# [platformio] # src_dir = Core/Src From f66621547aae286c3e639d1253b8d423ed0119b1 Mon Sep 17 00:00:00 2001 From: Sundarbavan Date: Thu, 26 Sep 2024 17:29:53 +0530 Subject: [PATCH 3/7] u32 -> u16 in encoders --- Core/Src/main.c | 2 +- Library/Inc/MPU6050.h | 2 +- Library/Inc/encoder.h | 4 +- Library/Inc/typedefs.h | 1 + Library/Src/MPU6050.c | 23 ++- Library/Src/PD.c | 420 ++++++++++++++++++++--------------------- Library/Src/encoder.c | 2 +- Program/Inc/entry.h | 4 +- Program/Src/entry.cpp | 19 +- kitro.ioc | 4 + 10 files changed, 248 insertions(+), 233 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index 2bb24f3..24db42a 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -329,7 +329,7 @@ static void MX_TIM2_Init(void) htim2.Instance = TIM2; htim2.Init.Prescaler = 0; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; - htim2.Init.Period = 4294967295; + htim2.Init.Period = 65535; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; sConfig.EncoderMode = TIM_ENCODERMODE_TI1; diff --git a/Library/Inc/MPU6050.h b/Library/Inc/MPU6050.h index df11e1e..ab10a95 100644 --- a/Library/Inc/MPU6050.h +++ b/Library/Inc/MPU6050.h @@ -9,7 +9,7 @@ #include -#define BUFFER_LENGTH 1000u // 1000u +#define BUFFER_LENGTH ((u32)1000u) // 1000u extern float angle_z; extern uint8_t gyro_identity; diff --git a/Library/Inc/encoder.h b/Library/Inc/encoder.h index 3e89520..296a53a 100755 --- a/Library/Inc/encoder.h +++ b/Library/Inc/encoder.h @@ -4,9 +4,9 @@ #include "main.h" #include "typedefs.h" -#define _ENCODER_START (u32)u32_max/1e4 +#define _ENCODER_START (u16)u16_max/1e4 #define l_position TIM2-> CNT -#define r_position (u32_max-TIM3-> CNT) +#define r_position (u16_max-TIM3-> CNT) void encoderInit(void); diff --git a/Library/Inc/typedefs.h b/Library/Inc/typedefs.h index ccb9651..de27766 100755 --- a/Library/Inc/typedefs.h +++ b/Library/Inc/typedefs.h @@ -5,6 +5,7 @@ #include #define u32_max 4294967295 +#define u16_max 65535 #define u32 uint32_t #define u16 uint16_t diff --git a/Library/Src/MPU6050.c b/Library/Src/MPU6050.c index 9105501..b1a82c3 100644 --- a/Library/Src/MPU6050.c +++ b/Library/Src/MPU6050.c @@ -4,11 +4,12 @@ #define GYRO_CONFIG_REG 0x1B #define PWR_MGMT_1_REG 0x6B #define GYRO_ZOUT_H_REG 0x47 -#define GYRO_SENSITIVITY 131.0 // Sensitivity for 250dps +#define GYRO_SENSITIVITY 131.0 * 6 // Sensitivity for 250dps const float timeDifference = 2e-3; // 2ms time step const float NOISE_THRESHOLD = 0.05; // Noise threshold + float angle_z = 0; float last_angle_rate = 0, angle_rate = 0; float offset = 0; @@ -56,29 +57,27 @@ int16_t readGyro(void) // Function to calibrate the gyroscope void gyroCalibration(void) { - int16_t gyroZ; + int16_t calibration_buffer[BUFFER_LENGTH]; int32_t calibrationSum = 0; - for (uint32_t i = 0; i < BUFFER_LENGTH; i++) + for (u32 i = 0; i < BUFFER_LENGTH; i++) { - gyroZ = readGyro(); - calibrationSum += gyroZ; + calibration_buffer[i] = readGyro(); HAL_Delay(2); + calibrationSum += calibration_buffer[i]; } offset = (float)calibrationSum / BUFFER_LENGTH; // Calculate noise level - for (u32 i = 0; i < BUFFER_LENGTH; i++) - { - gyroZ = readGyro(); - noise += pow((gyroZ - offset), 2); - } - noise = sqrt(noise / BUFFER_LENGTH) / 2.0 * GYRO_SENSITIVITY; + for (u32 i = 0; i < BUFFER_LENGTH; i++) + noise += pow(calibration_buffer[i] - offset, 2); + noise = pow(noise, .5) / 2 / GYRO_SENSITIVITY; printf("Calibration complete. Offset: %f, Noise: %f\r\n", offset, noise); } + // Function to update gyroscope data int gyroUpdate(void) { @@ -86,7 +85,7 @@ int gyroUpdate(void) angle_rate = ((float)(gyroZ - offset)) / GYRO_SENSITIVITY; // Apply noise filtering - if (fabs(angle_rate) < NOISE_THRESHOLD) + if (fabs(angle_rate) < NOISE_THRESHOLD && fabs(angle_rate) < noise) { angle_rate = 0; } diff --git a/Library/Src/PD.c b/Library/Src/PD.c index 192e104..cc0cfd5 100755 --- a/Library/Src/PD.c +++ b/Library/Src/PD.c @@ -1,212 +1,212 @@ -//#include "PD.h" -// -//// VARIABLES -//u32 l_start = 0; -//static u32 r_start = 0, previous_time = 0, current_time = 0, start_time = 0, last_exit_time = 0; // STORE STARTING POSITION -//static float start_angle = 0; -// -//static MV_Type mv_type = IDLE; -//static float dist_ang; -// -//static float PD_correction_sc = 0, PD_correction_ac = 0, PD_correction_ir = 0; -//static float sc_last_error = 0, ac_last_error = 0, ir_last_error = 0; -// -///////////////////////////////////////////////////// CONTROLLER ///////////////////////////////////////////////////////////////// -//static int fm_counter = 0; -//const float TERMINATION_TH = 4e-2; -//bool align_select = false; -// -//bool finishMove(MV_Type mv_type_, float dist_ang_) -//{ -// -// mv_type = mv_type_, dist_ang = dist_ang_; -// current_time = HAL_GetTick(); -// -// // FIRST CALL -// if (l_start == 0) -// { -// l_start = l_position, r_start = r_position, start_angle = angle_z; +#include "PD.h" + +// VARIABLES +u32 l_start = 0; +static u32 r_start = 0, previous_time = 0, current_time = 0, start_time = 0, last_exit_time = 0; // STORE STARTING POSITION +static float start_angle = 0; + +static MV_Type mv_type = IDLE; +static float dist_ang; + +static float PD_correction_sc = 0, PD_correction_ac = 0, PD_correction_ir = 0; +static float sc_last_error = 0, ac_last_error = 0, ir_last_error = 0; + +/////////////////////////////////////////////////// CONTROLLER ///////////////////////////////////////////////////////////////// +static int fm_counter = 0; +const float TERMINATION_TH = 4e-2; +bool align_select = false; + +bool finishMove(MV_Type mv_type_, float dist_ang_) +{ + + mv_type = mv_type_, dist_ang = dist_ang_; + current_time = HAL_GetTick(); + + // FIRST CALL + if (l_start == 0) + { + l_start = l_position, r_start = r_position, start_angle = angle_z; // (mv_type == STRAIGHT_RUN) ? LED1_ON : ((mv_type == POINT_TURN) ? LED2_ON : LED3_ON); -// sc_last_error = 0, ac_last_error = 0, fm_counter = 0; -// previous_time = current_time; -// start_time = current_time, last_exit_time = 0; -// assignParameters(); -// return false; -// } -// -// // CORRECTIONS -// PD_correction_ac = 0, PD_correction_ir = 0; -// speedController(); -// -// // TERMINATION CODITION -// if (fabs(PD_correction_sc) < fabs(TERMINATION_TH) || (current_time - start_time > 2000) ||( (current_time - last_exit_time) > 100 && last_exit_time != 0)) -// { -// if (fm_counter > 5) -// { -// l_start = 0, r_start = 0; -// fm_counter = 0; + sc_last_error = 0, ac_last_error = 0, fm_counter = 0; + previous_time = current_time; + start_time = current_time, last_exit_time = 0; + assignParameters(); + return false; + } + + // CORRECTIONS + PD_correction_ac = 0, PD_correction_ir = 0; + speedController(); + + // TERMINATION CODITION + if (fabs(PD_correction_sc) < fabs(TERMINATION_TH) || (current_time - start_time > 2000) ||( (current_time - last_exit_time) > 100 && last_exit_time != 0)) + { + if (fm_counter > 5) + { + l_start = 0, r_start = 0; + fm_counter = 0; // (mv_type == STRAIGHT_RUN) ? LED1_OFF : ((mv_type == POINT_TURN) ? LED2_OFF : LED3_OFF); -// return true; -// } -// fm_counter++; -// HAL_Delay(20); -// } -// -// // SET WHEEL -// switch (mv_type) -// { -// case STRAIGHT_RUN: -// l_speed = PD_correction_sc - PD_correction_ac + PD_correction_ir; -// r_speed = PD_correction_sc + PD_correction_ac - PD_correction_ir; -// break; -// case POINT_TURN: -// l_speed = -PD_correction_sc + PD_correction_ac; -// r_speed = +PD_correction_sc - PD_correction_ac; -// break; -// case FRONT_ALIGN: -// l_speed = -PD_correction_sc ; -// r_speed = PD_correction_sc ; -// break; -// } -// setWheels(); -// previous_time = current_time; -// align_select = false; -// return false; -//} -// -//////////////////////////////////////////////////// PARAMETER CHOICE /////////////////////////////////////////////////////////////// -//// PARAMETERS -//static float sc_kp = 0, sc_kd = 0, sc_red = 1e3; -//static float ac_kp = 0, ac_kd = 0, ac_red = 1e3; -//static float ir_kp = 0, ir_kd = 0, ir_red = 1e3; -//static float counts_ = 0; // CONVERTING ANGLE/ DISTANCE TO ENCODER COUNTS -//static float speed_th_ = 0; -// -//void assignParameters(void) -//{ -// switch (mv_type) -// { -// case IDLE: -// sc_red = 1e5, ac_red = 1e5; -// break; -// -// case STRAIGHT_RUN: -// speed_th_ = st_speed; -// counts_ = dist_ang * LINEAR_SENSITIVITY; -// -// if (fabs(st_speed - 0.3) < .05) -// { -// sc_kp = 1, sc_kd = 5e-3, sc_red = 200; -// ac_kp = 1.1, ac_kd = 8e-2, ac_red = 100; -// ir_kp = 1, ir_kd = 3e-2, ir_red = 5e2; -// } -// else if (fabs(st_speed - 0.5) < .05) -// { -// sc_kp = 1.1, sc_kd = 2e-3, sc_red = 400; -// ac_kp = 1.3, ac_kd = 1e-3, ac_red = 500; -// ir_kp = 1, ir_kd = 1e-3, ir_red = 2000; -// } -// else -// { -// sc_kp = 1.2, sc_kd = 2e-3, sc_red = 450; -// ac_kp = 1.3, ac_kd = 1e-3, ac_red = 600; -// ir_kp = 1, ir_kd = 1e-3, ir_red = 2500; -// } -// break; -// -// case POINT_TURN: -// counts_ = dist_ang * TURN_SENSITIVITY; -// speed_th_ = rt_speed; -// -// sc_kp = 1.2, sc_kd = 1e-2, sc_red = 60; // 2e-3 -// ac_kp = 1, ac_kd = 3e-3, ac_red = 1000; -// break; -// -// case FRONT_ALIGN: -// speed_th_ = al_speed; -// sc_kp = 1, sc_kd = 0, sc_red = 500; -// break; -// } -// return; -//} -///////////////////////////////////////////////////// SPEED CONTROLLER ///////////////////////////////////////////////////////////// -//static float sc_error = 0; -// -//void speedController(void) -//{ -// switch (mv_type) -// { -// case IDLE: -// sc_error = 0; -// break; -// -// case STRAIGHT_RUN: -// sc_error = l_start + r_start + 2 * counts_, sc_error -= l_position, sc_error -= r_position; // sc_error = (l_start + r_start + 2*counts_) - l_position - r_position -// break; -// -// case POINT_TURN: -// // ENCODER BASED TURN : sc_error = (counts_ - (l_start - l_position)) + (counts_ - (r_position - r_start)) -// // sc_error = 2*counts_ - l_start + r_start, sc_error += l_position, sc_error -=r_position; // BACK UP : ENCODER BASED TURN -// // GYRO BASED TURN -// sc_error = (start_angle + dist_ang) - angle_z; -// break; -// -// case FRONT_ALIGN: + return true; + } + fm_counter++; + HAL_Delay(20); + } + + // SET WHEEL + switch (mv_type) + { + case STRAIGHT_RUN: + l_speed = PD_correction_sc - PD_correction_ac + PD_correction_ir; + r_speed = PD_correction_sc + PD_correction_ac - PD_correction_ir; + break; + case POINT_TURN: + l_speed = -PD_correction_sc + PD_correction_ac; + r_speed = +PD_correction_sc - PD_correction_ac; + break; + case FRONT_ALIGN: + l_speed = -PD_correction_sc ; + r_speed = PD_correction_sc ; + break; + } + setWheels(); + previous_time = current_time; + align_select = false; + return false; +} + +////////////////////////////////////////////////// PARAMETER CHOICE /////////////////////////////////////////////////////////////// +// PARAMETERS +static float sc_kp = 0, sc_kd = 0, sc_red = 1e3; +static float ac_kp = 0, ac_kd = 0, ac_red = 1e3; +static float ir_kp = 0, ir_kd = 0, ir_red = 1e3; +static float counts_ = 0; // CONVERTING ANGLE/ DISTANCE TO ENCODER COUNTS +static float speed_th_ = 0; + +void assignParameters(void) +{ + switch (mv_type) + { + case IDLE: + sc_red = 1e5, ac_red = 1e5; + break; + + case STRAIGHT_RUN: + speed_th_ = st_speed; + counts_ = dist_ang * LINEAR_SENSITIVITY; + + if (fabs(st_speed - 0.3) < .05) + { + sc_kp = 1, sc_kd = 5e-3, sc_red = 200; + ac_kp = 1.1, ac_kd = 8e-2, ac_red = 100; + ir_kp = 1, ir_kd = 3e-2, ir_red = 5e2; + } + else if (fabs(st_speed - 0.5) < .05) + { + sc_kp = 1.1, sc_kd = 2e-3, sc_red = 400; + ac_kp = 1.3, ac_kd = 1e-3, ac_red = 500; + ir_kp = 1, ir_kd = 1e-3, ir_red = 2000; + } + else + { + sc_kp = 1.2, sc_kd = 2e-3, sc_red = 450; + ac_kp = 1.3, ac_kd = 1e-3, ac_red = 600; + ir_kp = 1, ir_kd = 1e-3, ir_red = 2500; + } + break; + + case POINT_TURN: + counts_ = dist_ang * TURN_SENSITIVITY; + speed_th_ = rt_speed; + + sc_kp = 1.2, sc_kd = 1e-2, sc_red = 60; // 2e-3 + ac_kp = 1, ac_kd = 3e-3, ac_red = 1000; + break; + + case FRONT_ALIGN: + speed_th_ = al_speed; + sc_kp = 1, sc_kd = 0, sc_red = 500; + break; + } + return; +} +/////////////////////////////////////////////////// SPEED CONTROLLER ///////////////////////////////////////////////////////////// +static float sc_error = 0; + +void speedController(void) +{ + switch (mv_type) + { + case IDLE: + sc_error = 0; + break; + + case STRAIGHT_RUN: + sc_error = l_start + r_start + 2 * counts_, sc_error -= l_position, sc_error -= r_position; // sc_error = (l_start + r_start + 2*counts_) - l_position - r_position + break; + + case POINT_TURN: + // ENCODER BASED TURN : sc_error = (counts_ - (l_start - l_position)) + (counts_ - (r_position - r_start)) + // sc_error = 2*counts_ - l_start + r_start, sc_error += l_position, sc_error -=r_position; // BACK UP : ENCODER BASED TURN + // GYRO BASED TURN + sc_error = (start_angle + dist_ang) - angle_z; + break; + + case FRONT_ALIGN: // sc_error = (LFSensor - RFSensor); -// break; -// } -// -// PD_correction_sc = (float)(sc_kp * sc_error + sc_kd * 1e3 * (sc_error - sc_last_error) / (current_time - previous_time)) / sc_red; -// sc_last_error = sc_error; -// if (fabs(PD_correction_sc) > speed_th_) -// { -// PD_correction_sc = (PD_correction_sc > 0) ? speed_th_ : -speed_th_; -// if (irController() && align_select) -// { -// PD_correction_ac = 0; -// irController(); -// } -// else -// { -// PD_correction_ir = 0; -// angularController(); -// } -// return; -// } -// // PD_correction_ac = 0; -//} -// -//////////////////////////////////////////// ANGULAR CONTROLLER ////////////////////////////////////////////////////////// -//static float ac_error = 0; -// -//void angularController(void) -//{ -// switch (mv_type) -// { -// -// // STRAIGHT RUN -// case (STRAIGHT_RUN): -// ac_error = l_position, ac_error -= r_position; -// break; -// -// // POINT-ROTATION -// case (POINT_TURN): -// ac_error = r_position, ac_error += l_position, ac_error -= (l_start + r_start), ac_error = (float)ac_error; // a_error = (l_position - l_start) + (r_position - r_start) -// break; -// default: -// ac_error = 0; -// break; -// } -// -// PD_correction_ac = (ac_kp * ac_error + sc_kd * 1e3 * (sc_error - sc_last_error) / (current_time - previous_time)) / ac_red; -// ac_last_error = ac_error; -// if (fabs(PD_correction_ac) > .5 * speed_th_) -// PD_correction_ac = (PD_correction_ac > 0) ? .5 * speed_th_ : -.5 * speed_th_; -// -// return; -//} -// -///////////////////////////////////////////////////////// IR-CONTROLLER ///////////////////////////////////////////////////////////////////////////////// + break; + } + + PD_correction_sc = (float)(sc_kp * sc_error + sc_kd * 1e3 * (sc_error - sc_last_error) / (current_time - previous_time)) / sc_red; + sc_last_error = sc_error; + if (fabs(PD_correction_sc) > speed_th_) + { + PD_correction_sc = (PD_correction_sc > 0) ? speed_th_ : -speed_th_; + if (irController() && align_select) + { + PD_correction_ac = 0; + irController(); + } + else + { + PD_correction_ir = 0; + angularController(); + } + return; + } + // PD_correction_ac = 0; +} + +////////////////////////////////////////// ANGULAR CONTROLLER ////////////////////////////////////////////////////////// +static float ac_error = 0; + +void angularController(void) +{ + switch (mv_type) + { + + // STRAIGHT RUN + case (STRAIGHT_RUN): + ac_error = l_position, ac_error -= r_position; + break; + + // POINT-ROTATION + case (POINT_TURN): + ac_error = r_position, ac_error += l_position, ac_error -= (l_start + r_start), ac_error = (float)ac_error; // a_error = (l_position - l_start) + (r_position - r_start) + break; + default: + ac_error = 0; + break; + } + + PD_correction_ac = (ac_kp * ac_error + sc_kd * 1e3 * (sc_error - sc_last_error) / (current_time - previous_time)) / ac_red; + ac_last_error = ac_error; + if (fabs(PD_correction_ac) > .5 * speed_th_) + PD_correction_ac = (PD_correction_ac > 0) ? .5 * speed_th_ : -.5 * speed_th_; + + return; +} + +/////////////////////////////////////////////////////// IR-CONTROLLER ///////////////////////////////////////////////////////////////////////////////// //static float ir_error = 0; //const float MIDDLE_VALUE_DL = 1210; // @@ -232,8 +232,8 @@ //} //static bool a = false; //// DL SENSOR ALIGNMENT -//bool irController(void) -//{ +bool irController(void) +{ // calculateAndSaveAverages(); // a = leftWall(); // if ((mv_type == STRAIGHT_RUN)) @@ -256,5 +256,5 @@ // return true; // } // PD_correction_ir = 0; -// return false; -//} + return false; +} diff --git a/Library/Src/encoder.c b/Library/Src/encoder.c index 71b0827..90e84d8 100755 --- a/Library/Src/encoder.c +++ b/Library/Src/encoder.c @@ -10,6 +10,6 @@ void encoderInit(void){ void resetEncoder(void){ TIM2->CNT = _ENCODER_START + 1; - TIM3->CNT = u32_max-_ENCODER_START; + TIM3->CNT = u16_max-_ENCODER_START; } diff --git a/Program/Inc/entry.h b/Program/Inc/entry.h index 62ed4bb..47b91d3 100644 --- a/Program/Inc/entry.h +++ b/Program/Inc/entry.h @@ -32,7 +32,7 @@ extern "C" { // #include "typedefs.h" #include "ssd1306.h" // #include "buzzer.h" -// #include "PD.h" + #include "PD.h" // extern bool buttonPress; // extern int mouseState; @@ -61,7 +61,7 @@ extern I2C_HandleTypeDef hi2c2; // INTERRUPTS // void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin); -// void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim); + void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim); #ifdef __cplusplus } diff --git a/Program/Src/entry.cpp b/Program/Src/entry.cpp index ae13cd8..f550b1c 100644 --- a/Program/Src/entry.cpp +++ b/Program/Src/entry.cpp @@ -68,6 +68,8 @@ int greymatter(void) { // XY_prev.x = 0; gyroInit(); gyroCalibration(); + encoderInit(); + motorInit(); while (1) { // mouseRun(); @@ -79,9 +81,14 @@ int greymatter(void) { // ssd1306_Fill(White); // ssd1306_UpdateScreen(); // HAL_Delay(500); - print("a\n\r"); -// gyroUpdate(); - HAL_Delay(500); +// print("a\n\r"); +// printf("%lu \n\r",r_position); +// printf("%u \n\r",r_position); +// HAL_Delay(5); +// finishMove(STRAIGHT_RUN, 0); +// setLeftWheel(1); +// setRightWheel(1); + } } @@ -107,7 +114,11 @@ int greymatter(void) { // // return 0; // } - +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +{ + if (htim == &htim4) + gyroUpdate(); +} // void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) //{ // if (htim == &htim14) diff --git a/kitro.ioc b/kitro.ioc index 1ccdc91..a8e212f 100644 --- a/kitro.ioc +++ b/kitro.ioc @@ -9,6 +9,8 @@ CAD.formats= CAD.pinconfig= CAD.provider= File.Version=6 +I2C2.I2C_Mode=I2C_Standard +I2C2.IPParameters=I2C_Mode I2C3.I2C_Mode=I2C_Fast I2C3.IPParameters=I2C_Mode KeepUserPlacement=false @@ -194,6 +196,8 @@ SH.S_TIM4_CH3.0=TIM4_CH3,PWM Generation3 CH3 SH.S_TIM4_CH3.ConfNb=1 SH.S_TIM4_CH4.0=TIM4_CH4,PWM Generation4 CH4 SH.S_TIM4_CH4.ConfNb=1 +TIM2.IPParameters=Period +TIM2.Period=65535 TIM4.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 TIM4.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2 TIM4.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3 From 36907442da50ccd915bc27ed92395716926deb5c Mon Sep 17 00:00:00 2001 From: Sundarbavan Date: Thu, 26 Sep 2024 18:21:42 +0530 Subject: [PATCH 4/7] Included TIM_STARR defs --- Core/Inc/main.h | 9 ++++++- Library/Inc/display.h | 2 +- Program/Inc/entry.h | 16 +++++++----- Program/Src/entry.cpp | 60 +++++++++++++++++++------------------------ kitro.ioc | 33 +++++++++++++++++++----- 5 files changed, 71 insertions(+), 49 deletions(-) diff --git a/Core/Inc/main.h b/Core/Inc/main.h index add4cf0..f723467 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -89,7 +89,14 @@ void Error_Handler(void); #define PWM_CH4_GPIO_Port GPIOB /* USER CODE BEGIN Private defines */ - +#define TIM1_START HAL_TIM_Base_Start(&htim1) +#define TIM1_STOP HAL_TIM_Base_Stop(&htim1); +#define TIM6_IT_START HAL_TIM_Base_Start_IT(&htim6) +#define TIM6_IT_STOP HAL_TIM_Base_Stop_IT(&htim6) +#define TIM10_IT_START HAL_TIM_Base_Start_IT(&htim10) +#define TIM10_IT_STOP HAL_TIM_Base_Stop_IT(&htim10) +#define TIM11_IT_START HAL_TIM_Base_Start_IT(&htim11) +#define TIM11_IT_STOP HAL_TIM_Base_Stop_IT(&htim11) /* USER CODE END Private defines */ #ifdef __cplusplus diff --git a/Library/Inc/display.h b/Library/Inc/display.h index 04d2947..78a28c9 100755 --- a/Library/Inc/display.h +++ b/Library/Inc/display.h @@ -28,7 +28,7 @@ HUGE // 16x24 // THIS VARIABLE DECIDES WHAT IS ON SCREEN extern DISP_State disp_state; -// INITIALIZATION OF THE DISPLAY +// INITIALIZATION OF THE DISPLAY void displayInit(void); // CLEARNING SCREEN diff --git a/Program/Inc/entry.h b/Program/Inc/entry.h index 47b91d3..f85040e 100644 --- a/Program/Inc/entry.h +++ b/Program/Inc/entry.h @@ -22,14 +22,14 @@ extern "C" { #include "algo.h" // #include "adc.h" // #include "led.h" -// #include "motor.h" -// #include "encoder.h" +#include "motor.h" +#include "encoder.h" // #include "display.h" - #include +#include // #include "read_sensors.h" -// #include "typedefs.h" +#include "typedefs.h" #include "ssd1306.h" // #include "buzzer.h" #include "PD.h" @@ -53,15 +53,19 @@ int greymatter(void); // INITIALIZATION OF HARDWARE //extern TIM_HandleTypeDef htim4; -// int initialization_block(void); +int initialization_block(void); + +extern TIM_HandleTypeDef htim1; extern TIM_HandleTypeDef htim2; extern TIM_HandleTypeDef htim3; extern TIM_HandleTypeDef htim4; +extern TIM_HandleTypeDef htim10; +extern TIM_HandleTypeDef htim11; extern I2C_HandleTypeDef hi2c2; // INTERRUPTS // void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin); - void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim); +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim); #ifdef __cplusplus } diff --git a/Program/Src/entry.cpp b/Program/Src/entry.cpp index f550b1c..767082b 100644 --- a/Program/Src/entry.cpp +++ b/Program/Src/entry.cpp @@ -47,7 +47,7 @@ void print(const char *str){ } int greymatter(void) { - // initialization_block(); + initialization_block(); // HAL_Delay(1000); // disp_state = DEFAULT; // @@ -66,10 +66,6 @@ int greymatter(void) { // // XY_prev.y = 0; // XY_prev.x = 0; - gyroInit(); - gyroCalibration(); - encoderInit(); - motorInit(); while (1) { // mouseRun(); @@ -85,7 +81,7 @@ int greymatter(void) { // printf("%lu \n\r",r_position); // printf("%u \n\r",r_position); // HAL_Delay(5); -// finishMove(STRAIGHT_RUN, 0); + finishMove(STRAIGHT_RUN, 100); // setLeftWheel(1); // setRightWheel(1); @@ -93,42 +89,38 @@ int greymatter(void) { } } -// int initialization_block(void) -//{ +int initialization_block(void) +{ // ALL_LED_ON; -// TIM1_START; ////////////////// CRUCIAL PART DON"T OFFFFFFFFFFFFFFFF -///////////////////////////// TIM6_IT_START; -// -// motorInit(); -// encoderInit(); -// gyroInit(); + TIM1_START; ////////////////// CRUCIAL PART DON"T OFFFFFFFFFFFFFFFF +/////////////////////////// TIM6_IT_START; + + motorInit(); + encoderInit(); + gyroInit(); // displayInit(); // buzzerInit(); -// + // ALL_LED_OFF; -// HAL_Delay(1000); -// gyroCalibration(); + HAL_Delay(1000); + gyroCalibration(); // disp_state = DEFAULT; -// TIM13_IT_START; -// // TIM14_IT_START; -// -// return 0; -// } -void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) + TIM10_IT_START; + // TIM14_IT_START; + + return 0; + } + + void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { - if (htim == &htim4) - gyroUpdate(); -} -// void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -//{ -// if (htim == &htim14) -// ; -// else if (htim == &htim13) -// gyroUpdate(), -// readSensor(); + if (htim == &htim11) + ; + else if (htim == &htim10) + gyroUpdate(), + readSensor(); // else if (htim == &htim6) // displayUpdate(); -// } + } // // void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) //{ diff --git a/kitro.ioc b/kitro.ioc index a8e212f..ed70d1c 100644 --- a/kitro.ioc +++ b/kitro.ioc @@ -18,15 +18,18 @@ Mcu.CPN=STM32F411CEU6 Mcu.Family=STM32F4 Mcu.IP0=ADC1 Mcu.IP1=I2C2 +Mcu.IP10=TIM10 +Mcu.IP11=TIM11 +Mcu.IP12=USART1 Mcu.IP2=I2C3 Mcu.IP3=NVIC Mcu.IP4=RCC Mcu.IP5=SYS -Mcu.IP6=TIM2 -Mcu.IP7=TIM3 -Mcu.IP8=TIM4 -Mcu.IP9=USART1 -Mcu.IPNb=10 +Mcu.IP6=TIM1 +Mcu.IP7=TIM2 +Mcu.IP8=TIM3 +Mcu.IP9=TIM4 +Mcu.IPNb=13 Mcu.Name=STM32F411C(C-E)Ux Mcu.Package=UFQFPN48 Mcu.Pin0=PC13-ANTI_TAMP @@ -43,6 +46,9 @@ Mcu.Pin18=PB8 Mcu.Pin19=PB9 Mcu.Pin2=PA1 Mcu.Pin20=VP_SYS_VS_Systick +Mcu.Pin21=VP_TIM1_VS_ClockSourceINT +Mcu.Pin22=VP_TIM10_VS_ClockSourceINT +Mcu.Pin23=VP_TIM11_VS_ClockSourceINT Mcu.Pin3=PA2 Mcu.Pin4=PA3 Mcu.Pin5=PA4 @@ -50,7 +56,7 @@ Mcu.Pin6=PA5 Mcu.Pin7=PA6 Mcu.Pin8=PA7 Mcu.Pin9=PB10 -Mcu.PinsNb=21 +Mcu.PinsNb=24 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F411CEUx @@ -150,7 +156,7 @@ ProjectManager.ToolChainLocation= ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptBeforePath= ProjectManager.UnderRoot=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_I2C2_Init-I2C2-false-HAL-true,5-MX_I2C3_Init-I2C3-false-HAL-true,6-MX_TIM4_Init-TIM4-false-HAL-true,7-MX_USART1_UART_Init-USART1-false-HAL-true,8-MX_TIM2_Init-TIM2-false-HAL-true,9-MX_TIM3_Init-TIM3-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_ADC1_Init-ADC1-false-HAL-true,4-MX_I2C2_Init-I2C2-false-HAL-true,5-MX_I2C3_Init-I2C3-false-HAL-true,6-MX_TIM4_Init-TIM4-false-HAL-true,7-MX_USART1_UART_Init-USART1-false-HAL-true,8-MX_TIM2_Init-TIM2-false-HAL-true,9-MX_TIM3_Init-TIM3-false-HAL-true,10-MX_TIM1_Init-TIM1-false-HAL-true RCC.AHBFreq_Value=16000000 RCC.APB1Freq_Value=16000000 RCC.APB2Freq_Value=16000000 @@ -196,6 +202,13 @@ SH.S_TIM4_CH3.0=TIM4_CH3,PWM Generation3 CH3 SH.S_TIM4_CH3.ConfNb=1 SH.S_TIM4_CH4.0=TIM4_CH4,PWM Generation4 CH4 SH.S_TIM4_CH4.ConfNb=1 +TIM1.IPParameters=Prescaler +TIM1.Prescaler=49 +TIM10.IPParameters=Period +TIM10.Period=50000 +TIM11.IPParameters=Prescaler,Period +TIM11.Period=50000 +TIM11.Prescaler=1 TIM2.IPParameters=Period TIM2.Period=65535 TIM4.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1 @@ -208,5 +221,11 @@ USART1.IPParameters=VirtualMode USART1.VirtualMode=VM_ASYNC VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_TIM10_VS_ClockSourceINT.Mode=Enable_Timer +VP_TIM10_VS_ClockSourceINT.Signal=TIM10_VS_ClockSourceINT +VP_TIM11_VS_ClockSourceINT.Mode=Enable_Timer +VP_TIM11_VS_ClockSourceINT.Signal=TIM11_VS_ClockSourceINT +VP_TIM1_VS_ClockSourceINT.Mode=Internal +VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT board=custom isbadioc=false From b5ee7ae9e50f58dbde014b352383f6583262b8d4 Mon Sep 17 00:00:00 2001 From: Sundarbavan Date: Thu, 26 Sep 2024 19:23:05 +0530 Subject: [PATCH 5/7] Updated write function --- .mxproject | 22 ++--- .settings/stm32cubeide.project.prefs | 2 +- Core/Inc/main.h | 4 - Core/Src/main.c | 138 +++++++++++++++++++++++---- Core/Src/stm32f4xx_hal_msp.c | 100 +++++++++++++++++-- Library/Src/MPU6050.c | 2 +- Program/Src/entry.cpp | 27 +++--- kitro.ioc | 2 +- 8 files changed, 242 insertions(+), 55 deletions(-) diff --git a/.mxproject b/.mxproject index 1973685..d2522d3 100644 --- a/.mxproject +++ b/.mxproject @@ -1,25 +1,25 @@ [PreviousLibFiles] -LibFiles=Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dmamux.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_adc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dmamux.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_i2c.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_tim.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f411xe.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Drivers/CMSIS/Include/core_cm85.h;Drivers/CMSIS/Include/cachel1_armv7.h;Drivers/CMSIS/Include/pac_armv81.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/core_cm35p.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/core_armv81mml.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm55.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/pmu_armv8.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/core_starmc1.h;Drivers/CMSIS/Include/cmsis_armclang_ltm.h; +LibFiles=Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_adc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_adc_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_adc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_rcc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_rcc_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_bus.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_rcc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_system.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_utils.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash_ramfunc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_gpio.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_gpio_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_gpio.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_dma_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_dma.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_dma.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_dmamux.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pwr.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pwr_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_pwr.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_cortex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_cortex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal.h;Drivers\STM32F4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_def.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_exti.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_exti.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_i2c.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_i2c.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_i2c_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_tim.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_tim_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_tim.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_uart.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_usart.h;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_adc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_adc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_adc_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_adc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_rcc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_rcc_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_bus.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_rcc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_system.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_utils.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_flash_ramfunc.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_gpio.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_gpio_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_gpio.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_dma_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_dma.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_dma.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_dmamux.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pwr.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_pwr_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_pwr.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_cortex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_cortex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal.h;Drivers\STM32F4xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_def.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_exti.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_exti.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_i2c.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_i2c.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_i2c_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_tim.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_tim_ex.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_tim.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_hal_uart.h;Drivers\STM32F4xx_HAL_Driver\Inc\stm32f4xx_ll_usart.h;Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f411xe.h;Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f4xx.h;Drivers\CMSIS\Device\ST\STM32F4xx\Include\system_stm32f4xx.h;Drivers\CMSIS\Device\ST\STM32F4xx\Include\system_stm32f4xx.h;Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c;Drivers\CMSIS\Include\cachel1_armv7.h;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_armclang_ltm.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv81mml.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm35p.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm55.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_cm85.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\core_starmc1.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\pac_armv81.h;Drivers\CMSIS\Include\pmu_armv8.h;Drivers\CMSIS\Include\tz_context.h; [PreviousUsedCubeIDEFiles] -SourceFiles=Core/Src/main.c;Core/Src/stm32f4xx_it.c;Core/Src/stm32f4xx_hal_msp.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;;; -HeaderPath=Drivers/STM32F4xx_HAL_Driver/Inc;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;Drivers/CMSIS/Device/ST/STM32F4xx/Include;Drivers/CMSIS/Include;Core/Inc; +SourceFiles=Core\Src\main.c;Core\Src\stm32f4xx_it.c;Core\Src\stm32f4xx_hal_msp.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_adc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c;Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c;Core\Src\system_stm32f4xx.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_adc_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_adc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_rcc_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_flash_ramfunc.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_gpio.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_dma.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_pwr_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_cortex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_exti.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_i2c_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_tim_ex.c;Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_uart.c;Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c;Core\Src\system_stm32f4xx.c;;; +HeaderPath=Drivers\STM32F4xx_HAL_Driver\Inc;Drivers\STM32F4xx_HAL_Driver\Inc\Legacy;Drivers\CMSIS\Device\ST\STM32F4xx\Include;Drivers\CMSIS\Include;Core\Inc; CDefines=USE_HAL_DRIVER;STM32F411xE;USE_HAL_DRIVER;USE_HAL_DRIVER; [PreviousGenFiles] AdvancedFolderStructure=true HeaderFileListSize=3 -HeaderFiles#0=../Core/Inc/stm32f4xx_it.h -HeaderFiles#1=../Core/Inc/stm32f4xx_hal_conf.h -HeaderFiles#2=../Core/Inc/main.h +HeaderFiles#0=..\Core\Inc\stm32f4xx_it.h +HeaderFiles#1=..\Core\Inc\stm32f4xx_hal_conf.h +HeaderFiles#2=..\Core\Inc\main.h HeaderFolderListSize=1 -HeaderPath#0=../Core/Inc +HeaderPath#0=..\Core\Inc HeaderFiles=; SourceFileListSize=3 -SourceFiles#0=../Core/Src/stm32f4xx_it.c -SourceFiles#1=../Core/Src/stm32f4xx_hal_msp.c -SourceFiles#2=../Core/Src/main.c +SourceFiles#0=..\Core\Src\stm32f4xx_it.c +SourceFiles#1=..\Core\Src\stm32f4xx_hal_msp.c +SourceFiles#2=..\Core\Src\main.c SourceFolderListSize=1 -SourcePath#0=../Core/Src +SourcePath#0=..\Core\Src SourceFiles=; diff --git a/.settings/stm32cubeide.project.prefs b/.settings/stm32cubeide.project.prefs index e7eaf17..31a812a 100644 --- a/.settings/stm32cubeide.project.prefs +++ b/.settings/stm32cubeide.project.prefs @@ -1,5 +1,5 @@ 635E684B79701B039C64EA45C3F84D30=C4495712B0C2E8A2AF8F69A17C20BF90 66BE74F758C12D739921AEA421D593D3=1 8DF89ED150041C4CBC7CB9A9CAA90856=941708D65AE899D041E2E88BD48979ED -DC22A860405A8BF2F2C095E5B6529F12=98BEC944DEC8C5C9D4FE92706B769F46 +DC22A860405A8BF2F2C095E5B6529F12=941708D65AE899D041E2E88BD48979ED eclipse.preferences.version=1 diff --git a/Core/Inc/main.h b/Core/Inc/main.h index f723467..dd35940 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -71,12 +71,8 @@ void Error_Handler(void); #define SHARP_3_GPIO_Port GPIOA #define SHARP_4_Pin GPIO_PIN_5 #define SHARP_4_GPIO_Port GPIOA -#define GYRO_SCL_Pin GPIO_PIN_10 -#define GYRO_SCL_GPIO_Port GPIOB #define DISPLAY_SCL_Pin GPIO_PIN_8 #define DISPLAY_SCL_GPIO_Port GPIOA -#define GYRO_SDA_Pin GPIO_PIN_3 -#define GYRO_SDA_GPIO_Port GPIOB #define DISPLAY_SDA_Pin GPIO_PIN_4 #define DISPLAY_SDA_GPIO_Port GPIOB #define PWM_CH1_Pin GPIO_PIN_6 diff --git a/Core/Src/main.c b/Core/Src/main.c index 24db42a..93a44d9 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -45,9 +45,12 @@ ADC_HandleTypeDef hadc1; I2C_HandleTypeDef hi2c2; I2C_HandleTypeDef hi2c3; +TIM_HandleTypeDef htim1; TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim3; TIM_HandleTypeDef htim4; +TIM_HandleTypeDef htim10; +TIM_HandleTypeDef htim11; UART_HandleTypeDef huart1; @@ -65,7 +68,9 @@ static void MX_TIM4_Init(void); static void MX_USART1_UART_Init(void); static void MX_TIM2_Init(void); static void MX_TIM3_Init(void); - +static void MX_TIM1_Init(void); +static void MX_TIM10_Init(void); +static void MX_TIM11_Init(void); /* USER CODE BEGIN PFP */ //#define PUTCHAR_PROTOTYPE int __io_putchar(int ch) /* USER CODE END PFP */ @@ -77,20 +82,7 @@ int _write(int fd, char * ptr, int len) HAL_UART_Transmit(&huart1, (uint8_t *) ptr, len, HAL_MAX_DELAY); return len; } -/** - * @brief Retargets the C library printf function to the USART. - * None - * @retval None - */ -//PUTCHAR_PROTOTYPE -//{ -// /* Place your implementation of fputc here */ -// /* e.g. write a character to the USART1 and Loop until the end of transmission */ -// HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); -// -// return ch; -//} -/* USER CODE END 0 */ +/* USER CODE END 0 */ /** * @brief The application entry point. @@ -107,8 +99,7 @@ int main(void) /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - - HAL_Init(); + HAL_Init(); /* USER CODE BEGIN Init */ @@ -130,6 +121,9 @@ int main(void) MX_USART1_UART_Init(); MX_TIM2_Init(); MX_TIM3_Init(); + MX_TIM1_Init(); + MX_TIM10_Init(); + MX_TIM11_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ @@ -256,7 +250,7 @@ static void MX_I2C2_Init(void) /* USER CODE END I2C2_Init 1 */ hi2c2.Instance = I2C2; - hi2c2.Init.ClockSpeed = 100000; + hi2c2.Init.ClockSpeed = 400000; hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c2.Init.OwnAddress1 = 0; hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; @@ -308,6 +302,52 @@ static void MX_I2C3_Init(void) } +/** + * @brief TIM1 Initialization Function + * @param None + * @retval None + */ +static void MX_TIM1_Init(void) +{ + + /* USER CODE BEGIN TIM1_Init 0 */ + + /* USER CODE END TIM1_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM1_Init 1 */ + + /* USER CODE END TIM1_Init 1 */ + htim1.Instance = TIM1; + htim1.Init.Prescaler = 49; + htim1.Init.CounterMode = TIM_COUNTERMODE_UP; + htim1.Init.Period = 65535; + htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim1.Init.RepetitionCounter = 0; + htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim1) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM1_Init 2 */ + + /* USER CODE END TIM1_Init 2 */ + +} + /** * @brief TIM2 Initialization Function * @param None @@ -467,6 +507,68 @@ static void MX_TIM4_Init(void) } +/** + * @brief TIM10 Initialization Function + * @param None + * @retval None + */ +static void MX_TIM10_Init(void) +{ + + /* USER CODE BEGIN TIM10_Init 0 */ + + /* USER CODE END TIM10_Init 0 */ + + /* USER CODE BEGIN TIM10_Init 1 */ + + /* USER CODE END TIM10_Init 1 */ + htim10.Instance = TIM10; + htim10.Init.Prescaler = 0; + htim10.Init.CounterMode = TIM_COUNTERMODE_UP; + htim10.Init.Period = 50000; + htim10.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim10.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim10) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM10_Init 2 */ + + /* USER CODE END TIM10_Init 2 */ + +} + +/** + * @brief TIM11 Initialization Function + * @param None + * @retval None + */ +static void MX_TIM11_Init(void) +{ + + /* USER CODE BEGIN TIM11_Init 0 */ + + /* USER CODE END TIM11_Init 0 */ + + /* USER CODE BEGIN TIM11_Init 1 */ + + /* USER CODE END TIM11_Init 1 */ + htim11.Instance = TIM11; + htim11.Init.Prescaler = 1; + htim11.Init.CounterMode = TIM_COUNTERMODE_UP; + htim11.Init.Period = 50000; + htim11.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim11.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim11) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM11_Init 2 */ + + /* USER CODE END TIM11_Init 2 */ + +} + /** * @brief USART1 Initialization Function * @param None diff --git a/Core/Src/stm32f4xx_hal_msp.c b/Core/Src/stm32f4xx_hal_msp.c index 1e574fc..7087ec1 100644 --- a/Core/Src/stm32f4xx_hal_msp.c +++ b/Core/Src/stm32f4xx_hal_msp.c @@ -168,19 +168,19 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) PB10 ------> I2C2_SCL PB3 ------> I2C2_SDA */ - GPIO_InitStruct.Pin = GYRO_SCL_Pin; + GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF4_I2C2; - HAL_GPIO_Init(GYRO_SCL_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - GPIO_InitStruct.Pin = GYRO_SDA_Pin; + GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF9_I2C2; - HAL_GPIO_Init(GYRO_SDA_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Peripheral clock enable */ __HAL_RCC_I2C2_CLK_ENABLE(); @@ -243,9 +243,9 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c) PB10 ------> I2C2_SCL PB3 ------> I2C2_SDA */ - HAL_GPIO_DeInit(GYRO_SCL_GPIO_Port, GYRO_SCL_Pin); + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10); - HAL_GPIO_DeInit(GYRO_SDA_GPIO_Port, GYRO_SDA_Pin); + HAL_GPIO_DeInit(GPIOB, GPIO_PIN_3); /* USER CODE BEGIN I2C2_MspDeInit 1 */ @@ -274,6 +274,50 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c) } +/** +* @brief TIM_Base MSP Initialization +* This function configures the hardware resources used in this example +* @param htim_base: TIM_Base handle pointer +* @retval None +*/ +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) +{ + if(htim_base->Instance==TIM1) + { + /* USER CODE BEGIN TIM1_MspInit 0 */ + + /* USER CODE END TIM1_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM1_CLK_ENABLE(); + /* USER CODE BEGIN TIM1_MspInit 1 */ + + /* USER CODE END TIM1_MspInit 1 */ + } + else if(htim_base->Instance==TIM10) + { + /* USER CODE BEGIN TIM10_MspInit 0 */ + + /* USER CODE END TIM10_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM10_CLK_ENABLE(); + /* USER CODE BEGIN TIM10_MspInit 1 */ + + /* USER CODE END TIM10_MspInit 1 */ + } + else if(htim_base->Instance==TIM11) + { + /* USER CODE BEGIN TIM11_MspInit 0 */ + + /* USER CODE END TIM11_MspInit 0 */ + /* Peripheral clock enable */ + __HAL_RCC_TIM11_CLK_ENABLE(); + /* USER CODE BEGIN TIM11_MspInit 1 */ + + /* USER CODE END TIM11_MspInit 1 */ + } + +} + /** * @brief TIM_Encoder MSP Initialization * This function configures the hardware resources used in this example @@ -386,6 +430,50 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) } } +/** +* @brief TIM_Base MSP De-Initialization +* This function freeze the hardware resources used in this example +* @param htim_base: TIM_Base handle pointer +* @retval None +*/ +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) +{ + if(htim_base->Instance==TIM1) + { + /* USER CODE BEGIN TIM1_MspDeInit 0 */ + + /* USER CODE END TIM1_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM1_CLK_DISABLE(); + /* USER CODE BEGIN TIM1_MspDeInit 1 */ + + /* USER CODE END TIM1_MspDeInit 1 */ + } + else if(htim_base->Instance==TIM10) + { + /* USER CODE BEGIN TIM10_MspDeInit 0 */ + + /* USER CODE END TIM10_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM10_CLK_DISABLE(); + /* USER CODE BEGIN TIM10_MspDeInit 1 */ + + /* USER CODE END TIM10_MspDeInit 1 */ + } + else if(htim_base->Instance==TIM11) + { + /* USER CODE BEGIN TIM11_MspDeInit 0 */ + + /* USER CODE END TIM11_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM11_CLK_DISABLE(); + /* USER CODE BEGIN TIM11_MspDeInit 1 */ + + /* USER CODE END TIM11_MspDeInit 1 */ + } + +} + /** * @brief TIM_Encoder MSP De-Initialization * This function freeze the hardware resources used in this example diff --git a/Library/Src/MPU6050.c b/Library/Src/MPU6050.c index b1a82c3..5210fa0 100644 --- a/Library/Src/MPU6050.c +++ b/Library/Src/MPU6050.c @@ -94,6 +94,6 @@ int gyroUpdate(void) angle_z += ((angle_rate + last_angle_rate) * timeDifference) / 2.0f; last_angle_rate = angle_rate; - printf("Angle Z: %f\r\n", angle_z); +// printf("Angle Z: %f\r\n", angle_z); return 0; } diff --git a/Program/Src/entry.cpp b/Program/Src/entry.cpp index 767082b..cef92b4 100644 --- a/Program/Src/entry.cpp +++ b/Program/Src/entry.cpp @@ -47,7 +47,7 @@ void print(const char *str){ } int greymatter(void) { - initialization_block(); +// initialization_block(); // HAL_Delay(1000); // disp_state = DEFAULT; // @@ -80,8 +80,9 @@ int greymatter(void) { // print("a\n\r"); // printf("%lu \n\r",r_position); // printf("%u \n\r",r_position); -// HAL_Delay(5); - finishMove(STRAIGHT_RUN, 100); + printf("Hello"); + HAL_Delay(50); +// finishMove(STRAIGHT_RUN, 100); // setLeftWheel(1); // setRightWheel(1); @@ -92,7 +93,7 @@ int greymatter(void) { int initialization_block(void) { // ALL_LED_ON; - TIM1_START; ////////////////// CRUCIAL PART DON"T OFFFFFFFFFFFFFFFF +// TIM1_START; ////////////////// CRUCIAL PART DON"T OFFFFFFFFFFFFFFFF /////////////////////////// TIM6_IT_START; motorInit(); @@ -103,24 +104,24 @@ int initialization_block(void) // ALL_LED_OFF; HAL_Delay(1000); - gyroCalibration(); +// gyroCalibration(); // disp_state = DEFAULT; - TIM10_IT_START; +// TIM10_IT_START; // TIM14_IT_START; return 0; } - void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { - if (htim == &htim11) - ; - else if (htim == &htim10) - gyroUpdate(), - readSensor(); +// if (htim == &htim11) +// ; + if (htim == &htim10) + gyroUpdate(); +// readSensor(); // else if (htim == &htim6) // displayUpdate(); - } +} // // void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) //{ diff --git a/kitro.ioc b/kitro.ioc index ed70d1c..05341a2 100644 --- a/kitro.ioc +++ b/kitro.ioc @@ -9,7 +9,7 @@ CAD.formats= CAD.pinconfig= CAD.provider= File.Version=6 -I2C2.I2C_Mode=I2C_Standard +I2C2.I2C_Mode=I2C_Fast I2C2.IPParameters=I2C_Mode I2C3.I2C_Mode=I2C_Fast I2C3.IPParameters=I2C_Mode From 88b2b6dead50fee2db9afd5519de104d32b34a5e Mon Sep 17 00:00:00 2001 From: Sundarbavan Date: Fri, 27 Sep 2024 09:25:40 +0530 Subject: [PATCH 6/7] gyro senstivity changed --- .cproject | 4 ++-- Core/Src/main.c | 27 ++++++++++++++++++++------- Library/Src/MPU6050.c | 6 +++--- Program/Src/entry.cpp | 22 ++++++++++++++-------- kitro.ioc | 37 +++++++++++++++++++++++++------------ 5 files changed, 64 insertions(+), 32 deletions(-) diff --git a/.cproject b/.cproject index 68ed0ee..f156b46 100644 --- a/.cproject +++ b/.cproject @@ -24,7 +24,7 @@