From 1d25e73e3d6d789b52433afee4ab3a1f70019912 Mon Sep 17 00:00:00 2001 From: realraum Date: Mon, 12 Dec 2011 22:34:01 +0000 Subject: [PATCH] first working timer interupt for rf433rcv --- rf433rcv/teensy/Makefile | 2 +- rf433rcv/teensy/example.c | 94 ++++++++++++++---------------------------- rf433rcv/teensy/usb_rawhid.c | 4 +- 3 files changed, 35 insertions(+), 65 deletions(-) diff --git a/rf433rcv/teensy/Makefile b/rf433rcv/teensy/Makefile index edf9f8a..8bd5973 100644 --- a/rf433rcv/teensy/Makefile +++ b/rf433rcv/teensy/Makefile @@ -444,7 +444,7 @@ gccversion : # Program the device. program: $(TARGET).hex $(TARGET).eep - $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) + ~/teensy_loader_cli/teensy_loader_cli -mmcu=atmega32u4 -w $(TARGET).hex # Generate avr-gdb config/init file which does the following: diff --git a/rf433rcv/teensy/example.c b/rf433rcv/teensy/example.c index 635b16f..649b207 100644 --- a/rf433rcv/teensy/example.c +++ b/rf433rcv/teensy/example.c @@ -26,83 +26,53 @@ #include #include #include "usb_rawhid.h" -#include "analog.h" #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) volatile uint8_t do_output=0; -uint8_t buffer[64]; +uint8_t read_buffer[64]; +uint8_t write_buffer[64]; int main(void) { - int8_t r; - uint8_t i; - uint16_t val, count=0; + int8_t r; + uint8_t i; + uint16_t val, count=0; - // set for 16 MHz clock - CPU_PRESCALE(0); + // set for 16 MHz clock + CPU_PRESCALE(0); + DDRF|=3; + PORTF&=~1; + // Configure timer 0 to generate a timer overflow interrupt every + // 200*8 clock cycles, 100us + TCCR0A = 1<0) + usb_rawhid_send(read_buffer, 50); - // Wait an extra second for the PC's operating system to load drivers - // and do whatever it does to actually be ready for input - _delay_ms(1000); - - // Configure timer 0 to generate a timer overflow interrupt every - // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock - TCCR0A = 0x00; - TCCR0B = 0x05; - TIMSK0 = (1< 0) { - // output 4 bits to D0, D1, D2, D3 pins - DDRD = 0x0F; - PORTD = (PORTD & 0xF0) | (buffer[0] & 0x0F); - // ignore the other 63.5 bytes.... - } - // if time to send output, transmit something interesting - if (do_output) { - do_output = 0; - // send a packet, first 2 bytes 0xABCD - buffer[0] = 0xAB; - buffer[1] = 0xCD; - // put A/D measurements into next 24 bytes - for (i=0; i<12; i++) { - val = analogRead(i); - buffer[i * 2 + 2] = val >> 8; - buffer[i * 2 + 3] = val & 255; - } - // most of the packet filled with zero - for (i=26; i<62; i++) { - buffer[i] = 0; - } - // put a count in the last 2 bytes - buffer[62] = count >> 8; - buffer[63] = count & 255; - // send the packet - usb_rawhid_send(buffer, 50); - count++; - } - } + } } // This interrupt routine is run approx 61 times per second. -ISR(TIMER0_OVF_vect) +ISR(TIMER0_COMPA_vect) { - static uint8_t count=0; + PORTF^=2; - // set the do_output variable every 2 seconds - if (++count > 122) { - count = 0; - do_output = 1; - } } diff --git a/rf433rcv/teensy/usb_rawhid.c b/rf433rcv/teensy/usb_rawhid.c index dae1214..036fbd7 100644 --- a/rf433rcv/teensy/usb_rawhid.c +++ b/rf433rcv/teensy/usb_rawhid.c @@ -34,8 +34,8 @@ **************************************************************************/ // You can change these to give your code its own name. -#define STR_MANUFACTURER L"MfgName" -#define STR_PRODUCT L"Teensy Raw HID Example" +#define STR_MANUFACTURER L"realraum" +#define STR_PRODUCT L"rf433rxtx" // These 4 numbers identify your device. Set these to // something that is (hopefully) not used by any others! -- 1.7.10.4