]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
fixed the set Voltage function of DCDC converter
authorAdrian Weber <adrian.a.weber@physik.uni-giessen.de>
Thu, 20 Feb 2020 15:42:26 +0000 (16:42 +0100)
committerAdrian Weber <adrian.a.weber@physik.uni-giessen.de>
Thu, 20 Feb 2020 15:42:26 +0000 (16:42 +0100)
atmega32u4/dcdc_rich/main.c

index 321a9334906d536665cfd6a8845fad84311430ee..7b96ad90a9190be85fe86038069ece53f4d60ba2 100644 (file)
@@ -99,15 +99,15 @@ uint8_t is_my_address(uint8_t s) {
 void setVoltages(void){
   cli();
   STCP_LOW();
-  for (unsigned int i = 3; i >= 0; i-- ){
+  for (uint8_t i = 0; i < 4; i++ ){
     for (unsigned int j = 0; j < 5; j++){// 5 times to fill also Q7S
       SHCP_LOW();
       SHIFT_DATA_LOW();
       SHCP_HIGH(); // write
     }
-    for (unsigned int j = 3; j >= 0; j--){
+    for (unsigned int j = 0; j< 4; j++){
       SHCP_LOW();
-      if (dcdc_settings[i][j] == 1) { 
+      if (dcdc_settings[3-i][3-j] == 1) { 
         SHIFT_DATA_HIGH();
       } else {
         SHIFT_DATA_LOW();
@@ -247,23 +247,36 @@ void getdata(uint8_t buf) {
 
       if (rxbuf[0] == 'W'){ //write
         
-        // switch DCDC channel On/Off
-        if (hex_to_int(rxbuf[5]) == 0) {
-          switchDCDC(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9]));
-        }
-
-        // set voltage of DCDC-Converter
-        if (hex_to_int(rxbuf[5]) == 1) {
-          setDCDC(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9]));
-          eeprom_update_byte((uint8_t*)(0x20+hex_to_int(rxbuf[4])),hex_to_int(rxbuf[9])&0xF);
-        }
-
-        // switch DCDC channel On
-        if (hex_to_int(rxbuf[5]) == 5) {
-          setInfo(hex_to_int(rxbuf[4]),/* hex_to_int(rxbuf[6])*4096
-                                        +hex_to_int(rxbuf[7])*256
-                                        +hex_to_int(rxbuf[8])*16
-                                        +*/hex_to_int(rxbuf[9]));
+        switch (hex_to_int(rxbuf[5])) {
+          // switch DCDC channel On/Off
+          case 0: {switchDCDC(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9]));
+                  uint8_t answer[] = "FFFFFF";
+                  send_answer_hex(&answer[0],0xFFFF);
+                  break;
+                  }
+
+          // set voltage of DCDC-Converter
+          case 1: {setDCDC(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9]));
+                  //eeprom_update_byte((uint8_t*)(0x20+hex_to_int(rxbuf[4])),hex_to_int(rxbuf[9])&0xF);
+                  uint8_t answer[] = "FFFFFF";
+                  send_answer_hex(&answer[0],0xFFFF);
+                  break;}
+
+          // switch DCDC channel On
+          case 5: {//setInfo(hex_to_int(rxbuf[4]),/* hex_to_int(rxbuf[6])*4096
+                   //                             +hex_to_int(rxbuf[7])*256
+                   //                              +hex_to_int(rxbuf[8])*16
+                   //                            +*/hex_to_int(rxbuf[9]));
+                  uint8_t answer[] = "FFFFFF";
+                  send_answer_hex(&answer[0],0xFFFF);
+                  break;}
+
+          default:  {  
+                      uint8_t answer[] = "FFFFFF";
+                      send_answer_hex(&answer[0],0xFFFF);
+                      break;                
+                    }  
+          
         }
       }
 
@@ -416,8 +429,8 @@ __attribute__((naked)) int main(void) {
   dcdc_settings[3][2] = (eeprom_value >> 2)& 0x1;
   dcdc_settings[3][3] = (eeprom_value >> 3)& 0x1;
 
-  //setVoltages();
-  //SHIFT_EN_OUTPUT(); // Enable output of shift register to mosfet
+  setVoltages();
+  SHIFT_EN_OUTPUT(); // Enable output of shift register to mosfet
   sei();
   uint8_t ADC_State = 0; // 0: start of uC; 1: Volt; 2: Current; 3: Temp
   uint16_t lasttime = 0;