From: Ole Artz Date: Thu, 17 Mar 2022 10:00:37 +0000 (+0100) Subject: DCDC MDC Dummy Board: implement DCDC switch and voltage adjustment. X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=b6a4b144455df87640fb460aa75b06ec1b7c6991;p=avr.git DCDC MDC Dummy Board: implement DCDC switch and voltage adjustment. --- diff --git a/atmega32u4/dcdc_mdc_dummy/README.md b/atmega32u4/dcdc_mdc_dummy/README.md index 2f5425c..5083f23 100644 --- a/atmega32u4/dcdc_mdc_dummy/README.md +++ b/atmega32u4/dcdc_mdc_dummy/README.md @@ -1,4 +1,4 @@ -# MDC DCDC Single Dummy Converter Board +# MDC DCDC Dummy Converter Board This is the firmware for the dcdc_mdc_dummy Converter Board. It's a test board for the upcomming MDC DCDC Converter Board which serves as the power supply for the mdc layers/chambers. @@ -33,9 +33,11 @@ Example: "RF2012FE51\n" ------------------------------------------------------------------------------------------------------------------------ -## Channelnumber definition +## Groupnumber definition -|Channelnumber | Description | +Each group has two channels (0, 1) + +| Groupnumber | Description | |---------------|---------------| | 0 | DCDC 0 | | 1 | DCDC 1 | @@ -49,15 +51,16 @@ Example: "RF2012FE51\n" | Registers | Description | |---------------|---------------------------------------------------------------| -| 0 | LDO ON/OFF | -| 1 | DCDC set voltage adjustment resistors | -| 2 | Voltage V_in (NA) | -| 3 | Current C_in (NA) | -| 4 | Temperature (RO) | +| 0 | DCDC (Group) ON/OFF | +| 1 | DCDC (Channel) set voltage adjustment resistors | +| 2 | Voltage V_in (RO) | +| 3 | Current C_in (RO) | +| 4 | Temperature (DCDC 2/Group 3) (RO) | | 5 | [15:4] Firmware; [3:2] reserved; [1] Switch ; [0] LED (RO) | | 6 | Current Offset | | 7 | Voltage V_out (RO) | -| 8 | Current C_out (RO) | +| 8 | Current C_out (NA) | +| 9 | Sense GND (NA) | NA := not available RO := read only @@ -69,5 +72,4 @@ RO := read only The dcdc_mdc_dummy Converter Board get his operating voltage via MicroUSB and receives messages via the LANTelnetServerBoard with UART Baud rate 57600. ------------------------------------------------------------------------------------------------------------------------ - -### Version 1.0, 2020-08-25 +### Version 1.0, 2021-08-19 diff --git a/atmega32u4/dcdc_mdc_dummy/main.c b/atmega32u4/dcdc_mdc_dummy/main.c index ba91795..da46445 100644 --- a/atmega32u4/dcdc_mdc_dummy/main.c +++ b/atmega32u4/dcdc_mdc_dummy/main.c @@ -1,56 +1,56 @@ // #define F_CPU 8000000UL +#include #include -#include #include -#include #include #include +#include #define FIRMWARE_VERSION 0x001 /* //ADC // 0 Sense1 Vin -// 1 GND -// 4 Sense2 Vmon3 -// 5 Sense3 TEMP_OUT -// 6 Sense4 Vmon2 -// 7 Sense5 Vmon1 -// 10 Sense6 Vmon0 +// 1 Sense_GND +// 4 Sense2 Vmon4 DCDC3 CH0 +// 5 Sense3 TEMP_OUT2 DCDC2 +// 6 Sense4 Vmon3 DCDC2 CH0 +// 7 Sense5 Vmon2 DCDC1 CH0 +// 10 Sense6 Vmon1 DCDC0 CH0 // 11 Sense7 Cin - -// PB5 LED CH 0 -// PB6 LED CH 1 -// PC6 LED CH 2 -// PC7 LED CH 3 -//PD6 LED1 -//PD4 LED2 +// PB5 LED DCDC 0 (green) +// PB6 LED DCDC 1 (green) +// PC6 LED DCDC 2 (green) +// PC7 LED DCDC 3 (green) +// PD6 LED1 (yellow) +// PD4 LED2 (red) //PB7 Output enable //shift register outputs (times 4) Output 0 on MSB, Output 3 on LSB side -//CTRL10 (MSB) -//CTRL11 -//CTRL12 +// CTRL10 (MSB) +// CTRL11 +// CTRL12 // empty -//DCDC_EN -//CTRL00 -//CTRL01 -//CTRL02 +// DCDC_EN //DCDC ON/OFF +// CTRL00 +// CTRL01 +// CTRL02 // | Registers | description | // |-----------|--------------------------------------------------------------| -// | 0 | LDO ON/OFF | +// | 0 | DCDC ON/OFF | // | 1 | DCDC set voltage adjustment resistors | -// | 2 | Voltage V_in (NA) | -// | 3 | Current C_in (NA) | +// | 2 | Voltage V_in (RO) | +// | 3 | Current C_in (RO) | // | 4 | Temperature (RO) | // | 5 | [15:4] Firmware; [3:2] reserved; [1] Switch ; [0] LED (RO) | // | 6 | Current Offset | // | 7 | Voltage V_out (RO) | -// | 8 | Current C_out (RO) | +// | 8 | Current C_out (NA) | +// | 9 | Sense GND (NA) | // **Data format:** *XuuGcRvvvv* // **Data format:** *X000cRvvvv* @@ -58,507 +58,600 @@ #define ISMYADDR() (rxbuf[1] == '0' && rxbuf[2] == '0') -#define LED1_ON() PORTD |= (1<> (nib*4)) & 0xF; - if (t <= 9) {return t + 0x30;} - return t - 10 + 0x61; - } - -uint8_t hex_to_int(uint8_t h) { //assumes valid number - if (h < 0x40) return h-0x30; - if (h < 0x50) return h-0x41+10; - return h-0x61+10; + uint8_t t = (in >> (nib * 4)) & 0xF; + if (t <= 9) { + return t + 0x30; } + return t - 10 + 0x61; +} + +uint8_t hex_to_int(uint8_t h) { // assumes valid number + if (h < 0x40) return h - 0x30; + if (h < 0x50) return h - 0x41 + 10; + return h - 0x61 + 10; +} -void sub1(uint8_t* c1, uint8_t* c2) { - uint8_t b = hex_to_int(*c1)*16 + hex_to_int(*c2); +void sub1(uint8_t *c1, uint8_t *c2) { + uint8_t b = hex_to_int(*c1) * 16 + hex_to_int(*c2); b -= 1; - *c1 = nib_to_hex(b,1); - *c2 = nib_to_hex(b,0); - } + *c1 = nib_to_hex(b, 1); + *c2 = nib_to_hex(b, 0); +} -void send_answer_buf(uint8_t*b) { - UCSR1B |= (1<= 0; i--) { + SHCP_LOW(); + if (shift_register & mask) + SHIFT_DATA_HIGH(); + else + SHIFT_DATA_LOW(); + SHCP_HIGH(); + mask >>= 1; + } + SHCP_LOW(); + SHIFT_DATA_LOW(); + // Load to Ouput Register: + STCP_HIGH(); + STCP_HIGH(); + STCP_LOW(); + SHIFT_EN_OUTPUT(); + sei(); } -void setDCDC(uint8_t chan, uint8_t val) { -// //DCDC CH0 -// if (chan == 2 & val<=7) { -// val = 7 - val; -// shift_register &= ~((1<<15)|(1<<14)|(1<<13)); //clear decbitpos15-13 -// shift_register |= val<<13; -// } -// //DCDC CH1 -// if (chan == 3 & val<=7) { -// val = 7 - val; -// shift_register &= ~((1<<11)|(1<<10)|(1<<9)); -// shift_register |= val<<9; -// } -// //LDO CH1 -// if (chan == 1 & val<=7) { -// val = 7 - val; -// shift_register &= ~((1<<7)|(1<<6)|(1<<5)); -// shift_register |= val<<5; -// } -// //LDO CH0 -// if (chan == 0 & val<=7) { -// val = 7 - val; -// shift_register &= ~((1<<2)|(1<<1)|(1<<0)); -// shift_register |= val<<0; -// } -// setVoltages(); +void switchDCDC(uint8_t group, uint8_t val) { + if (val == 0) { + shift_register &= ~((uint32_t)1 << (4 + group * 8)); // DCDC off + if (group == 0) { + LED_CH0_OFF(); + } else if (group == 1) { + LED_CH1_OFF(); + } else if (group == 2) { + LED_CH2_OFF(); + } else if (group == 3) { + LED_CH3_OFF(); + } + } + else { + shift_register |= ((uint32_t)1 << (4 + group * 8)); // DCDC on + if (group == 0) { + LED_CH0_ON(); + } else if (group == 1) { + LED_CH1_ON(); + } else if (group == 2) { + LED_CH2_ON(); + } else if (group == 3) { + LED_CH3_ON(); + } + } + setVoltages(); } -void setInfo(uint8_t chan, uint8_t val){ - if ((val & 0x1) == 1) { LED1_ON(); information |= (1<<0);}// LED1 on - if ((val & 0x1) == 0) { LED1_OFF(); information &= ~(1<<0);}// LED1 off - - if (((val>>1) & 0x1) == 1) { LED2_ON(); information |= (1<<1);}// LED2 on - if (((val>>1) & 0x1) == 0) { LED2_OFF(); information &= ~(1<<1);}// LED2 off +void setDCDC(uint8_t group, uint8_t chan, uint8_t val) { + // DCDC CH0 + if (chan == 0 && val <= 7) { + val = 7 - val; + shift_register &= ~(((uint32_t)1 << ((5 + group * 8) + 2)) | ((uint32_t)1 << ((5 + group * 8) + 1)) | ((uint32_t)1 << (5 + group * 8))); // clear bitpositon f.e. group = 0 -> 7,6,5 + val = ((val >> 2) & 1) | (val & 2)| ((val <<2) & 4); //for lineal increase + shift_register |= (uint32_t)val << (group * 8 + 5); + } + // DCDC CH1 + if (chan == 1 && val <= 7) { + val = 7 - val; + shift_register &= ~(((uint32_t)1 << ((group * 8) + 2)) | ((uint32_t)1 << ((group * 8) + 1)) | ((uint32_t)1 << (group * 8))); // clear bitpositon f.e. group = 0 -> 2,1,0 + val = ((val >> 2) & 1) | (val & 2)| ((val <<2) & 4); + shift_register |= (uint32_t)val << (group * 8); + } + + setVoltages(); +} + +void setInfo(uint8_t chan, uint8_t val) { + if ((val & 0x1) == 1) {LED1_ON(); information |= (1 << 0);} // LED1 on + if ((val & 0x1) == 0) {LED1_OFF(); information &= ~(1 << 0);} // LED1 off - information |= (FIRMWARE_VERSION<<4); + if (((val >> 1) & 0x1) == 1) {LED2_ON(); information |= (1 << 1);} // LED2 on + if (((val >> 1) & 0x1) == 0) {LED2_OFF(); information &= ~(1 << 1);} // LED2 off + + information |= (FIRMWARE_VERSION << 4); } /* // Data: XuuGcRvvvv -//Switch deactivated +// Switch deactivated // X - command (write: W, read: R, answer: A etc.) // uu - Controllernumber (Hex value) -// G - Groupnumber (to talk to all channels, that belong together, in one command.) +// G - Groupnumber (to talk to all channels, that belong together, +in one command.) // c - channelnumber in the group (Hex value) // R - register (Hex value) -// vvvv - 16 Bit value +// vvvv - 16 Bit value // // All in all 10 characters // RF2012FE51 // // close with a "\n" // e.g. "RF2012FE51\n" -// +// // // // | Registers | description | // |-----------|--------------------------------------------------------------| -// | 0 | LDO ON/OFF | +// | 0 | DCDC ON/OFF | // | 1 | DCDC set voltage adjustment resistors | -// | 2 | Voltage V_in (NA) | -// | 3 | Current C_in (NA) | +// | 2 | Voltage V_in (RO) | +// | 3 | Current C_in (RO) | // | 4 | Temperature (RO) | // | 5 | [15:4] Firmware; [3:2] reserved; [1] Switch ; [0] LED (RO) | // | 6 | Current Offset | // | 7 | Voltage V_out (RO) | -// | 8 | Current C_out (RO) | +// | 8 | Current C_out (NA) | +// | 9 | Sense GND (RO) | */ void getdata(uint8_t buf) { if (rxcnt != 0 || (buf == 'A' || buf == 'W' || buf == 'R')) { rxbuf[rxcnt++] = buf; } - if (buf == '\n' || buf == '\r') { //End of Command + if (buf == '\n' || buf == '\r') { // End of Command if (rxbuf[0] == 'A') { -//answer - memcpy ((uint8_t*)txbuf,(uint8_t*)rxbuf,10); - txbuf[11] = 0; - send_answer_buf(txbuf); + // answer + 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 - txbuf[0] = 'S'; - uint8_t length = rxcnt - 2 ; // Length of Counter - //read current counter value - uint32_t cnt = 0; - if (length == 0){ - length = 1; - } else { - uint32_t base = 1; - for (uint8_t i = length; i > 0; i--){ - cnt += hex_to_int(rxbuf[i])*base; - base *= 16; - } + txbuf[0] = 'S'; + uint8_t length = rxcnt - 2; // Length of Counter + // read current counter value + uint32_t cnt = 0; + if (length == 0) { + length = 1; + } else { + uint32_t base = 1; + for (uint8_t i = length; i > 0; i--) { + + cnt += hex_to_int(rxbuf[i]) * base; + base *= 16; + } + } + // inc counter value + cnt++; + // send to next uC + if ((cnt % 16) == 0) + length++; + for (uint8_t i = length; i > 0; i--) { + txbuf[i] = nib_to_hex(cnt, length - i); + } + if (length > 8) + length = 8; // skip to keep a clean ending of message + txbuf[length + 1] = 10; + 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 (is_my_address(10)) { //answer 0x00d1 works with this line + if (rxbuf[0] == 'W') { + // write + switch (hex_to_int(rxbuf[5])) { + + // 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); } - // inc counter value - cnt++; - //send to next uC - if ((cnt % 16) == 0) length++; - for (uint8_t i = length; i > 0; i--){ - txbuf[i] = nib_to_hex(cnt,length-i); + send_answer_hex(&rxbuf[0], 0x00d1); + break; + + // set voltage of DCDC-Converter + 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 (length > 8) length = 8; // skip to keep a clean ending of message - txbuf[length+1] = 10; - txbuf[length+2] = 0; - send_answer_buf(txbuf); - rxcnt = 0; - } else if (is_my_address(10)){ // message is for this uC - if (rxbuf[0] == 'W'){ -//write - switch (hex_to_int(rxbuf[5])) { - - // set LDO ON/OFF - case 0: if (hex_to_int(rxbuf[4]) < 3) { - switchLDO(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); - } - send_answer_hex(&rxbuf[0],shift_register); - break; - - // set voltage of DCDC-Converter - case 1: if (hex_to_int(rxbuf[4]) < 5) { - setDCDC(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); - } - send_answer_hex(&rxbuf[0],shift_register); - break; - - // set information - case 5: setInfo(hex_to_int(rxbuf[4]),hex_to_int(rxbuf[9])); - send_answer_hex(&rxbuf[0],information); - break; - - // set current offset - case 6: curr_offset = (hex_to_int(rxbuf[7])*16+hex_to_int(rxbuf[8]))&0xFF; - eeprom_update_byte((uint8_t*)0x26,curr_offset); - send_answer_hex(&rxbuf[0],curr_offset*16); - break; - - default:send_answer_hex(&rxbuf[0], 0xFFFF); - break; - + send_answer_hex(&rxbuf[0], 0x00d1); + break; + + // set information + case 5: + setInfo(hex_to_int(rxbuf[4]), hex_to_int(rxbuf[9])); + send_answer_hex(&rxbuf[0], information); + break; + + // set current offset + case 6: + curr_offset = (hex_to_int(rxbuf[7]) * 16 + hex_to_int(rxbuf[8])) & 0xFF; + eeprom_update_byte((uint8_t *)0x26, curr_offset); + send_answer_hex(&rxbuf[0], curr_offset * 16); + break; + + default: + send_answer_hex(&rxbuf[0], 0xFFFF); + break; } } - if (rxbuf[0] == 'R'){ -//read - // get LDO status + if (rxbuf[0] == 'R') { + // read + + // get DCDC status if (hex_to_int(rxbuf[5]) == 0) { - uint16_t read_LDO_status = 0xFFFF; - //LDO Status CH1 - if (hex_to_int(rxbuf[4]) == 1) {read_LDO_status = ((shift_register >> 4) & 1); - } - //LDO Status CH0 - if (hex_to_int(rxbuf[4]) == 0) {read_LDO_status = ((shift_register >> 3) & 1); - } - send_answer_hex(&rxbuf[0],read_LDO_status); + uint16_t read_DCDC_status = 0xFFFF; + // DCDC Status CH0 + if (hex_to_int(rxbuf[4]) == 0) { + read_DCDC_status = ((shift_register >> (4 + hex_to_int(rxbuf[3]) * 8)) & 1); + } + + send_answer_hex(&rxbuf[0], read_DCDC_status); } - + // get voltage resistors selection if (hex_to_int(rxbuf[5]) == 1) { - uint16_t read_setting = 0xFFFF; - //DCDC CH0 - if (hex_to_int(rxbuf[4]) == 2) {read_setting = 7 - ((shift_register >> 13) & 7); - } - //DCDC CH1 - if (hex_to_int(rxbuf[4]) == 3) {read_setting = 7 - ((shift_register >> 9) & 7); - } - //LDO CH1 - if (hex_to_int(rxbuf[4]) == 1) {read_setting = 7 - ((shift_register >> 5) & 7); - } - //LDO CH0 - if (hex_to_int(rxbuf[4]) == 0) {read_setting = 7 - (shift_register & 7); - } - send_answer_hex(&rxbuf[0],read_setting); + uint16_t read_setting = 0xFFFF; + // CH0 + if (hex_to_int(rxbuf[4]) == 0) { + read_setting = 7 - ((shift_register >> (hex_to_int(rxbuf[3]) * 8 + 5)) & 7); + } + // CH1 + if (hex_to_int(rxbuf[4]) == 1) { + read_setting = 7 - ((shift_register >> (hex_to_int(rxbuf[3]) * 8)) & 7); + } + send_answer_hex(&rxbuf[0], read_setting); } - + // get voltage V_in if (hex_to_int(rxbuf[5]) == 2) { - send_answer_hex(&rxbuf[0],V_in); + V_in = (5 * adc[0]) / 2; + send_answer_hex(&rxbuf[0], V_in); } - + // get current C_in if (hex_to_int(rxbuf[5]) == 3) { - send_answer_hex(&rxbuf[0],C_in); + C_in = (5 * adc[11]) / 2; + send_answer_hex(&rxbuf[0], C_in); } - + // get temperature if (hex_to_int(rxbuf[5]) == 4) { - temp = adc[5]; - send_answer_hex(&rxbuf[0],temp); + temp = adc[5]; + send_answer_hex(&rxbuf[0], temp); } - + // get information if (hex_to_int(rxbuf[5]) == 5) { - information |= (FIRMWARE_VERSION<<4); - send_answer_hex(&rxbuf[0],information); + information |= (FIRMWARE_VERSION << 4); + send_answer_hex(&rxbuf[0], information); } - + // get current offset if (hex_to_int(rxbuf[5]) == 6) { - send_answer_hex(&rxbuf[0],curr_offset*16); - } - + send_answer_hex(&rxbuf[0], curr_offset * 16); + } + // get voltage V_out if (hex_to_int(rxbuf[5]) == 7) { - //DCDC CH0 - if (hex_to_int(rxbuf[4]) == 2) { - V_out = (5*adc[0])/2; - send_answer_hex(&rxbuf[0],V_out); - } - //DCDC CH1 - if (hex_to_int(rxbuf[4]) == 3) { - V_out = (5*adc[7])/2; - send_answer_hex(&rxbuf[0],V_out); - } - //LDO CH1 - if (hex_to_int(rxbuf[4]) == 1) { - V_out = (5*adc[6])/2; - send_answer_hex(&rxbuf[0],V_out); - } - //LDO CH0 - if (hex_to_int(rxbuf[4]) == 0) { - V_out = (5*adc[1])/2; - send_answer_hex(&rxbuf[0],V_out); - } - + + // DCDC 0 + if (hex_to_int(rxbuf[3]) == 0) { + V_out = (5 * adc[10]) / 2; // 2.5 (5/2) stepsize of adc + send_answer_hex(&rxbuf[0], V_out); + } + // DCDC 1 + if (hex_to_int(rxbuf[3]) == 1) { + V_out = (5 * adc[7]) / 2; + send_answer_hex(&rxbuf[0], V_out); + } + // DCDC 2 + if (hex_to_int(rxbuf[3]) == 2) { + V_out = (5 * adc[6]) / 2; + send_answer_hex(&rxbuf[0], V_out); + } + // DCDC 3 + if (hex_to_int(rxbuf[3]) == 2) { + V_out = (5 * adc[4]) / 2; + 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; + ; + send_answer_hex(&rxbuf[0], GND); } - - // 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); - } } } - if (rxcnt >= 10 || buf == '\n' || buf == '\r') { rxcnt = 0; } -} + if (rxcnt >= 11 || buf == '\n' || buf == '\r') { + rxcnt = 0; + } + } } + ISR(ADC_vect) { static uint8_t channel = 0; adc[channel] = ADC; - - if (channel == 1) channel = 4; - else if (channel == 7) channel = 13; - else if (channel == 13)channel = 0; - else channel++; - + + if (channel == 1) channel = 4; + else if (channel == 7) channel = 13; + else if (channel == 13) channel = 0; + else channel++; + ADMUX &= 0xe0; ADMUX |= (channel & 0xf); - if (channel == 13) ADCSRB |= (1< 11 || txbuf[txpoint] == 0) { - txpoint = 0; - UCSR1B &= ~(1<< UDRIE1); //deactivate Transmit - } - } - + if (txbuf[txpoint] != 0) + UDR1 = txbuf[txpoint++]; + if (txpoint > 11 || txbuf[txpoint] == 0) { + txpoint = 0; + UCSR1B &= ~(1 << UDRIE1); // deactivate Transmit + } +} + ISR(TIMER0_OVF_vect) { time++; asm volatile("wdr"); -} - +} + __attribute__((naked)) void main(void) { - + CLKPR = (1 << CLKPCE); // prescaler 2 = 8 MHz CLKPR = (1 << CLKPS0); // prescaler 2 - // Configure ports - - MCUCR |= (1< 0: no PullUp 1: Pullup + // DDRx : 0 = Input; 1 = Output + // PORTx : Input -> 0: no PullUp 1: Pullup // Output -> 0: LOW 1: HIGH PORTB = 0b00000000; - DDRB = 0b11101110; + DDRB = 0b11101110; PORTC = 0b00000000; - DDRC = 0b11000000; + DDRC = 0b11000000; PORTD = 0b00001100; - DDRD = 0b01011000; - + DDRD = 0b01011000; + PORTE = 0b00000000; - DDRE = 0b00000000; + DDRE = 0b00000000; PORTF = 0b00000000; - DDRF = 0b00000000; - - //Timer0 at 30 Hz overflow for ADC control + DDRF = 0b00000000; + + // Timer0 at 30 Hz overflow for ADC control TCCR0B = (5 << CS00); - TIMSK0 = (1 << TOIE0); //Overflow interrupt` + TIMSK0 = (1 << TOIE0); // Overflow interrupt` - //Init USART - UCSR1A = (1 << U2X1); // Double Speed Mode - //UCSR1A = (0 << U2X1); // Single Speed Mode + // Init USART + UCSR1A = (1 << U2X1); // Double Speed Mode + // UCSR1A = (0 << U2X1); // Single Speed Mode UCSR1B = (1 << RXCIE1) | (0 << TXCIE1) | (0 << RXEN1) | (1 << TXEN1); - UCSR1C = (3 << UCSZ10); //8 Bit - UBRR1 = 0x10; // 38k4 (SSM) //0x33; // 38k4 //0x10; //57600 + UCSR1C = (3 << UCSZ10); // 8 Bit + UBRR1 = 0x10; // 38k4 (SSM) //0x33; // 38k4 //0x10; //57600 _delay_ms(10); UCSR1B |= (1 << RXEN1); - -// ADMUX = (3 << REFS0); //reference 2.56V internal -// ADCSRA = (1 << ADEN) | (0 << ADSC) | (1 << ADIE) | (7 << ADPS0); //enable, start, irq, /128 -// DIDR0 = 0b11111111; -// DIDR2 = (1 << ADC13D); -// ADMUX &= 0xe0; ADMUX |= 1; ADCSRB |= (1<= 0) { -// isMaster = 1; -// //SELECT_MASTER(); -// getdata(n); -// } - - if((time != lasttime)) { + + while (1) { + // int n = usb_serial_getchar(); + // if (n >= 0) { + // isMaster = 1; + // //SELECT_MASTER(); + // getdata(n); + // } + + if ((time != lasttime)) { } lasttime = time; }