picadae/ctrl/Makefile,main.c : Added code to allow ATMega2560 as target.
This commit is contained in:
parent
3fbe3ad019
commit
db1ab31279
@ -2,14 +2,39 @@ ifndef TTY
|
|||||||
TTY=/dev/ttyACM0
|
TTY=/dev/ttyACM0
|
||||||
endif
|
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:
|
# compiler flags:
|
||||||
# -Os : optimize size
|
# -Os : optimize size
|
||||||
# -DF_CPU=16000000UL : define F_CPU as 16Mghz
|
# -DF_CPU=16000000UL : define F_CPU as 16Mghz
|
||||||
# -mmcu=atmega328p : target MCU
|
# -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
|
main.hex : main.c
|
||||||
# compile to object file (optimize for size)
|
# 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
|
# link as ELF binary
|
||||||
#avr-gcc -mmcu=atmega328p main.o -o main.elf
|
#avr-gcc -mmcu=atmega328p main.o -o main.elf
|
||||||
# convert ELF format to an IHEX format as used by avrdude
|
# convert ELF format to an IHEX format as used by avrdude
|
||||||
@ -17,7 +42,7 @@ main.hex : main.c
|
|||||||
|
|
||||||
|
|
||||||
burn:
|
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 :
|
clean :
|
||||||
rm main.o twi.o main.elf main.hex
|
rm main.o twi.o main.elf main.hex
|
||||||
|
@ -10,6 +10,16 @@
|
|||||||
|
|
||||||
#include "twi.h"
|
#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
|
#define SER_BUF_N (16) // size of receive buffer
|
||||||
@ -102,7 +112,7 @@ void i2c_init()
|
|||||||
twi_init();
|
twi_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(USART_RX_vect)
|
ISR(SERIAL_RX_ISR)
|
||||||
{
|
{
|
||||||
// receive the incoming byte
|
// receive the incoming byte
|
||||||
ser_buf[ ser_buf_i_idx ] = uart_getchar();
|
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
|
DDRB |= _BV(DDB5); // set led pin for output
|
||||||
|
|
||||||
timer_init(); // setup the timer
|
|
||||||
uart_init(); // setup UART data format and baud rate
|
uart_init(); // setup UART data format and baud rate
|
||||||
i2c_init();
|
i2c_init();
|
||||||
sei(); // re-enable interrupts
|
sei(); // re-enable interrupts
|
||||||
@ -165,12 +155,6 @@ int main (void)
|
|||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
if( timerFl )
|
|
||||||
{
|
|
||||||
//PORTB ^= _BV(PORTB5); // toggle LED
|
|
||||||
|
|
||||||
timerFl = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there are bytes waiting in the serial buffer
|
// if there are bytes waiting in the serial buffer
|
||||||
if( ser_buf_o_idx != ser_buf_i_idx )
|
if( ser_buf_o_idx != ser_buf_i_idx )
|
||||||
|
Loading…
Reference in New Issue
Block a user