Go Down

Topic: ATTiny85 registers sending me a bit nuts...  (Read 196 times) previous topic - next topic


Well, I am basically trying to learn about interrupts so made a basic circuit with an ATTiny85 with a Red LED on digital 3 (PB2) and a green LED on digital pin 4 (PB3).

I have a 100ohm resisted wire from the 5v rail supply being used to "flip" PB5 (digital 0) pins logic. I was expecting the LEDs to alternate depending on wether I have bothered to change the logic in the last second...
The red LED stays on no matter what!

I have annotated my code with some references I have gotten in the datasheet...

Code: [Select]

volatile unsigned long some_variable;

ISR(PCINT0_vect) {

void setup()
  SREG =  0b10000000; //Set bit I to 1 in SREG byte (AVR Status Register). 4.4.1 in datasheet. -> Enables interrupts.
  MCUCR = 0b00000001; // A change in pin logic will cause the ISR to be initiated (9.3.1 in datasheet).
  GIMSK = 0b01000000;   // Enable pin change interrupt Table 9.3.2
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, INPUT);


void loop ()   {
if (some_variable=1){

    digitalWrite(3, HIGH);


} //loop


Hello there,

Regarding tje input pin, I would suggext to use a 10k pullup and leave it connected to vcc all the time.  You can then use a switch or a simple piece of wire to connect it to gnd.  As it is,  i believe the input pin is either tied to vcc or left floating. Is my assumption correct?

In the isr,  you are forcing the value of the variable without ever reading the status of the input pin.  I would suggest to perform a read of the input pin and assign the result to the variable.

Don't know whether it will help,  these are just suggestions...


Coding Badly

Go Up