option bytes watchdog option read
This commit is contained in:
parent
dcd53a3ea4
commit
d84082f147
20
main.c
20
main.c
|
@ -36,6 +36,7 @@
|
|||
#include <libopencm3/stm32/rtc.h> // real time clock utilities
|
||||
#include <libopencm3/stm32/iwdg.h> // independent watchdog utilities
|
||||
#include <libopencm3/stm32/dbgmcu.h> // debug utilities
|
||||
#include <libopencm3/stm32/flash.h> // flash utilities
|
||||
|
||||
/* own libraries */
|
||||
#include "global.h" // board definitions
|
||||
|
@ -252,7 +253,6 @@ void main(void)
|
|||
printf("setup PZEM-004 electricity meter: ");
|
||||
sensor_pzem_setup(); // setup PZEM electricity meter
|
||||
printf("OK\n");
|
||||
sensor_pzem_measurement_request(0xc0a80101, SENSOR_PZEM_VOLTAGE);
|
||||
|
||||
// setup SDM120 electricity meter
|
||||
printf("setup SDM120 electricity meter: ");
|
||||
|
@ -276,8 +276,15 @@ void main(void)
|
|||
iwdg_set_period_ms(WATCHDOG_PERIOD); // set independent watchdog period
|
||||
iwdg_start(); // start independent watchdog
|
||||
printf("OK\n");
|
||||
if (FLASH_OBR&FLASH_OBR_OPTERR) {
|
||||
printf("option bytes not set in flash: software wachtdog used (not started at reset)\n");
|
||||
} else if (FLASH_OBR&FLASH_OBR_WDG_SW) {
|
||||
printf("software wachtdog used (not started at reset)\n");
|
||||
} else {
|
||||
printf("hardware wachtdog used (started at reset)\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// send HTTP POST request
|
||||
printf("making HTTP request: ");
|
||||
char line[256] = {0}; // measurement line to send
|
||||
|
@ -298,6 +305,11 @@ void main(void)
|
|||
button_flag = false; // reset button flag
|
||||
char c = ' '; // to store received character
|
||||
bool char_flag = false; // a new character has been received
|
||||
|
||||
struct sensor_pzem_measurement_t pzem_measurements[3][4]; // PZEM-004T measurements
|
||||
uint8_t pzem_measurement_i = 0; // PZEM-004T measurement index
|
||||
sensor_pzem_measurement_request(0xc0a80100+pzem_measurement_i, SENSOR_PZEM_VOLTAGE); // start measurement
|
||||
|
||||
while (true) { // infinite loop
|
||||
iwdg_reset(); // kick the dog
|
||||
/*
|
||||
|
@ -333,10 +345,12 @@ void main(void)
|
|||
}
|
||||
while (sensor_pzem_measurement_received) { // measurement from electricity meter received
|
||||
struct sensor_pzem_measurement_t measurement = sensor_pzem_measurement_decode(); // decode measurement
|
||||
pzem_measurements[pzem_measurement_i][measurement.type] = measurement; // save measurement (the type matches the index)
|
||||
(void)pzem_measurements[pzem_measurement_i][measurement.type];
|
||||
if (measurement.valid) { // only show valid measurement
|
||||
switch (measurement.type) {
|
||||
case SENSOR_PZEM_VOLTAGE:
|
||||
printf("voltage: %.01f V\n", measurement.value.voltage);
|
||||
printf("voltage: %.01f V\n", measurement.value.voltage); // display measurement
|
||||
break;
|
||||
case SENSOR_PZEM_CURRENT:
|
||||
printf("current: %.02f A\n", measurement.value.current);
|
||||
|
|
Loading…
Reference in New Issue