From 241f29b7cc64fd5f7bdc989067129fd0936eea2b Mon Sep 17 00:00:00 2001 From: Adrian Weber Date: Thu, 20 Feb 2020 16:42:26 +0100 Subject: [PATCH] fixed the set Voltage function of DCDC converter --- atmega32u4/dcdc_rich/main.c | 57 +++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/atmega32u4/dcdc_rich/main.c b/atmega32u4/dcdc_rich/main.c index 321a933..7b96ad9 100644 --- a/atmega32u4/dcdc_rich/main.c +++ b/atmega32u4/dcdc_rich/main.c @@ -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; -- 2.43.0