From db1ab312791ae973fc88f1b732608dd07e094c6a Mon Sep 17 00:00:00 2001 From: "kevin.larke" Date: Mon, 18 Nov 2019 09:35:08 -0500 Subject: [PATCH] picadae/ctrl/Makefile,main.c : Added code to allow ATMega2560 as target. --- control/ctrl/Makefile | 29 +++++++++++++++++++++++++++-- control/ctrl/main.c | 38 +++++++++++--------------------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/control/ctrl/Makefile b/control/ctrl/Makefile index 09dc77a..37a0eb9 100644 --- a/control/ctrl/Makefile +++ b/control/ctrl/Makefile @@ -2,14 +2,39 @@ ifndef TTY TTY=/dev/ttyACM0 endif +MMCU=atmega328 +#MMCU=atmega2560 + +ifeq ($(MMCU),atmega328) +PROG_MMCU=atmega328p +PROG_DEV=arduino +AVRD_CONF= +DISABLE_AUTO_ERASE= +SKIP_CHECKS=-FV +endif + +ifeq ($(MMCU),atmega2560) +PROG_MMCU=$(MMCU) +PROG_DEV=wiring +AVRD_CONF=-C/etc/avrdude/avrdude.conf +DISABLE_AUTO_ERASE=-D +SKIP_CHECKS=-FV +endif + + + # compiler flags: # -Os : optimize size # -DF_CPU=16000000UL : define F_CPU as 16Mghz # -mmcu=atmega328p : target MCU +# -F : skip device signature read +# -V : disable automatic verify step +# -v : enable verbose output +# -D : disable auto erase flash main.hex : main.c # compile to object file (optimize for size) - avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -o main.elf main.c twi.c + avr-gcc -Os -DF_CPU=16000000UL -mmcu=$(MMCU) -o main.elf main.c twi.c # link as ELF binary #avr-gcc -mmcu=atmega328p main.o -o main.elf # convert ELF format to an IHEX format as used by avrdude @@ -17,7 +42,7 @@ main.hex : main.c burn: - avrdude -F -V -c arduino -p ATMEGA328P -P $(TTY) -b 115200 -U flash:w:main.hex + avrdude $(SKIP_CHECKS) -v $(AVRD_CONF) -c$(PROG_DEV) -p$(PROG_MMCU) -P$(TTY) -b 115200 $(DISABLE_AUTO_ERASE) -U flash:w:main.hex:i clean : rm main.o twi.o main.elf main.hex diff --git a/control/ctrl/main.c b/control/ctrl/main.c index 6f4ac25..73e0c14 100644 --- a/control/ctrl/main.c +++ b/control/ctrl/main.c @@ -10,6 +10,16 @@ #include "twi.h" +#define ICP_PRE_SCALE (4) +#if defined(__AVR_ATmega2560__) +#define SERIAL_RX_ISR USART0_RX_vect +#elif defined(__AVR_ATmega328__) +#define SERIAL_RX_ISR USART_RX_vect +#else +#error Unknown target processor +#endif + + //------------------------------------------------------------------------------ #define SER_BUF_N (16) // size of receive buffer @@ -102,7 +112,7 @@ void i2c_init() twi_init(); } -ISR(USART_RX_vect) +ISR(SERIAL_RX_ISR) { // receive the incoming byte ser_buf[ ser_buf_i_idx ] = uart_getchar(); @@ -112,25 +122,6 @@ ISR(USART_RX_vect) } -//-------------------------------------------------------------------------------------------------- -static volatile int timerFl = 0; - - -ISR(TIMER1_COMPA_vect) -{ - timerFl = 1; -} - -void timer_init(void) -{ - TCCR1A = 0; // set timer control registers to default - TCCR1B = 0; // - OCR1A = 15624; // 1 Hz = 16Mghz / (1024 * 15624) - TCCR1B |= (1 << WGM12); // CTC mode on - TCCR1B |= (1 << CS10); // Set CS10 and CS12 bits for 1024 prescaler: - TCCR1B |= (1 << CS12); // - TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt -} //-------------------------------------------------------------------------------------------------- @@ -156,7 +147,6 @@ int main (void) DDRB |= _BV(DDB5); // set led pin for output - timer_init(); // setup the timer uart_init(); // setup UART data format and baud rate i2c_init(); sei(); // re-enable interrupts @@ -165,12 +155,6 @@ int main (void) for(;;) { - if( timerFl ) - { - //PORTB ^= _BV(PORTB5); // toggle LED - - timerFl = 0; - } // if there are bytes waiting in the serial buffer if( ser_buf_o_idx != ser_buf_i_idx )