Intro to AVR ATtiny 2313 CS 423 Dick

  • Slides: 16
Download presentation
Intro to AVR ATtiny 2313 CS 423 Dick Steflik

Intro to AVR ATtiny 2313 CS 423 Dick Steflik

AVR ATtiny 2313

AVR ATtiny 2313

2313 Features RISC, 120 instructions, most executable in one clock cycle, 32 x 8

2313 Features RISC, 120 instructions, most executable in one clock cycle, 32 x 8 general purpose registers, up to 20 MIPS at 20 Mhz Memory - 2 Kbytes Flash, 128 Bytes EEPROM, 128 bytes SRAM Peripherals Features – 1 -8 bit timer, 1 - 16 bit timer, 4 - PWM channels, On-chip analog comparitor, watchdog timer, Universal Serial Interface, Full Duplex USART 18 programmable I/O lines Operating Voltage – 2. 7 – 5. 5 VDC In System Programmable via SPI (Serial Peripheral Interface)

Basic Pin Descriptions VCC – Digital Supply Voltage Gnd – ground Port A (PA

Basic Pin Descriptions VCC – Digital Supply Voltage Gnd – ground Port A (PA 2. . PA 0) – 3 bit, bi-directional I/O with selectable internal pullups Port B (PB 7. . PB 0) – 8 bit, bi-directional I/O with selectable internal pullups Port D (PD 6 -PD 0) - 7 bit, bi-directional I/O with selectable internal pullups Reset – system reset – active low XTAL 1 – external crystal input (alt. PA 0) XTAL 2 – external crystal output (alt. PA 1)

Serial Peripheral Interface Bus SPI is used by all Atmel microcontrollers for loading the

Serial Peripheral Interface Bus SPI is used by all Atmel microcontrollers for loading the flash program memory (many other OEMs also) Easily implemented in hardware Faster than other methods (I 2 C, SMBUS) Master-slave methodology Half or Full Duplex operation

SPI with 2 slaves SPI Master SPI Slave 1 SCLK MOSI MISO SS 1

SPI with 2 slaves SPI Master SPI Slave 1 SCLK MOSI MISO SS 1 SS SS 2 SPI Slave 2 SCLK MOSI MISO SS

AVR Programming AVR Programmer PC AVRDUDE PPT RS 232 USB ATtiny 2313 VCC SCLK

AVR Programming AVR Programmer PC AVRDUDE PPT RS 232 USB ATtiny 2313 VCC SCLK MOSI VCC (20) SCLK (19) MISO (18) GND RESET (1) GND (10) MOSI (17) GND

API Applications Flash, EEPROM, MMC and SD cards Sensors Temperature Pressure (touch screens) LCD

API Applications Flash, EEPROM, MMC and SD cards Sensors Temperature Pressure (touch screens) LCD Panels Communications (802. 15 (Zig. Bee), CAN, Ethernet. . ) Control – D/A, A/D, Digital Pots, position encoders

/* Blinker Demo */ /* Include useful pre-defined functions */ #include <avr/interrupt. h> //

/* Blinker Demo */ /* Include useful pre-defined functions */ #include <avr/interrupt. h> // Defines pins, ports, etc to make programs easier to read #define F_CPU 100000 UL // Sets up the default speed for delay. h #include <util/delay. h> int main(){ DDRD = _BV(PD 4); while(1){ PORTD = _BV(PD 4); _delay_ms(1000); PORTD &= ~_BV(PD 4); _delay_ms(1000); } return(0); } /* enable output on port D, pin 4 */

Interrupts 1 0 x 0000 BOR, Watchdog Reset 2 0 x 0001 0 3

Interrupts 1 0 x 0000 BOR, Watchdog Reset 2 0 x 0001 0 3 0 x 0002 1 4 0 x 0003 Event 5 0 x 0004 Match A 6 0 x 0005 7 0 x 0006 8 0 x 0007 complete 9 0 x 0008 Empty 10 0 x 0009 Complete 11 0 x 000 A 12 0 x 000 B 13 0 x 000 C Match B 14 0 x 000 D Match A Reset External Pin, POR, INT 0 External Interrupt Request INT 1 External Interrupt Request TIMER 1 CAPT Timer/Counter 1 Capture TIMER 1 COMPA Timer/Counter 1 Compare TIMER 1 OVF TIMER 0 OVF USART 0, RX Timer/Counter 1 Overflow Timer/Counter 0 Overflow USART 0 Receive USART 0 UDRE USART 0 Data Register USART 0 RX USART 0 Transmit ANALOG COMP PCINT TIMER 1 COMPB Analog Comparitor Pin Change Interrupt Timer/Counter 1 Compare TIMER 0 COMPA Timer/Counter 0 Compare

ISR Macro #include <avr/interrupt. h> Defines the beginning of your Interrupt Servicing Routine Places

ISR Macro #include <avr/interrupt. h> Defines the beginning of your Interrupt Servicing Routine Places the starting address of the ISR code into the interrupt vector ISR(SIG_INT 0) { cli(); //disable interrupts. . . sei(); // enable interrupts } places address of the body if the ISR into 0 x 0001

Programmable Interrupts INT 0 - Pin 6 INT 1 – Pin 7 PCINT –

Programmable Interrupts INT 0 - Pin 6 INT 1 – Pin 7 PCINT – Pins 12 -19 PCMSK – Pin Change Mask Register Which pins contribute to the pin change interrupt 4 different pin changes can be detected Pin goes low Any logical change Falling edge Rising edge

Interrupt Sense Control Interrupt 1 Sense Control ISC 11 ISC 10 Description 0 0

Interrupt Sense Control Interrupt 1 Sense Control ISC 11 ISC 10 Description 0 0 0 1 1 Low level on INT 1 Any logical change on INT 1 Falling edge on INT 1 Rising Edge on INT 1 Interrupt 0 Sense Control ISC 01 ISC 00 Description 0 0 0 1 on INT 0 1 1 Low level on INT 0 Any logical change Falling edge on INT 0 Rising Edge on INT 0

MCU Control Register Defines which of the four states will activate the interrupt ex.

MCU Control Register Defines which of the four states will activate the interrupt ex. MCUCR = (1<<ISC 01) | (1<<ISC 00) Interrupt on pin INT 0 falling edge

Example #include <avr/interrupt. h> int main(void) { // set Pin 6 (PD 02) as

Example #include <avr/interrupt. h> int main(void) { // set Pin 6 (PD 02) as the interrupt pin PCMSK |= (1<<PIND 2); // interrupt on INT 0 falling edge MCUCR = (1<<ISC 01) | (1 << ISC 00); // turn on interrupts GIMSK |= (1<<INT 0); // wait for interrupt while (1) {. . . };