Posts

Showing posts from 2022

Parking sensor by using STM32CubeIDE and HC-SR04

Image
Sources :  1- www.kaynak1.com 2-  www.kaynak2.com The hardwares that I used :  STM32F103C8 ST-LΔ°NK V2 HC-SR04 ULTRASONIC SENSOR LCD 16 X 2                                         πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€ πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€ main.c file :  #include "main.h" #include "i2c-lcd.h" I2C_HandleTypeDef hi2c1; TIM_HandleTypeDef htim1; void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_I2C1_Init(void); static void MX_TIM1_Init(void); void delay (uint16_t time) { __HAL_TIM_SET_COUNTER(&htim1, 0); while (__HAL_TIM_GET_COUNTER (&htim1) < time); } uint32_t IC_Val1 = 0; uint32_t IC_Val2 = 0; uint32_t Difference = 0; uint8_t Is_First_Captured = 0;  // is the first value captured ? uint8_t Distance  = 0; #define TRIG_PIN GPIO_PIN_9 #define TRIG_PORT GPIOA // Let's write the callback function void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) { if (htim->Channel == HAL_TIM_ACTIVE

Interface LCD 16x2 with STM32 by using STM32CubeIDE

Image
πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€ πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€πŸ˜€ main.c dosyasΔ± :  #include "main.h" void SystemClock_Config(void); static void MX_GPIO_Init(void); /* USER CODE BEGIN PFP */ #include "LCD.h" #include <stdio.h> /* USER CODE END PFP */ int main(void) {   HAL_Init();   MX_GPIO_Init();   /* USER CODE BEGIN 2 */   lcd_init(_LCD_4BIT, _LCD_FONT_5x8, _LCD_2LINE);   lcd_print(1, 1, "Merhaba"); //1.satΔ±rΔ±n 1. sΓΌtunu   lcd_print(2, 1, "DΓΌnya"); //2. satΔ±rΔ±n 1. sΓΌtunu   /* USER CODE END 2 */ char yazi[16] = " " ;//yazi isminde, char tipinde 16 elemanΔ± olan bir dizi int i = 0; HAL_Delay(2500); lcd_clear();    /* Infinite loop */   /* USER CODE BEGIN WHILE */   while (1)   {      /* USER CODE END WHILE */ i++; lcd_print(1, 1, "SayΔ± : "); sprintf(yazi,"%d",i);  lcd_print(2, 1, yazi); HAL_Delay(1000); lcd_clear();      /* USER CODE BEGIN 3 */   }   /* USER CODE END 3 */ } void Syst

LED blinking project with STM32

Image
Hardwares :   STM32F103C8Tx , ST-LinkV2  STM32CubeIDE  Pinout&Configuration :  In the System/Core settings, only Debug = Serial Wire is selected, while in the RCC, High Speed Clock(HSE) = Crystal/Ceramic Resonator is selected. The PC13 pin on the microprocessor can be selected GPIO_Output and given LED or any other different name as the Label name. Clock Configuration settings can be made as follows : In the Project Manager  section, only theproject is given a name, STM32CubeID is selected as the Toolchain/IDE. After this step go to the Code Generator section on the left side and select second option from the top " Copy only the necessary library files ". Now it will generate the code when saved with CTRL+S keys. Or you can also generate the code using the " Device Configuration Tool Code Generation " button with a yellow icon in the upper-left menu bar.Now our main.c file will be formed. We'll write several codes here :  We will write the code that will a