Hello everyone,
I'm doing a project based on the Arduino Pro Mini board (3.3V version) coupled with a GSM-GPS A7 module.
I created a serial port with NeoSWSerial.h (using the D11 and D10 pins of the arduino Pro Mini) for dialogue and At Commands with the GSM module, while the data from the GPS are received by the hardware port (pin D0 of the arduino board) .
Everything works perfectly.
Later I decided to try using the Interrupt function on Pin D2, but it seems like there's some problem doing this, because the software doesn't work properly anymore.
Is it possible that in the Hardware-Software condition that I am using and described, it is not possible to use interrupts?
Thanks for your help.
Is it possible that in the Hardware-Software condition that I am using and described, it is not possible to use interrupts?
Anything is possible. To say what is most likely the problem, we'd need to see your code, know what is connected to pin 2, and know exactly what the program does, and does not, do.
There is nothing connected to Pin D2 (interrupt 0).
Just a wire to connect to GND for test.
I have just declared the interrupt and the Pin related to the same interrupt.
I also noticed that during the initialization phase of the GSM module, and the program started, the LED turns on and off even without an interrupt event.
When interrupt pin goes to GND I want to turn on the led connected to pin 13.
[/
const byte interruptPin = 2;
void setup()
{
pinMode (interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), DoSomething, FALLING);
{
void DoSomething() {
digitalWrite (13, HIGH);
delay (1000);
digitalWrite (13, LOW);
}
code]
There is nothing connected to Pin D2 (interrupt 0).
Only a wire to manually connect to GND.
Is there something connected? Or not? Nothing but a wire is a stupid answer.
If there is a wire, connected to ground, the state of the pin will never change, so there never will be a FALLING edge to trigger the interrupt.
NeoSWSerial (as all swSerials) disables interrupts during TX-phase for accurate timing as far as i know. But hereit shows an overview of it's advantages and confirms what i mentioned (also that during RX they are partly disabled) this will cause conflicts. Just the calling of the interrupts may take precedence over the ones you use (or vice versa)
Thanks for replies Paul,
I anwered to your question correctly.
There is nothing connected to Pin D2 (interrupt 0).
Just a wire (not connected except to the pin D2) that I use to connect it manually to GND for test the interrupt event.
In other words the wire is floating.
Antony3000:
In other words the wire isfloatingan antenna.
Thanks for replies Deva_Rishi,
And then I can't use interrupt routines?
Or I must changing something in the hardware (or in the software)?
Antony3000:
const byte interruptPin = 2;void setup()
{pinMode (interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), DoSomething, FALLING);{
void DoSomething() {
digitalWrite (13, HIGH);
delay (1000);
digitalWrite (13, LOW);
}
It's really hard to imagine doing anything worse in an ISR than this.
gfvalvo:
It's really hard to imagine doing anything worse in an ISR than this.
I know that the ISR code is very wrong, but I wrote it only for a test.
I also changed delay (1000) with delay (10), but the result doesn't change much.
Furthermore, I have already written that the LED turns on during the initialization phase of the GSM module, even without any simulated interrupt event.
So it seems that the real problem is not the delay (1000) but probably a conflict with NeoSWerial.
Antony3000:
So it seems that the real problem is not the delay (1000) but probably a conflict with NeoSWerial.
That may be A real problem. But, ANOTHER real problem is that you don't understand how interrupts and delay() work:
- delay() depends on the millis timer.
- the millis timer depends on interrupts
- interrupts are disabled during an ISR
See the problem?
gfvalvo:
That may be A real problem. But, ANOTHER real problem is that you don't understand how interrupts and delay() work:
- delay() depends on the millis timer.
- the millis timer depends on interrupts
- interrupts are disabled during an ISR
See the problem?
Do you think that (with a correct ISR without delay()) I will can use interrupts?
I've never used NeoSWSerial.
Antony3000:
Do you think that (with a correct ISR without delay()) I will can use interrupts?
I think you can use a Timer-interrupt that calls a polling ISR, while you are using (any) swSerial. But if you want to use a hw-Interrupt then you should disable swSerial (as described in the documentation for NeoSwSerial) and not expect the interrupt to fire correctly during swSerial communication. I am not saying it is not possible, but i would try doing it 1 thing at the time. 9600 Baud i am confident you'll manage. how often do you think you need to poll ?
Deva_Rishi:
I think you can use a Timer-interrupt that calls a polling ISR, while you are using (any) swSerial. But if you want to use a hw-Interrupt then you should disable swSerial (as described in the documentation for NeoSwSerial) and not expect the interrupt to fire correctly during swSerial communication. I am not saying it is not possible, but i would try doing it 1 thing at the time. 9600 Baud i am confident you'll manage. how often do you think you need to poll ?
Thanks for replies,
I need to poll not more than every 1000 ms. (1 s).
Probably the time for execute an entire loop cycle is less than 1000 ms, and then I think to resolve the problem with a simple polling of a pin state.
I tryed to use pin 2 as simple digital input pin with pull-up to poll it every 1000 ms., but it seems does't work.
Antony3000:
I tryed to use pin 2 as simple digital input pin with pull-up to poll it every 1000 ms., but it seems does't work.
please show us the code..