При удалении команды else перестаёт выполняться условие и отправлять данные в Serial. Почему?
Было:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <NecDecoder.h>
NecDecoder ir;
void setup() {
Serial.begin(115200);
PORTA.DIRSET = PIN7_bm; // Set only PA7(LED) as output without affecting other pins
PORTA.DIRCLR = PIN5_bm; // Set PA5 to input
PORTA.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc; // Set PA5 to PULLUP with Interrupt sensing on Falling edge
sei();
}
void loop() {
if (ir.available()) {
Serial.println(ir.readData(), HEX);
PORTA.OUTTGL = PIN7_bm; // toggle LED
delay(100);
}
else {
PORTA.OUTCLR = PIN7_bm; // turn off LED
}
}
ISR(PORTA_PORT_vect) {
if (PORTA.INTFLAGS & PIN5_bm) { // only if the interrrupt trigger is for PA5
ir.tick();
PORTA.INTFLAGS = PIN5_bm; // clear PA5 interrupt flag
}
}
Стало
#include <avr/io.h>
#include <avr/interrupt.h>
#include <NecDecoder.h>
NecDecoder ir;
void setup() {
Serial.begin(115200);
PORTA.DIRSET = PIN7_bm; // Set only PA7(LED) as output without affecting other pins
PORTA.DIRCLR = PIN5_bm; // Set PA5 to input
PORTA.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc; // Set PA5 to PULLUP with Interrupt sensing on Falling edge
sei();
}
void loop() {
if (ir.available()) {
Serial.println(ir.readData(), HEX);
}
}
ISR(PORTA_PORT_vect) {
if (PORTA.INTFLAGS & PIN5_bm) { // only if the interrrupt trigger is for PA5
ir.tick();
PORTA.INTFLAGS = PIN5_bm; // clear PA5 interrupt flag
}
}
Верхний код это как было, нижний - как изменился loop, все остальное осталось без изменений. Верхний код работает, с изменениями не работает. Извольте - с.
чудеса.
Ну так возвращайте по одной оставшиеся строчки и смотрите, когда заработает. Там вариантов-то немного… Устройство у вас и этот тест никто, кроме вас, сделать не сможет.
Это козе ясно. Рабочий вариант у меня есть изначально. Я хочу докопаться до истины, почему это работает именно так. Хотя по моему разумению так работать не должно, где то я туплю. Согласно мануалу:
“PORTA.OUTTGL = PIN7_bm;” переключает состояние соответствующего пина порта А, а “PORTA.OUTCLR = PIN7_bm;” выставляет его в ноль. Вопрос: каким образом это влияет на “PIN5_bm” или на что-то еще, что препятствует выполнению условия с выводом в Serial?
Так тоже работает:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <NecDecoder.h>
NecDecoder ir;
void setup() {
Serial.begin(115200);
PORTA.DIRSET = PIN7_bm; // Set only PA7(LED) as output without affecting other pins
PORTA.DIRCLR = PIN5_bm; // Set PA5 to input
PORTA.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc; // Set PA5 to PULLUP with Interrupt sensing on Falling edge
sei();
}
void loop() {
if (ir.available()) {
Serial.println(ir.readData(), HEX);
}
PORTA.OUTCLR = PIN7_bm;
}
ISR(PORTA_PORT_vect) {
if (PORTA.INTFLAGS & PIN5_bm) { // only if the interrrupt trigger is for PA5
ir.tick();
PORTA.INTFLAGS = PIN5_bm; // clear PA5 interrupt flag
}
}
#include <avr/io.h>
#include <avr/interrupt.h>
#include <NecDecoder.h>
NecDecoder ir;
void setup() {
Serial.begin(115200);
PORTC.DIRSET = PIN1_bm; // Set only PA7(LED) as output without affecting other pins
PORTB.DIRCLR = PIN4_bm; // Set PA5 to input
PORTB.PIN4CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc; // Set PA5 to PULLUP with Interrupt sensing on Falling edge
sei();
}
void loop() {
if (ir.available()) {
Serial.println(ir.readData(), HEX);
PORTC.OUTTGL = PIN1_bm; // toggle LED
delay(100);
}
else {
PORTC.OUTCLR = PIN1_bm; // turn off LED
}
}
ISR(PORTB_PORT_vect) {
if (PORTB.INTFLAGS & PIN4_bm) { // only if the interrrupt trigger is for PA5
ir.tick();
PORTB.INTFLAGS = PIN4_bm; // clear PA5 interrupt flag
}
}
Так не работает:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <NecDecoder.h>
NecDecoder ir;
void setup() {
Serial.begin(115200);
PORTC.DIRSET = PIN1_bm; // Set only PA7(LED) as output without affecting other pins
PORTB.DIRCLR = PIN4_bm; // Set PA5 to input
PORTB.PIN4CTRL = PORT_PULLUPEN_bm | PORT_ISC_FALLING_gc; // Set PA5 to PULLUP with Interrupt sensing on Falling edge
sei();
}
void loop() {
if (ir.available()) {
Serial.println(ir.readData(), HEX);
}
}
ISR(PORTB_PORT_vect) {
if (PORTB.INTFLAGS & PIN4_bm) { // only if the interrrupt trigger is for PA5
ir.tick();
PORTB.INTFLAGS = PIN4_bm; // clear PA5 interrupt flag
}
}