External interrupts are not working when UART is disconnected.
Posted: Wed Apr 07, 2021 12:48 am
Hi,
The scetch is working correctly when UART is connected to computer.
And does not work when UART is disconnected.
What is a reason?
Thanks.
Power is independent.
USB-TTL adapter has 4 wires (GND, RX, TX, DTR)
byte ledPin1 = 4;
byte ledPin2 = 16;
byte ledPin3 = 23;
byte interruptPin1 = 39;
byte interruptPin2 = 36;
byte interruptPin3 = 34;
volatile byte state1 = LOW;
volatile byte state2 = LOW;
volatile byte state3 = LOW;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(interruptPin1, INPUT);
pinMode(interruptPin2, INPUT);
pinMode(interruptPin3, INPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin1), blink1, CHANGE);
attachInterrupt(digitalPinToInterrupt(interruptPin2), blink2, CHANGE);
attachInterrupt(digitalPinToInterrupt(interruptPin3), blink3, CHANGE);
}
void loop() {
}
/* interrupt function toggle the LED */
void blink1() {
state1 = !state1;
digitalWrite(ledPin1, state1);
}
void blink2() {
state2 = !state2;
digitalWrite(ledPin2, state2);
}
void blink3() {
state3 = !state3;
digitalWrite(ledPin3, state3);
}
The scetch is working correctly when UART is connected to computer.
And does not work when UART is disconnected.
What is a reason?
Thanks.
Power is independent.
USB-TTL adapter has 4 wires (GND, RX, TX, DTR)
byte ledPin1 = 4;
byte ledPin2 = 16;
byte ledPin3 = 23;
byte interruptPin1 = 39;
byte interruptPin2 = 36;
byte interruptPin3 = 34;
volatile byte state1 = LOW;
volatile byte state2 = LOW;
volatile byte state3 = LOW;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(interruptPin1, INPUT);
pinMode(interruptPin2, INPUT);
pinMode(interruptPin3, INPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin1), blink1, CHANGE);
attachInterrupt(digitalPinToInterrupt(interruptPin2), blink2, CHANGE);
attachInterrupt(digitalPinToInterrupt(interruptPin3), blink3, CHANGE);
}
void loop() {
}
/* interrupt function toggle the LED */
void blink1() {
state1 = !state1;
digitalWrite(ledPin1, state1);
}
void blink2() {
state2 = !state2;
digitalWrite(ledPin2, state2);
}
void blink3() {
state3 = !state3;
digitalWrite(ledPin3, state3);
}