Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ******************************************************************************
- File: main.c
- Info: Generated by Atollic TrueSTUDIO(R) 9.1.0 2018-10-20
- The MIT License (MIT)
- Copyright (c) 2018 STMicroelectronics
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- ******************************************************************************
- */
- /* Includes */
- #include "stm32f0xx.h"
- /* Private macro */
- /* Private variables */
- /* Private function prototypes */
- /* Private functions */
- /**
- **===========================================================================
- **
- ** Abstract: main program
- **
- **===========================================================================
- */
- #include <stdio.h>
- int main() {
- /* Dette Program bruger STM32F030x8 microprocessoren fra St.com
- * Prrogrammet er udviklet på Atollic True Studio, som ST.com
- * har købt. De stiller den fulde version til rådighed for
- * udviklere der bruger deres produkter
- * */
- // ADC calibration
- ADC1->CR &= ~ADC_CR_ADEN; // sikre at ADC_Enable flaget er resat
- ADC1->CR |= ADC_CR_ADCAL; // Calibrer_Enable flaget er sat
- while ((ADC1->CR & ADC_CR_ADCAL) != 0) { // sålænge bit ADC_CR_ADCAL ikke er 0
- // er calibreringen ikke færdig
- /* Her kan man med fordel sættet en led der
- slukker når calibreringen er færdig. ellers
- har man ingen indikation om at calibreringen
- fortsætter i lang tid */
- }
- // Select a clock source
- RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
- RCC->CR2 |= RCC_CR2_HSI14ON; // Valg af clock HSI14ON er default oscillator for ADC
- while((RCC->CR2 & RCC_CR2_HSI14RDY) == 0) { // Sålænge RCC_CR2_HSI14RDY
- // ikke er sat, er clock ikke konfigureret
- }
- ADC1->CFGR2 |= ADC_CFGR2_CKMODE; // sætter ADCén til synkron clock mode
- // ADC enable
- ADC->CCR |= ADC_CCR_TSEN; // sætter adc til at modtage data fra temperatur føleren
- ADC1->CR |= ADC_CR_ADEN; // enabler ADC
- while((ADC1->ISR & ADC_ISR_ADRDY)== 0) {
- }
- ADC1->SMPR |= ADC_SMPR_SMP_0 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_2; // langsomste sampling time vælges 239.5
- // ADC clock cycles
- ADC1->CHSELR |= ADC_CHSELR_CHSEL16; // default channel for temperatur føler
- ADC->CCR |= ADC_CCR_VREFEN;
- while(1) {
- // Start conversion
- ADC1->CR |= ADC_CR_ADSTART; // bit sættes til påbegyndelse af konvertering
- while((ADC1->ISR & ADC_ISR_EOC) == 0) {} // så længe konverteringen er i gang venter vi
- }
- printf("%d\n",ADC1->DR); // data udskrives til standard output (skærm)
- }
Add Comment
Please, Sign In to add comment