Go Down

Topic: setup() continuously println, although reset line only once LOW (Read 181 times) previous topic - next topic

JeepersCreepers

Purpose of sketch_sep10a is implement PCINT19 external interrupt RISING on pin D3

ext_isr(){ //Turn pin 8 enables opto-isolator on then off }

setup() { // Serial.println("s"); Enable pin 8 and pin 11 digital output, attachInterrupt on D3 to ext_isr, RISING }

loop() { // Turn pin 11 LED on then off, pin 11 connected to pin D3 }

Problem is that "s" is continuously printing on console COM9 although Arduino reset line is only once LOW
then remains HIGH, so if not repeatedly reset then what can cause setup to run and print continuously ?

Attaching .png for breadboard and Saleae trace, sketch code below:
Code: [Select]


#define D3 3
#define TRIG3 D3

int ext_isr_count = 0;
void ext_isr() {
  // Interrupt handler for TRIG3 on D3, blink pin 8 LED
  PORTB |= B00000001;  //Turn pin 8 LED on
  EIFR = 1; //Clear External Interrupt Flag 0
  PCIFR = 4; //Clear Pin Change Interrupt Flag 2 for PCINT[23:16]
  ext_isr_count++;
  delay(1);
  PORTB &= B11111110; //Turn pin 8 LED off
  return;
}
void config_PCINT() {
    EICRA = 3; //RISING 3 for INT0, later 15 for INT1 also
    EIMSK = 1; //INT0 enable, later 3 for INT1 also
    EIFR = 1; //Clear INTF0 initially, later 3 for INTF1 also
    PCICR = 4; //PCINT[23:16] for PCINT19, later 6 for [14:8] also
    PCIFR = 4; //PCINT[23:16], later 6 for [14:8] also
    *digitalPinToPCMSK(TRIG3) |= bit(digitalPinToPCMSKbit(TRIG3));
    //PCMSK2 |= (1<<PCINT19);
    // Later enable PCMSK1 for PCINT9 and PCINT8
    return;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("s");

  config_PCINT();
 
  DDRB |= B00001001; //Enable pin 8 and pin 11 digital output
  pinMode(8,OUTPUT);

  pinMode(TRIG3, INPUT); //Enable pin D3 input for ext_isr
  attachInterrupt( digitalPinToInterrupt(TRIG3), ext_isr, RISING);
}

void loop() {
  // put your main code here, to run repeatedly:
  // Emulate TRIG3 pulse on pin 11 digital output
    PORTB = B00001000; // Turn Pin 11 LED on
    delay(2);
    PORTB = 0;  // Turn Pin 11 LED off
    delay(20);
}


Paul_KD7HB

what can cause setup to run and print continuously ?

Continuously resetting the Arduino. That is usually caused by power problems.

What is attached to COM9?

Paul

JeepersCreepers

When click SerialMonitor icon of Arduino IDE 1.8.5 then COM9 console terminal opens, showing all Serial.println()

Additional clue: When I unplug pin D3 configured as external interrupt, RISING, PCINT19 then console stops printing
"s", of course, turns off redLED on the opto-isolator since then ext_isr() is not running to turn on D8. 

The D11 output into D3 is at 4.8v when HIGH 3.18ms, 0v when LOW 0.14ms

Another clue: ATMega328P documentation says execution of ext_isr routine should clear the interrupt but to
get repeated execution of ext_isr it has to have:
  EIFR = 1; //Clear External Interrupt Flag 0
  PCIFR = 4; //Clear Pin Change Interrupt Flag 2 for PCINT[23:16]
Without these, then there is just one printing from setup() and just 1 run of ext_isr as seen on scope for LEDred.

The attached modified sketch_sep10a.ino prints a counter that increments in setup()
That count is always 1 printed to console.  This implies setup is not running multiple times but the
console keeps printing, which I cannot fathom.

darrob

What you have posted only re-enforces what Paul_KD7HB said.

What appears to be happening is that you Arduino is continually resetting itself.

To verify this, add additional Serial.print lines to setup - eg
Code: [Select]

  Serial.println("Some Nonsense");
  Serial.println("To see if");
  Serial.println("My Arduino is resetting or not");


If that entire lot comes out on the console multiple times, then you should check the wiring and voltage levels of your circuit.


Go Up