Why does println cause this code to fail?

Hi. The attached code never gets beyond the line:

Serial.println(853.0);

Comment it out and the rest of the code should run just fine. Can anyone tell me why? Frankly, I'm starting to get really tired of the limitations and idiosyncrasies of this lobotomized 'c' called an 'Arduino sketch'.

Thanks.

#define LOG_OUT 1 // use the log output function
#define FHT_N 128 // set to 256 point fht

#include <FHT.h> // include the library

void setup() {
  Serial.begin(115200); // use the serial port
  TIMSK0 = 0; // turn off timer0 for lower jitter
  ADCSRA = 0xe5; // set the adc to free running mode
  ADMUX = 0x40; // use adc0
  DIDR0 = 0x01; // turn off the digital input for adc0
}

void loop() {
  while(1) { // reduces jitter
    Serial.println(854.0);
    cli();  // UDRE interrupt slows this way down on arduino1.0
    int i;
    int g;
    for (i = 0 ; i < FHT_N ; i++) { // save 256 samples
      while(!(ADCSRA & 0x10)); // wait for adc to be ready
      ADCSRA = 0xf5; // restart adc
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int k = (j << 8) | m; // form into an int
      k -= 0x0200; // form into a signed int
      k <<= 6; // form into a 16b signed int
      fht_input[i] = k; // put real data into bins
      Serial.println(853.0);
    }
    Serial.println(855.0);
    fht_window(); // window the data for better frequency response
    fht_reorder(); // reorder the data before doing the fht
    fht_run(); // process the data in the fht
    fht_mag_log(); // take the output of the fht
    sei();
//    Serial.write(255); // send a start byte
//    Serial.write(fht_log_out, FHT_N/2); // send out the data
    for(int g=0; g<FHT_N/2; i++) {
      Serial.print(i+g);
      Serial.print('\t');
      Serial.println(fht_log_out[g]); // send out the data
    }
  }
}

Moderator edit: Frankly, I'm starting to get really tired of people who can't be bothered to read the guidelines and use CODE TAGS.

fht_adc.ino (1.73 KB)

Many functions (methods) in Serial depend upon interrupts. You have disabled interrupts, so Serial.println(...) will get stuck.

It is not a good idea to print from within an interrupt routine. Similarly, it is not a good idea to print when interrupts are disabled.

You're also preventing the loop function ever completing. Serial does it's housekeeping between itterations of the loop, so this isn't happening in your sketch.

If something is so time critical that interrupts need disabling, then the delay caused by a serial.print is going to be disastrous (even if it worked). You need a rethink.

lobotomized 'c' called an 'Arduino sketch'.

The version of C/C++ used by the Arduino is the full on every thing in version of C/C++. Nothing is missing!.

Try and learn the language before making such stupid comments.

Mark

Serial does it's housekeeping between itterations of the loop, so this isn't happening in your sketch.

No, it doesn't. It fires interrupts as needed to send data, regardless of where in loop() the execution point is. Interrupts happen when serial data arrives.

Of course, is it still stupid to run an infinite loop inside an infinite loop(). That comment is flat out wrong.