attiny 45/85,attachinterupt problem. Need help

Hi i am using attiny 45/85 as master for sending pulses on a device (slave) on 2 chanels (pins),
it works fine but i have a problem when i add on my code these lines

void setup() {
attachInterrupt(0, pin_check, RISING);   


void pin_check(){  


as you can see there is an interrupt that calls an empty function (pin_check),

the problem is that when i change that pin from low to high many times (with a button) the slave device (that reads the pulses i am sending) shows an error (in a display), so that means that there is a wrong in the pulses that my attiny is sending.

what is the problem on interupt that couses this problem? it runs an empty function! very strange on me!

does interupt stop the main void loop?

please help me

i am using arduino as ISP for attiny

does interupt stop the main void loop?

It doesn't stop it. It interrupts it, like a ringing telephone interrupts you from reading a book. When the interrupt has been dealt with (or, ignored, in your case), control returns to loop, right where it left off.

so you just help me found the problem on my situation

my attiny reads pulses from a sensor, and then send them to the device (slave) so when it interupts the code (that is reading the pulses from the sensor) it loses time and the logic data is there any idea how to fix it?

Tell us more about the pulses you're trying to send.

Or, for an even better answer, post your Sketch.

int input_CH_A = 4; //this pin goes to sensor
int pin_interrupt = 2;
int output_CH_A=3;//the output pin
int output_CH_B=1;//the output pin

void setup()
  pinMode(input_CH_A , INPUT);
  pinMode(pin_interrupt , INPUT);
  attachInterrupt(0, pin_check, RISING);

void pin_check()

void loop(){
  if (digitalRead(input_CH_A)==1){ 
      pinMode(output_CH_A , INPUT); //A=1 With a pullup resistor
      pinMode(output_CH_B , OUTPUT); 
      digitalWrite(output_CH_B,0); //B=0 
  if (digitalRead(input_CH_A)==0){  
      pinMode(output_CH_A , OUTPUT); 
      digitalWrite(output_CH_A,0); //A=0
      pinMode(output_CH_B , INPUT); //B=1 With a pullup resistor


Is input_CH_A (pin 4) a connection from the slave to the 45/85 master?

What is the slave?

You never read from output_CH_A or output_CH_B. What is the purpose of setting them to input?

no i just rename it, it is an input pin that it is connected with a sensor

so it works like this



i have a pullup resistor on them so when i change it to input that pin goes on high, if you dont mind see that like digitalWrite(output_CH_A,1);

if you dont mind see that like digitalWrite(output_CH_A,1);

Is there some advantage to doing it your way over the simpler to understand declaration of output_CH_A as an output and setting it with digitalWrite?

some times you need to do that if you want high (1) logic from another voltage source like 24v (that slave needs)

is there any way to check a pin if that rising or falling in a specific place of the code?

for example void loop (){ task(1); task(2); check_if_there_is_change_on_pin2();//i have no problem if that needs some microseconds


i am tryinng to find a solution on my problem,

my scetch is working but...all i need is to check if there is a change on pin2 and if yes to store value 1 on a variable. nothing more.

i remember that before 2 months i tried attachinterupt and then detachinterupt but it couldnt re-attachinterupt, on the next loop.

is it posible now?

If you don't need the immediacy of an interrupt, just poll the pin on each pass through loop. The longest delay from a state change to detection will be the time it takes for loop to complete a pass.

could you please make an example of that ? i didnt undestand you 100% (sorry for my bad english) what "poll" means here?

Polling means reading the pin state on every pass through loop:

void loop()
   int pinState = digitalRead(pin_interrupt );
   // Do whatever else needs to be done on each pass

but i want to know if there is change on that pin, not to read if this is high or low

On each pass, you need to read the current state of the pin (currValue), and record that. At the end of the loop, save that value as prevValue. Then, a state change has occurred if currValue != prevValue.

i think it is not correct

becouse what if in the begining of the loop the state is 1,in the middle is 0 and goes back to 1 in the end of the loop,where the sketh will store it to compare it?

i want the sketch to know if there is change betwwen the void loop

If loop executes fast enough, the chance of a state change occurring in loop is pretty small. But, if the change must be detected immediately, then you must use interrupts, and loop must be written in a way that makes it interrupt-able.

is it posible to enable and disable the interrupt when i want to do it? or how else can i fix my problem?how can i make it interrupt-able?
:’( :’(