Guest User

Untitled

a guest
Oct 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. /*
  2. ******************************************************************************
  3. File: main.c
  4. Info: Generated by Atollic TrueSTUDIO(R) 9.1.0 2018-10-20
  5.  
  6. The MIT License (MIT)
  7. Copyright (c) 2018 STMicroelectronics
  8.  
  9. Permission is hereby granted, free of charge, to any person obtaining a copy
  10. of this software and associated documentation files (the "Software"), to deal
  11. in the Software without restriction, including without limitation the rights
  12. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. copies of the Software, and to permit persons to whom the Software is
  14. furnished to do so, subject to the following conditions:
  15.  
  16. The above copyright notice and this permission notice shall be included in all
  17. copies or substantial portions of the Software.
  18.  
  19. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. SOFTWARE.
  26.  
  27. ******************************************************************************
  28. */
  29.  
  30. /* Includes */
  31. #include "stm32f0xx.h"
  32.  
  33. /* Private macro */
  34. /* Private variables */
  35. /* Private function prototypes */
  36. /* Private functions */
  37.  
  38. /**
  39. **===========================================================================
  40. **
  41. ** Abstract: main program
  42. **
  43. **===========================================================================
  44. */
  45. #include <stdio.h>
  46.  
  47. int main() {
  48.  
  49. /* Dette Program bruger STM32F030x8 microprocessoren fra St.com
  50. * Prrogrammet er udviklet på Atollic True Studio, som ST.com
  51. * har købt. De stiller den fulde version til rådighed for
  52. * udviklere der bruger deres produkter
  53. * */
  54.  
  55.  
  56.  
  57. // ADC calibration
  58. ADC1->CR &= ~ADC_CR_ADEN; // sikre at ADC_Enable flaget er resat
  59. ADC1->CR |= ADC_CR_ADCAL; // Calibrer_Enable flaget er sat
  60.  
  61. while ((ADC1->CR & ADC_CR_ADCAL) != 0) { // sålænge bit ADC_CR_ADCAL ikke er 0
  62. // er calibreringen ikke færdig
  63.  
  64. /* Her kan man med fordel sættet en led der
  65. slukker når calibreringen er færdig. ellers
  66. har man ingen indikation om at calibreringen
  67. fortsætter i lang tid */
  68. }
  69.  
  70. // Select a clock source
  71.  
  72. RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
  73. RCC->CR2 |= RCC_CR2_HSI14ON; // Valg af clock HSI14ON er default oscillator for ADC
  74.  
  75. while((RCC->CR2 & RCC_CR2_HSI14RDY) == 0) { // Sålænge RCC_CR2_HSI14RDY
  76. // ikke er sat, er clock ikke konfigureret
  77.  
  78. }
  79.  
  80. ADC1->CFGR2 |= ADC_CFGR2_CKMODE; // sætter ADCén til synkron clock mode
  81.  
  82. // ADC enable
  83. ADC->CCR |= ADC_CCR_TSEN; // sætter adc til at modtage data fra temperatur føleren
  84. ADC1->CR |= ADC_CR_ADEN; // enabler ADC
  85.  
  86. while((ADC1->ISR & ADC_ISR_ADRDY)== 0) {
  87.  
  88. }
  89.  
  90. ADC1->SMPR |= ADC_SMPR_SMP_0 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_2; // langsomste sampling time vælges 239.5
  91. // ADC clock cycles
  92.  
  93. ADC1->CHSELR |= ADC_CHSELR_CHSEL16; // default channel for temperatur føler
  94.  
  95. ADC->CCR |= ADC_CCR_VREFEN;
  96.  
  97. while(1) {
  98. // Start conversion
  99. ADC1->CR |= ADC_CR_ADSTART; // bit sættes til påbegyndelse af konvertering
  100.  
  101. while((ADC1->ISR & ADC_ISR_EOC) == 0) {} // så længe konverteringen er i gang venter vi
  102.  
  103. }
  104. printf("%d\n",ADC1->DR); // data udskrives til standard output (skærm)
  105. }
Add Comment
Please, Sign In to add comment