]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
Update MDC powerboard with option to not write to EEPROM for powercycles
authorJan Michel <michel@physik.uni-frankfurt.de>
Fri, 30 Jun 2023 15:36:26 +0000 (17:36 +0200)
committerJan Michel <michel@physik.uni-frankfurt.de>
Fri, 30 Jun 2023 15:36:26 +0000 (17:36 +0200)
atmega32u4/dcdc_mdc/main.c

index 5c9c5a9d17aa5a47aae3207304d1923ecc929488..59f6a65a82a48880e6ff50ca50adb11e36a74719 100644 (file)
@@ -90,7 +90,7 @@ void getdata(uint8_t buf);
 /* 
  *  #################################### define parameters to fixed values
  */
-#define FIRMWARE_VERSION 0x002
+#define FIRMWARE_VERSION 0x003
 
 #define ISMYADDR() (rxbuf[1] == '0' && rxbuf[2] == '0')
 
@@ -269,7 +269,6 @@ void switchDCDC(uint8_t group, uint8_t val) {
       LED_CH3_ON();
     }
   }
-  setVoltages();
 }
 
 void setDCDC(uint8_t group, uint8_t chan, uint8_t val) {
@@ -339,7 +338,7 @@ ISR(USART1_RX_vect) {
     getdata(buf);
   } else {
     // usb_serial_putchar(buf);
-  }
+  } 
 }
 
 ISR(USART1_UDRE_vect) {
@@ -415,12 +414,23 @@ void getdata(uint8_t buf) {
 
         // set DCDC ON/OFF
         case 0:
-          if (hex_to_int(rxbuf[3]) < 4) {
-            switchDCDC(hex_to_int(rxbuf[3]), hex_to_int(rxbuf[9]));
-            eeprom_update_byte((uint8_t *)0x21, shift_register);
-            eeprom_update_byte((uint8_t *)0x22, shift_register >> 8);
-            eeprom_update_byte((uint8_t *)0x23, shift_register >> 16);
-            eeprom_update_byte((uint8_t *)0x24, shift_register >> 24);
+          if (hex_to_int(rxbuf[3]) <= 4) {
+            if (rxbuf[3]=='4') {
+              switchDCDC(0,hex_to_int(rxbuf[9]));
+              switchDCDC(1,hex_to_int(rxbuf[9]));
+              switchDCDC(2,hex_to_int(rxbuf[9]));
+              switchDCDC(3,hex_to_int(rxbuf[9]));
+              }
+            else {  
+              switchDCDC(hex_to_int(rxbuf[3]), hex_to_int(rxbuf[9]));
+              }
+            setVoltages();
+            if(rxbuf[6] != '8') {
+              eeprom_update_byte((uint8_t *)0x21, shift_register);
+              eeprom_update_byte((uint8_t *)0x22, shift_register >> 8);
+              eeprom_update_byte((uint8_t *)0x23, shift_register >> 16);
+              eeprom_update_byte((uint8_t *)0x24, shift_register >> 24);
+            }
           }
           send_answer_hex(&rxbuf[0], 0x00d1);
           break;
@@ -429,10 +439,12 @@ void getdata(uint8_t buf) {
         case 1:
           if (hex_to_int(rxbuf[3]) < 4) {
             setDCDC(hex_to_int(rxbuf[3]), hex_to_int(rxbuf[4]), hex_to_int(rxbuf[9]));
-            eeprom_update_byte((uint8_t *)0x21, shift_register);
-            eeprom_update_byte((uint8_t *)0x22, shift_register >> 8);
-            eeprom_update_byte((uint8_t *)0x23, shift_register >> 16);
-            eeprom_update_byte((uint8_t *)0x24, shift_register >> 24);
+            if(rxbuf[6] != '8') {
+              eeprom_update_byte((uint8_t *)0x21, shift_register);
+              eeprom_update_byte((uint8_t *)0x22, shift_register >> 8);
+              eeprom_update_byte((uint8_t *)0x23, shift_register >> 16);
+              eeprom_update_byte((uint8_t *)0x24, shift_register >> 24);
+            }
           }
           send_answer_hex(&rxbuf[0], 0x00d1);
           break;
@@ -538,21 +550,6 @@ void getdata(uint8_t buf) {
             send_answer_hex(&rxbuf[0], V_out);
           }
         }
-        /*
-                // get current C_out
-                if (hex_to_int(rxbuf[5]) == 8) {
-                //LDO CH1
-                    if (hex_to_int(rxbuf[4]) == 1) {
-                      C_out = adc[13];
-                    }
-                //LDO CH0
-                    if (hex_to_int(rxbuf[4]) == 0) {
-                      C_out = adc[3];
-                    }
-                  send_answer_hex(&rxbuf[0],C_out);
-                }
-        */
-
         // get GND
         if (hex_to_int(rxbuf[5]) == 9) {
           GND = (5 * adc[1]) / 2;