Hi,
Background:I am trying to set up an Arduino Mega (master) to ATTiny84 (slave) using SPI.
Since there will be more than one ATTiny84 slaves, I need to use the SS to tell the ATTiny to start listening to the incoming transmission.
While I plan to use some code from (
http://forum.arduino.cc/index.php?topic=71975.0 and
http://forum.arduino.cc/index.php/topic,126771.15.html) but neither talks about the SS interrupt.
My plan is to use Pin12 (PCINT1) to receive a falling edge interrupt to set a flag. If flag is set, USI_OVF_vect subroutine processes the received byte else discards it.
Question:What code allows me to detect the interrupt on a falling edge on the specified pin?
Here's my existing code which doesn't work.
I would like to turn on LED2 when I pull CS low but currently this code only causes LED1 and LED0 to flicker (they should not as the analog inputs are set to make them stay on all the time)
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define LED2_PIN 1 //Pin3 on chip
#define LED1_PIN 5 //Pin8 on chip
#define LED0_PIN 6 //Pin9 on chip
#define ADC_IN0 A2 //Pin11 on chip will read a pot value in future
#define ADC_IN1 A3 //Pin10 on chip
#define CS 9 //Pin12 on chip
int cnt=0;
int p0=LOW;
int p1=LOW;
int p2=LOW;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(LED0_PIN, OUTPUT);
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(CS , INPUT);
digitalWrite(LED0_PIN, LOW); //the LED is on
digitalWrite(LED1_PIN, LOW); //the LED is on
digitalWrite(LED2_PIN, LOW); //the LED is on
sei();
sbi(GIMSK,PCIE0); // Turn on Pin Change interrupt <=Not sure this is correct
sbi(PCMSK0,PCINT1); // Which pins are affected by the interrupt <=Not sure this is correct
}
ISR(PCINT1_vect){ <=Not sure this is correct
p2=(p2==HIGH)?LOW:HIGH;
}
// the loop routine runs over and over again forever:
void loop() {
delay(200);
p0 = (analogRead(ADC_IN0)>512)?HIGH:LOW;
p1 = (analogRead(ADC_IN1)<512)?HIGH:LOW;
digitalWrite(LED0_PIN, p0);
digitalWrite(LED1_PIN, p1);
digitalWrite(LED2_PIN, p2);
}
Additional info:I am using core files for ATTiny84 from here:
http://arduino-tiny.googlecode.com/files/arduino-tiny-0100-0017.zipwhich seems a little wonky. When I used the 8MHz chip option my delay(1000) took 8 seconds to execute. So I am using the 1MHz option in board type.
Thanks.
Regards,
Abe