From 59da2bfa3b42a8478306a23561ae3b0e5dd57427 Mon Sep 17 00:00:00 2001 From: Adrian Weber Date: Fri, 21 Feb 2020 11:47:33 +0100 Subject: [PATCH] fix in script for direct Read and Write in register; fixed read and set of informations and writing voltage to eeproom --- atmega32u4/dcdc_rich/dcdc.pl | 11 +++++- atmega32u4/dcdc_rich/main.c | 74 +++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/atmega32u4/dcdc_rich/dcdc.pl b/atmega32u4/dcdc_rich/dcdc.pl index d1d5183..d579376 100755 --- a/atmega32u4/dcdc_rich/dcdc.pl +++ b/atmega32u4/dcdc_rich/dcdc.pl @@ -150,7 +150,7 @@ if($args > 1) { if ($mode == 1) { # direct register access - if($args == 6) { + if($args == 6 || $args == 5) { # microcontroller number in chain $uC = $ARGV[1]; @@ -172,6 +172,9 @@ if ($mode == 1) { $rw = "R"; } elsif ($rw eq "w" || $rw eq "W") { $rw = "W"; + if ($args == 5) { + die "Not all arguements were specified!\n"; + } } else { die "This register does not exist\n"; } @@ -184,7 +187,11 @@ if ($mode == 1) { } # Value - $val = $ARGV[5]; + if ($rw eq "R") { + $val = 0x0; + } else { + $val = $ARGV[5]; + } if (substr($val,0,2) eq "0x") {$val= hex(substr($val,2));} if ($val > 0xFFFF) { die "The value is greater than 16 bit! Only 16 bit are allowed\n"; diff --git a/atmega32u4/dcdc_rich/main.c b/atmega32u4/dcdc_rich/main.c index 7b96ad9..859666f 100644 --- a/atmega32u4/dcdc_rich/main.c +++ b/atmega32u4/dcdc_rich/main.c @@ -25,6 +25,9 @@ #define SHIFT_EN_OUTPUT() PORTF &= ~(1<> (nib*4)) & 0xF; @@ -142,8 +146,13 @@ void setDCDC(uint8_t chan, uint8_t val) { } void setInfo(uint8_t chan, uint8_t val){ - if ((val & 0x1) == 1) LED_ON(); // LED on - if ((val & 0x1) == 0) LED_OFF(); // LED off + if ((val & 0x1) == 1) { LED_ON(); information |= (1<<0);}// LED on + if ((val & 0x1) == 0) { LED_OFF(); information &= ~(1<<0);}// LED off + + if (((val>>1) & 0x1) == 1) { SEL_ON(); information |= (1<<1);}// Switch activated + if (((val>>1) & 0x1) == 0) { SEL_OFF(); information &= ~(1<<1);}// Switch deactivated + + information |= (FIRMWARE_VERSION<<4); } uint16_t conversion_ADC(uint8_t mode) { @@ -249,33 +258,30 @@ void getdata(uint8_t buf) { 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); + case 0: switchDCDC(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9])); + send_answer_hex(&rxbuf[0],hex_to_int(rxbuf[9])); 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; - } + case 1: if (hex_to_int(rxbuf[4]) < 4) { + 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); + } + send_answer_hex(&rxbuf[0],hex_to_int(rxbuf[9])); + break; + + // set Infos register + 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])); + + send_answer_hex(&rxbuf[0],information); + break; + + default: send_answer_hex(&rxbuf[0],0xFFFF); + break; } } @@ -289,12 +295,12 @@ void getdata(uint8_t buf) { // get DCDC selection if (hex_to_int(rxbuf[5]) == 1) { - uint8_t setting = 0xFF; - if (hex_to_int(rxbuf[4]) < 4) setting = ((dcdc_settings[hex_to_int(rxbuf[4])][3]&0x1<<12) | - (dcdc_settings[hex_to_int(rxbuf[4])][2]&0x1<< 8) | - (dcdc_settings[hex_to_int(rxbuf[4])][1]&0x1<< 4) | - (dcdc_settings[hex_to_int(rxbuf[4])][0]&0x1) - ); + uint16_t setting = 0xFFFF; + if (hex_to_int(rxbuf[4]) < 4) setting = ((dcdc_settings[hex_to_int(rxbuf[4])][3]<<12) | + (dcdc_settings[hex_to_int(rxbuf[4])][2]<< 8) | + (dcdc_settings[hex_to_int(rxbuf[4])][1]<< 4) | + (dcdc_settings[hex_to_int(rxbuf[4])][0]) + ) & 0xFFFF; send_answer_hex(&rxbuf[0],setting); } @@ -315,8 +321,8 @@ void getdata(uint8_t buf) { // get info if (hex_to_int(rxbuf[5]) == 5) { - uint16_t res = ((FIRMWARE_VERSION<<4) | (0<<1) | (0<<0))&0xFFFF; - send_answer_hex(&rxbuf[0],res); + information |= (FIRMWARE_VERSION<<4); + send_answer_hex(&rxbuf[0],information); } } } -- 2.43.0