Go Down

Topic: serial programming with interrupt on arduino due board (Read 1 time) previous topic - next topic

ashwinibhat

Hello,
      I am programming serial communication on Arduino due board with Cortex M0 controller,but with interrrupt programming.But it is not working?
It is possible or not?

Please give me reply as early as possible

PaulS

Quote
I am programming serial communication on Arduino due board with Cortex M0 controller

That programming looks like?

Quote
but with interrrupt programming.

Why? Why isn't polling adequate? What is sending the serial data? How much? How often?

Quote
But it is not working?

It isn't? Are you sure? Don't you know?

Quote
It is possible or not?

Yes.

ashwinibhat

Hello sir,
      I have checked serial communication with interrupt,but it not working. Please help me programming wise.
I have used attachInterrupt(2, buttonPress, CHANGE) function for external interrupt0. Here 'buttonPress' it is function
whichcan be called at interrupt.
      Depending upon pressing a button, i have send one string on serial monitor through ISR routine.But it is not printing.
What i do?
Give me suggestion.

AmbiLobe

The sketch you are using is too far away to see, it. Can you place the source code software on my video screen? I will poll my screen in one hour without using an interrupt tonight.
I am going to get going.

ashwinibhat

I am using panic button,depending upon their condition serial monitor get printed.below my code-



volatile int ButtonPin=2;               //one panic button attached to pin no 2 for generation of interrupt
int LEDpin=13;
int buttonState=HIGH;                 //first state of button
volatile boolean serial_flag=false;   //flag used in serial communication

void setup() {
  // put your setup code here, to run once:
 
  pinMode(ButtonPin,INPUT);
  pinMode(LEDpin,OUTPUT);
 
 
 
  //enable Interrupt0 which is connect to button
  attachInterrupt(2, buttonPress, CHANGE);
 
  //turn ON serial communication
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:

    if(serial_flag)
    {
       Serial.print("not pressed\n");
       serial_flag=false;
    }

    else
    {
       Serial.print("not pressed\n");
    }

}



void buttonPress()      //this is my ISR
{
     serial_flag=true;
}

Paul Stoffregen

Your code prints the same "not pressed\n" message in either case.  How can you tell if it is working if the 2 cases print exactly the same thing?

ashwinibhat

sorry its my mistake,but i have change that one
   since it is giving me "not pressed" on serial port,and when i press button then it get stop.



volatile int ButtonPin=2;               //one panic button attached to pin no 2 for generation of interrupt
int LEDpin=13;
int buttonState=HIGH;                 //first state of button
volatile boolean serial_flag=false;   //flag used in serial communication

void setup() {
  // put your setup code here, to run once:
 
  pinMode(ButtonPin,INPUT);
  pinMode(LEDpin,OUTPUT);
 
 
 
  //enable Interrupt0 which is connect to button
  attachInterrupt(2, buttonPress, CHANGE);
 
  //turn ON serial communication
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:

    if(serial_flag)
    {
       Serial.print("pressed\n");
       serial_flag=false;
    }

    else
    {
       Serial.print("not pressed\n");
    }

}



void buttonPress()      //this is my ISR
{
     serial_flag=true;
}

ashwinibhat

please anybody help me out for this as early as possible

trustnoone

I had similar problems using the interrupt once before, what does the hardware setup of the button look like?
Also don't forget to factor in debouncing if its a button.

ashwinibhat

have you check my above code?about hardware setup
one end of button is connected to ground & other end is connected to VCC by pull up resistor.


trustnoone

#11
Sep 07, 2013, 06:12 pm Last Edit: Sep 07, 2013, 06:26 pm by trustnoone Reason: 1

have you check my above code?about hardware setup
one end of button is connected to ground & other end is connected to VCC by pull up resistor.


This might seem like a silly question but I'm guessing you also have one end of the button connected to pin 2 right?
The code is looking okay, unless I'm missing something?
I'm not sure if it helps but would it be easier if the interrupt was set to a RISING or FALLING edge? That way you it wouldn't have as much of a problem with debouncing. But I'm guessing that still won't fix your problem.

Go Up