![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
lightradar
Fork of Laster_Radar_test by
main.cpp
- Committer:
- chrish
- Date:
- 2015-11-20
- Revision:
- 1:ee1640b8be78
- Parent:
- 0:36109edfc712
- Child:
- 2:4d8ef1799adc
File content as of revision 1:ee1640b8be78:
#include "mbed.h" #include "TextLCD.h" #include "cdef.h" #include "I2C.h" DigitalOut myled(LED1); TextLCD display(PA_9, PC_7, PB_5, PB_4, PB_10, PA_8, TextLCD::LCD16x2); /****************************************************** * void vInitSystemClock(void) * Purpose: * Initialisiert Clocksystem HSI,HSE,PLL, Setzt HSE als * Taktquelle und PLL für SystemClock = 84 Mhz. * Aktiviert Clock Secuity System für fall das HSE versagt * Parameter: * -Keine Parameter- * Return value: * -Keine Return Values * Interrupt: * Im HSE Ausfall wird RCC Interrupt aufgerufen *******************************************************/ void vInitSystemClock(void) { /***Flash wait states 2 */ FLASH->ACR |= Bit1 ; /** Enable the High Speed Internal Clock and wait for HSI to be stable.*/ RCC->CR |= RCC_CR_HSION; while (!(RCC->CR & RCC_CR_HSIRDY)); RCC->CFGR = 0x00000000; // HSI enabled and used as System Clock. No Clock Division. while( (RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI ); // WAITING HSI IS SYSTEM CLOCK /**ENABLE HSE CLOCK and wait for HSE to be stable */ RCC->CR |= RCC_CR_HSEON ; while( (RCC->CR & RCC_CR_HSERDY) == 0); RCC->CR &= ~(RCC_CR_PLLI2SON | RCC_CR_CSSON | RCC_CR_PLLON) ; // Turn off PLL and CSS (clock security system). while(RCC->CR & RCC_CR_PLLRDY); // WAITING PLL OF /** Disable all clock generated interrupts. */ RCC->CIR = 0x00000000; RCC->PLLCFGR = 0x20000000; // SETZE PLL COMFIG REGISTERINHALT KOMPLETT AUF 0 /** SETTINGS FOR PLL OVER HSE 8Mhz **/ RCC->PLLCFGR |= (8 << 0) // 16 / 8 = 2MHz |(168 << 6) // 2 * 168 = 336MHz |(1 << 16) // 336MHz / 4 = 84MHz (0x01 corresponds to /4) |(RCC_PLLCFGR_PLLSRC_HSI) // HSI selected. |(7 << 24); // 336Mhz / 7 = 48MHz RCC->CFGR |= RCC_CFGR_PPRE1_DIV2; // Low speed peripheral clock setup set to 42Mhz. (84Mhz / 2) RCC->CR |= (RCC_CR_PLLON); // Start the PLL clock. while (!(RCC->CR & RCC_CR_PLLRDY)); // Wait for the PLL to start. RCC->CFGR &= ~(RCC_CFGR_SW); // SET PLL AS SYSTEM CLOCK RCC->CFGR |= RCC_CFGR_SW_PLL; while ((RCC->CFGR & RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL); // Wait for configuration to take place. /** ENABLE CLOCK SECUITY SYSTEM */ RCC->CR |= Bit19 ; NVIC_EnableIRQ(RCC_IRQn); } int main() { byte arr[2]; display.cls(); // vInitSystemClock(); display.printf("Hallo\n"); // PRESSURE_vInit(); while(1) { myled = 1; // LED is ON wait(0.1); // 200 ms // I2C_write(0xC4, 0x00, 0x04); myled = 0; // LED is OFF wait(0.3); // 1 sec // I2C_read(0xC4,0xC5, 0x8f, 2, arr); display.cls(); //display.printf("Distanz:%d cm\n", ((arr[0]<<8) | arr[1]) ); display.printf("Distanz: cm\n" ); } }