From 576dcc7789c010e73b116bef21050134434faea8 Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Fri, 30 Jun 2023 17:36:26 +0200 Subject: [PATCH] Update MDC powerboard with option to not write to EEPROM for powercycles --- atmega32u4/dcdc_mdc/main.c | 53 ++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/atmega32u4/dcdc_mdc/main.c b/atmega32u4/dcdc_mdc/main.c index 5c9c5a9..59f6a65 100644 --- a/atmega32u4/dcdc_mdc/main.c +++ b/atmega32u4/dcdc_mdc/main.c @@ -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; -- 2.43.0