Browse Source

ADC don't work.

Vladimir N. Shilov 1 year ago
parent
commit
fc46f616bd
1 changed files with 20 additions and 11 deletions
  1. 20 11
      main.c

+ 20 - 11
main.c

@@ -70,18 +70,19 @@ int main(void) {
   /*
   /*
    * Creates the blinker thread.
    * Creates the blinker thread.
    */
    */
-  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+  //chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
 
 
   /* Activates the ADC1 driver and the temperature sensor. */
   /* Activates the ADC1 driver and the temperature sensor. */
   adcStart(&ADCD1, NULL);
   adcStart(&ADCD1, NULL);
 
 
   /* Starting GPT3 driver, it is used for triggering the ADC. */
   /* Starting GPT3 driver, it is used for triggering the ADC. */
   gptStart(&GPTD1, &gptcfg1);
   gptStart(&GPTD1, &gptcfg1);
-  GPTD1.tim->CCMR1 = 100; // 1Mhz/100=10kHz=100 us
-  GPTD1.tim->EGR = STM32_TIM_EGR_CC1G; //  Capture/Compare 1 generation
-  GPTD1.tim->CCMR1= (STM32_TIM_CCMR1_OC1CE | STM32_TIM_CCMR1_OC1M(3));
-  GPTD1.tim->CCER = STM32_TIM_CCER_CC1E;
+//  GPTD1.tim->CCMR1 = 100; // 1Mhz/100=10kHz=100 us
+//  GPTD1.tim->EGR = STM32_TIM_EGR_CC1G; //  Capture/Compare 1 generation
+//  GPTD1.tim->CCMR1= (STM32_TIM_CCMR1_OC1CE | STM32_TIM_CCMR1_OC1M(3));
+//  GPTD1.tim->CCER = STM32_TIM_CCER_CC1E;
   //?GPTD1.tim->BDTR = STM32_TIM_BDTR_MOE;
   //?GPTD1.tim->BDTR = STM32_TIM_BDTR_MOE;
+//  gptStartContinuousI(&GPTD1, 100);
   adcStartConversion(&ADCD1, &adcgrpcfg1, &ADC_Data, ADC_GRP1_BUF_DEPTH); //?
   adcStartConversion(&ADCD1, &adcgrpcfg1, &ADC_Data, ADC_GRP1_BUF_DEPTH); //?
 
 
   /*
   /*
@@ -116,12 +117,20 @@ int main(void) {
   while (true) {
   while (true) {
     if (n != 0) {
     if (n != 0) {
       onewireMeasure();
       onewireMeasure();
-      t = onewireGetTemperature(0);
-      a = t / 1000; b = t % 1000;
-      chsnprintf(buf, 22, "T = %d.%03u °C     ", a, b);
-      ST7735_WriteString(0, LCD_LINE_1, buf, LiberM_7x10, Yellow, Black);
+      onewire_error_t err = onewireGetErrorCode();
+      if (err == onewire_OK) {
+        t = onewireGetTemperature(0);
+        t += 50;
+        t /= 100;
+        a = t / 10; b = t % 10;
+        chsnprintf(buf, 22, "T = %d.%u °C     ", a, b);
+        ST7735_WriteString(0, LCD_LINE_1, buf, LiberM_7x10, Yellow, Black);
+      } else {
+        chsnprintf(buf, 22, "Onewire error: %d", err);
+        ST7735_WriteString(0, LCD_LINE_1, buf, LiberM_7x10, Red, Black);
+      }
     }
     }
-    chsnprintf(buf, 22, "U = %u V", Voltage);
+    chsnprintf(buf, 22, "U = %u mV", Voltage);
     ST7735_WriteString(0, LCD_LINE_3, buf, LiberM_7x10, Orange, Black);
     ST7735_WriteString(0, LCD_LINE_3, buf, LiberM_7x10, Orange, Black);
     chThdSleepMilliseconds(1000);
     chThdSleepMilliseconds(1000);
   }
   }
@@ -222,7 +231,7 @@ static void ADC_cb(ADCDriver *adcp) {
   (void)adcp;
   (void)adcp;
   int i;
   int i;
   uint64_t adc_buf = 0;
   uint64_t adc_buf = 0;
-
+  palToggleLine(LINE_LED);
   for (i=0; i<ADC_GRP1_BUF_DEPTH; i++) {
   for (i=0; i<ADC_GRP1_BUF_DEPTH; i++) {
     adc_buf += ADC_Data[i] * ADC_Data[i];
     adc_buf += ADC_Data[i] * ADC_Data[i];
   }
   }