|
@@ -24,7 +24,7 @@
|
|
|
|
|
|
#include "main.h"
|
|
|
#include "st7735.h"
|
|
|
-#include "onewire.h"
|
|
|
+//#include "onewire.h"
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
/* Generic code. */
|
|
@@ -70,20 +70,20 @@ int main(void) {
|
|
|
/*
|
|
|
* 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. */
|
|
|
adcStart(&ADCD1, NULL);
|
|
|
+ adcStartConversion(&ADCD1, &adcgrpcfg1, ADC_Data, ADC_GRP1_BUF_DEPTH);
|
|
|
|
|
|
/* Starting GPT3 driver, it is used for triggering the ADC. */
|
|
|
- gptStart(&GPTD1, &gptcfg1);
|
|
|
+ gptStart(&GPTD3, &gptcfg1);
|
|
|
+ gptStartContinuousI(&GPTD3, 100);
|
|
|
// 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;
|
|
|
-// gptStartContinuousI(&GPTD1, 100);
|
|
|
- adcStartConversion(&ADCD1, &adcgrpcfg1, &ADC_Data, ADC_GRP1_BUF_DEPTH); //?
|
|
|
|
|
|
/*
|
|
|
* Buttons
|
|
@@ -102,6 +102,7 @@ int main(void) {
|
|
|
/*
|
|
|
* Normal main() thread activity.
|
|
|
*/
|
|
|
+ /*
|
|
|
ST7735_WriteString(0, LCD_LINE_1, "OneWire search...", LiberM_7x10, Blue, Black);
|
|
|
onewireMeasure();
|
|
|
int32_t t;
|
|
@@ -112,9 +113,10 @@ int main(void) {
|
|
|
if (n == 0) {
|
|
|
ST7735_WriteString(0, LCD_LINE_1, "DS18B20 not found.", LiberM_7x10, Red, Black);
|
|
|
}
|
|
|
-
|
|
|
+*/
|
|
|
int a, b;
|
|
|
while (true) {
|
|
|
+/*
|
|
|
if (n != 0) {
|
|
|
onewireMeasure();
|
|
|
onewire_error_t err = onewireGetErrorCode();
|
|
@@ -130,6 +132,7 @@ int main(void) {
|
|
|
ST7735_WriteString(0, LCD_LINE_1, buf, LiberM_7x10, Red, Black);
|
|
|
}
|
|
|
}
|
|
|
+*/
|
|
|
chsnprintf(buf, 22, "U = %u mV", Voltage);
|
|
|
ST7735_WriteString(0, LCD_LINE_3, buf, LiberM_7x10, Orange, Black);
|
|
|
chThdSleepMilliseconds(1000);
|
|
@@ -230,12 +233,13 @@ static uint8_t X_centered(const uint8_t len, const uint8_t pix) {
|
|
|
static void ADC_cb(ADCDriver *adcp) {
|
|
|
(void)adcp;
|
|
|
int i;
|
|
|
- uint64_t adc_buf = 0;
|
|
|
- palToggleLine(LINE_LED);
|
|
|
+ uint32_t adc_buf = 0;
|
|
|
+
|
|
|
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];
|
|
|
+ adc_buf += ADC_Data[i];
|
|
|
}
|
|
|
-
|
|
|
+/*
|
|
|
// adc_buf - sum of squares. SQRT:
|
|
|
uint32_t val = 0;
|
|
|
uint32_t step = 1;
|
|
@@ -244,9 +248,10 @@ static void ADC_cb(ADCDriver *adcp) {
|
|
|
step += 2;
|
|
|
val ++;
|
|
|
}
|
|
|
+*/
|
|
|
// transform ADC values to real voltage
|
|
|
- val /= ADC_GRP1_BUF_DEPTH;
|
|
|
- val *= ADC_REF_VOLTAGE;
|
|
|
- val /= 4096;
|
|
|
- Voltage = val;
|
|
|
+ adc_buf /= ADC_GRP1_BUF_DEPTH;
|
|
|
+ adc_buf *= ADC_REF_VOLTAGE;
|
|
|
+ adc_buf /= 4096;
|
|
|
+ Voltage = adc_buf;
|
|
|
}
|