/** ****************************************************************************** * @file : main.c * @author : Auto-generated by STM32CubeIDE * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ #include "stdint.h" #include "stdio.h" #include "string.h" #include "main.h" #include "timer.h" #include "analog.h" #include "i2c.h" #include "stm32_adafruit_lcd.h" #include "vl6180x.h" uint32_t SystemCoreClock=8000000; // Variable Systemtakt int16_t count=0; uint8_t str_out[32]; int main(void) { init_clock(); // Systemtakt auf 72MHz Init_Timer1(); // Timer 1 Encoder Auswertung Init_Timer3(); // Timer 3 4 Kanal PWM Init_Timer4(); // Timer 4 Encoder Auswertung Init_Timer6(); // Timer 6 einschalten für zyklischen Interrupt Init_Timer7(); // Timer 7 einschalten für Delay Funktionen Start_ADC_Complete(); BSP_LCD_Init(); BSP_LCD_SetFont(&Font20); i2c_init(I2C1, 0, 1, 36000000); uint8_t send_bufer[]={0}; uint8_t receive_buffer[5]; VL6180x_init(I2C1,0x50); TIM3->CCR1=205; TIM3->CCR2=409; TIM3->CCR3=613; TIM3->CCR4=818; while(1) { if(Bit4Hz) { count=TIM1->CNT; sprintf(str_out,"%5i",count); BSP_LCD_DisplayStringAt(0, 0, str_out, LEFT_MODE); count=TIM4->CNT; sprintf(str_out,"%5i",count); BSP_LCD_DisplayStringAt(0, 20, str_out, LEFT_MODE); Bit4Hz=0; } } } // Necessary wait states for Flash for high speeds // Umschalten auf 72MHz Takt mittels ext. 8MHz Quarz und PLL void init_clock(void) { FLASH->ACR = FLASH_ACR_PRFTBE | 0b010; SET_BIT(RCC->CR, RCC_CR_HSION); // HSI Oscillator einschalten while(!READ_BIT(RCC->CR, RCC_CR_HSIRDY)) {} // Warten bis HSI Oscillator bereit MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_HSI); // Umschalten zu HSI oscillator while ((RCC->CFGR & RCC_CFGR_SWS_Msk) != RCC_CFGR_SWS_HSI) {} // Warten bis Umschalten erfolgt ist CLEAR_BIT(RCC->CR, RCC_CR_PLLON); // PLL abschalten while(READ_BIT(RCC->CR, RCC_CR_PLLRDY)) {} // Warten bis PLL gestoppt MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, FLASH_ACR_LATENCY_1); // Flash 2 Wait States SET_BIT(RCC->CR, RCC_CR_HSEON); // Externen HSE Oscillator einschalten while(!READ_BIT(RCC->CR, RCC_CR_HSERDY)) {} // Warten bis HSE Oscillator bereit WRITE_REG(RCC->CFGR, RCC_CFGR_PLLSRC + RCC_CFGR_PLLMULL9 + RCC_CFGR_PPRE1_DIV2); // 72 MHz durch 8 MHz HSE oscillator mit 9x PLL, Lowspeed I/O läuft auf 36 MHz SET_BIT(RCC->CR, RCC_CR_PLLON); // PLL Einschalten while(!READ_BIT(RCC->CR, RCC_CR_PLLRDY)) {} // Warte bis PLL bereit MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_CFGR_SW_PLL); // PLL als Taktquelle SystemCoreClock=72000000; // Variable updaten CLEAR_BIT(RCC->CR, RCC_CR_HSION); // HSI Oscillator abschalten }