Hi all, I’m working on a spectrum analyzer, but I’ve run into a problem where the only thing printed out into the serial monitor is “st” and I have no clue why.

11:30:13.896 → st

Resetting serial monitor just prints 11:30:44.711 → stst

I’ve checked the ADC values while playing a 600Hz tone, and it prints values between -512 and 511, which is expected since I subtracted a DC offset of 512.

```
#define LIN_OUT 1
#define FFT_N 256 // set to 256 point fft
#define ANALOG_PIN 0
#define ADC_INTERRUPT_MASK 0x10
#define SAMPLING_FREQ (16000000/(13*32))
#define DC_OFFSET 512
#include "FFT.h" // include the library
void setup() {
Serial.begin(9600); // setup serial
DIDR0 = 0x01; // turn off the digital input for adc0
ADMUX = 0x40; // use adc0
/*
To get 10bit precision, from 50kHz to 200kHz clock must be supplied to the ADC. The
chip runs at 16MHHz. If we were set the prescaler value to 128 -> 0b011 as part of the
ADPS register value, then we get (16MHz/128) = 125kHz as the ADC Input Clock frequency.
Since it takes 13 input clock cycles to get one Audio sample, the effective sampling
frequency is 125Khz/13 = 9.6kHz. This is not sufficient as the audio frequency range
is from 20Hz to 20KHz.
If we choose a prescaler of 32, then the sampling frequency becomes 16000/(32*13) ~ 38KhZ
From Nyquist's Theorem, the effective bandwidth is half the sample rate,= 19Khz
*/
ADCSRA = 0xe5; //ADC to free running mode
}
void loop() {
cli();
while (1) {
for (int i = 0 ; i < 512 ; i += 2) { // we need 256 samples that represent the real into 256 bins of the FFT
while (!(ADC_INTERRUPT_MASK & ADCSRA)); // wait till the interrupt flag is 0. Which means conversion is in process
ADCSRA = 0xf5; // Set ADIF to 1 and ADSC to 1, as the first conversion was made and we need to be ready for the next conversion
byte low = ADCL; // fetch adc data
byte high = ADCH;
int value = (high << 8) | low; // form into an int
int adc_val = value - DC_OFFSET;
fft_input[i] = adc_val; // put real data into even bins
fft_input[i + 1] = 0; // set odd bins to 0
}
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_lin(); // take the output of the fft */
sei();
Serial.println("start");
for (byte i = 0 ; i < FFT_N / 2 ; i++) {
Serial.print("Frequency: "); Serial.print(i * ((SAMPLING_FREQ / 2) / FFT_N)); Serial.print(" ");
Serial.println(fft_lin_out[i]); // send out the data to the serial port so I can see what it's doing
}
}
}
```