]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
DCDC MDC Converter Board: add rxcnt check to answer and add handling scan in getdata()
authorOle Artz <ole.artz@t-online.de>
Tue, 31 May 2022 09:43:21 +0000 (11:43 +0200)
committerOle Artz <ole.artz@t-online.de>
Tue, 31 May 2022 09:43:21 +0000 (11:43 +0200)
atmega32u4/dcdc_mdc/main.c

index f6844aaf9d713dd57c2dc2c5410282ba044029fb..49b8f309d8439661394496f4aba7699c85ed5f45 100644 (file)
@@ -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