lightradar

Dependencies:   TextLCD mbed

Fork of Laster_Radar_test by Christopher H

Committer:
chrish
Date:
Mon Nov 23 07:54:55 2015 +0000
Revision:
2:4d8ef1799adc
Parent:
1:ee1640b8be78
Example Programm Disp + Bosch Sensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chrish 0:36109edfc712 1 #include "mbed.h"
chrish 0:36109edfc712 2 #include "TextLCD.h"
chrish 0:36109edfc712 3 #include "cdef.h"
chrish 0:36109edfc712 4 #include "I2C.h"
chrish 0:36109edfc712 5 DigitalOut myled(LED1);
chrish 0:36109edfc712 6 TextLCD display(PA_9, PC_7, PB_5, PB_4, PB_10, PA_8, TextLCD::LCD16x2);
chrish 2:4d8ef1799adc 7 Serial pc(SERIAL_TX, SERIAL_RX);
chrish 2:4d8ef1799adc 8
chrish 2:4d8ef1799adc 9
chrish 0:36109edfc712 10
chrish 0:36109edfc712 11 /******************************************************
chrish 0:36109edfc712 12 * void vInitSystemClock(void)
chrish 0:36109edfc712 13 * Purpose:
chrish 0:36109edfc712 14 * Initialisiert Clocksystem HSI,HSE,PLL, Setzt HSE als
chrish 0:36109edfc712 15 * Taktquelle und PLL für SystemClock = 84 Mhz.
chrish 0:36109edfc712 16 * Aktiviert Clock Secuity System für fall das HSE versagt
chrish 0:36109edfc712 17 * Parameter:
chrish 0:36109edfc712 18 * -Keine Parameter-
chrish 0:36109edfc712 19 * Return value:
chrish 0:36109edfc712 20 * -Keine Return Values
chrish 0:36109edfc712 21 * Interrupt:
chrish 0:36109edfc712 22 * Im HSE Ausfall wird RCC Interrupt aufgerufen
chrish 0:36109edfc712 23 *******************************************************/
chrish 0:36109edfc712 24 void vInitSystemClock(void)
chrish 0:36109edfc712 25 {
chrish 0:36109edfc712 26
chrish 0:36109edfc712 27 /***Flash wait states 2 */
chrish 0:36109edfc712 28 FLASH->ACR |= Bit1 ;
chrish 0:36109edfc712 29 /** Enable the High Speed Internal Clock and wait for HSI to be stable.*/
chrish 0:36109edfc712 30 RCC->CR |= RCC_CR_HSION;
chrish 0:36109edfc712 31 while (!(RCC->CR & RCC_CR_HSIRDY));
chrish 0:36109edfc712 32 RCC->CFGR = 0x00000000; // HSI enabled and used as System Clock. No Clock Division.
chrish 0:36109edfc712 33 while( (RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI ); // WAITING HSI IS SYSTEM CLOCK
chrish 0:36109edfc712 34 /**ENABLE HSE CLOCK and wait for HSE to be stable */
chrish 0:36109edfc712 35 RCC->CR |= RCC_CR_HSEON ;
chrish 0:36109edfc712 36 while( (RCC->CR & RCC_CR_HSERDY) == 0);
chrish 0:36109edfc712 37 RCC->CR &= ~(RCC_CR_PLLI2SON
chrish 0:36109edfc712 38 | RCC_CR_CSSON
chrish 0:36109edfc712 39 | RCC_CR_PLLON)
chrish 0:36109edfc712 40 ; // Turn off PLL and CSS (clock security system).
chrish 0:36109edfc712 41 while(RCC->CR & RCC_CR_PLLRDY); // WAITING PLL OF
chrish 0:36109edfc712 42 /** Disable all clock generated interrupts. */
chrish 0:36109edfc712 43 RCC->CIR = 0x00000000;
chrish 0:36109edfc712 44 RCC->PLLCFGR = 0x20000000; // SETZE PLL COMFIG REGISTERINHALT KOMPLETT AUF 0
chrish 0:36109edfc712 45 /** SETTINGS FOR PLL OVER HSE 8Mhz **/
chrish 0:36109edfc712 46 RCC->PLLCFGR |= (8 << 0) // 16 / 8 = 2MHz
chrish 0:36109edfc712 47 |(168 << 6) // 2 * 168 = 336MHz
chrish 0:36109edfc712 48 |(1 << 16) // 336MHz / 4 = 84MHz (0x01 corresponds to /4)
chrish 0:36109edfc712 49 |(RCC_PLLCFGR_PLLSRC_HSI) // HSI selected.
chrish 0:36109edfc712 50 |(7 << 24); // 336Mhz / 7 = 48MHz
chrish 0:36109edfc712 51 RCC->CFGR |= RCC_CFGR_PPRE1_DIV2; // Low speed peripheral clock setup set to 42Mhz. (84Mhz / 2)
chrish 0:36109edfc712 52 RCC->CR |= (RCC_CR_PLLON); // Start the PLL clock.
chrish 0:36109edfc712 53 while (!(RCC->CR & RCC_CR_PLLRDY)); // Wait for the PLL to start.
chrish 0:36109edfc712 54 RCC->CFGR &= ~(RCC_CFGR_SW); // SET PLL AS SYSTEM CLOCK
chrish 0:36109edfc712 55 RCC->CFGR |= RCC_CFGR_SW_PLL;
chrish 0:36109edfc712 56 while ((RCC->CFGR & RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL); // Wait for configuration to take place.
chrish 0:36109edfc712 57 /** ENABLE CLOCK SECUITY SYSTEM */
chrish 0:36109edfc712 58 RCC->CR |= Bit19 ;
chrish 0:36109edfc712 59 NVIC_EnableIRQ(RCC_IRQn);
chrish 0:36109edfc712 60
chrish 0:36109edfc712 61 }
chrish 0:36109edfc712 62
chrish 0:36109edfc712 63
chrish 0:36109edfc712 64
chrish 0:36109edfc712 65
chrish 0:36109edfc712 66
chrish 0:36109edfc712 67
chrish 0:36109edfc712 68
chrish 0:36109edfc712 69
chrish 2:4d8ef1799adc 70 int main()
chrish 2:4d8ef1799adc 71 {
chrish 0:36109edfc712 72 display.cls();
chrish 2:4d8ef1799adc 73 vInitSystemClock();
chrish 2:4d8ef1799adc 74 PRESSURE_vInit();
chrish 2:4d8ef1799adc 75 PRESSURE_vget_CALDATA();
chrish 2:4d8ef1799adc 76 PRESSURE_vwrite_EEPROM_REGISTER(BMP180_register_CONTROLL,0x2E);
chrish 2:4d8ef1799adc 77 wait(0.2);
chrish 2:4d8ef1799adc 78 PRESSURE_DATA.i_RAW_TEMPERATUR = PRESSURE_vread_EEPROM_REGISTER(BMP180_register_ADC_ERG);
chrish 2:4d8ef1799adc 79 wait(0.1);
chrish 2:4d8ef1799adc 80 PRESSURE_vwrite_EEPROM_REGISTER(BMP180_register_CONTROLL,0xB4); // HIGH RESULUTUIN
chrish 2:4d8ef1799adc 81 wait(0.1);
chrish 2:4d8ef1799adc 82 PRESSURE_DATA.i_RAW_PRESSURE = ( (PRESSURE_vread_EEPROM_REGISTER(BMP180_register_ADC_ERG))<<8 ) >>(8-BMP180_oss_high_resulution );
chrish 2:4d8ef1799adc 83 PRESSURE_vCALCULATE_TEMPANDPRESSURE();
chrish 2:4d8ef1799adc 84
chrish 2:4d8ef1799adc 85 while(1) {
chrish 0:36109edfc712 86 myled = 1; // LED is ON
chrish 2:4d8ef1799adc 87 PRESSURE_vwrite_EEPROM_REGISTER(BMP180_register_CONTROLL,0x2E);
chrish 2:4d8ef1799adc 88 wait(0.2);
chrish 2:4d8ef1799adc 89 PRESSURE_DATA.i_RAW_TEMPERATUR = PRESSURE_vread_EEPROM_REGISTER(BMP180_register_ADC_ERG);
chrish 2:4d8ef1799adc 90 PRESSURE_vwrite_EEPROM_REGISTER(BMP180_register_CONTROLL,0xB4); // HIGH RESULUTUIN
chrish 2:4d8ef1799adc 91 wait(0.1);
chrish 2:4d8ef1799adc 92 PRESSURE_DATA.i_RAW_PRESSURE = ( (PRESSURE_vread_EEPROM_REGISTER(BMP180_register_ADC_ERG))<<8 ) >>(8-BMP180_oss_high_resulution );
chrish 2:4d8ef1799adc 93 PRESSURE_vCALCULATE_TEMPANDPRESSURE();
chrish 0:36109edfc712 94 myled = 0; // LED is OFF
chrish 2:4d8ef1799adc 95 wait(0.1); // 1 sec
chrish 2:4d8ef1799adc 96 display.cls();
chrish 2:4d8ef1799adc 97 display.printf("TEMP:%d.%d C\n", (PRESSURE_DATA.i_TEMPERATURE)/10, (PRESSURE_DATA.i_TEMPERATURE)%10 );
chrish 2:4d8ef1799adc 98 display.locate(0,1);
chrish 2:4d8ef1799adc 99 display.printf("Press: %d PA\n",PRESSURE_DATA.i_PRESSURE );
chrish 2:4d8ef1799adc 100 pc.printf("TestPrintPCDisplay\n");
chrish 0:36109edfc712 101 }
chrish 0:36109edfc712 102 }