From 9cd30f2a0c75da9454f9f4fd02a16490d45c15c1 Mon Sep 17 00:00:00 2001 From: Ole Artz Date: Tue, 31 May 2022 11:43:21 +0200 Subject: [PATCH] DCDC MDC Converter Board: add rxcnt check to answer and add handling scan in getdata() --- atmega32u4/dcdc_mdc/main.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/atmega32u4/dcdc_mdc/main.c b/atmega32u4/dcdc_mdc/main.c index f6844aa..49b8f30 100644 --- a/atmega32u4/dcdc_mdc/main.c +++ b/atmega32u4/dcdc_mdc/main.c @@ -194,7 +194,7 @@ void setVoltages(void) { } void switchDCDC(uint8_t group, uint8_t val) { - // de/activate the dcdc themself + // de/activate the dcdc itself if (val == 0) { shift_register &= ~((uint32_t)1 << (4 + group * 8)); // DCDC off if (group == 0) { @@ -286,17 +286,20 @@ in one command.) */ void getdata(uint8_t buf) { - // handle the incoming comand and call the correct function - if (rxcnt != 0 || (buf == 'A' || buf == 'W' || buf == 'R')) { + // handle the incoming command and call the correct function + if (rxcnt != 0 || (buf == 'A' || buf = 'S' || buf == 'W' || buf == 'R')) { rxbuf[rxcnt++] = buf; } if (buf == '\n' || buf == '\r') { // End of Command - if (rxbuf[0] == 'A') { - // answer + + if (rxbuf[0] == 'A' && rxcnt == 11) { + // get answer from another MC and transmit it to the next memcpy((uint8_t *)txbuf, (uint8_t *)rxbuf, 10); txbuf[11] = 0; send_answer_buf(txbuf); - } else if (rxbuf[0] == 'S') { // Scann of chain, returns number of boards + + } else if (rxbuf[0] == 'S') { + // Scan of chain, returns number of boards txbuf[0] = 'S'; uint8_t length = rxcnt - 2; // Length of Counter // read current counter value @@ -325,8 +328,10 @@ void getdata(uint8_t buf) { txbuf[length + 2] = 0; send_answer_buf(txbuf); rxcnt = 0; - } else if (rxcnt == 11 && is_my_address(10)) { // message is for this uC + } else if (rxcnt == 11 && is_my_address(10)) { + // message is for this uC // } else if (is_my_address(10)) { //answer 0x00d1 works with this line + if (rxbuf[0] == 'W') { // write switch (hex_to_int(rxbuf[5])) { @@ -506,7 +511,7 @@ ISR(ADC_vect) { } ISR(USART1_RX_vect) { - // interupt for incoming comand + // interupt for incoming command uint8_t buf = UDR1; if (isMaster == 0) { getdata(buf); @@ -532,6 +537,7 @@ ISR(TIMER0_OVF_vect) { } __attribute__((naked)) void main(void) { + // initialize the board CLKPR = (1 << CLKPCE); // prescaler 2 = 8 MHz CLKPR = (1 << CLKPS0); // prescaler 2 -- 2.43.0