danielroitman
Member
Hello everyone,
I am trying to use the Audio.h library on the Teensy 4.1 with the I2S interface in slave mode to receive audio data from an ADS127L01 (an instrumentation ADC). The code works well with the ADS127L01 configured in SPI mode, but I am looking for a solution to use I2S and take advantage of the features in the Audio.h library.
I am trying to use the Audio.h library on the Teensy 4.1 with the I2S interface in slave mode to receive audio data from an ADS127L01 (an instrumentation ADC). The code works well with the ADS127L01 configured in SPI mode, but I am looking for a solution to use I2S and take advantage of the features in the Audio.h library.
Problem Description:
- LRCLK and BCLK Configuration:
- The LRCLK (or FSYNC) frequency of my ADS127L01 is 31.250 kHz. I managed to configure this correctly by adjusting the AUDIO_SAMPLE_RATE_EXACT variable to 31250.0f in the AudioStream.h file.
- The BCLK is 1 MHz, as my ADC has only 1 channel (mono). My question is: is there any way to configure the BCLK frequency directly via the Audio.h or AudioStream.h libraries? From what I’ve seen, the Teensy automatically configures the BCLK, but it's set to 2 MHz in master mode, which is double the required frequency. I need it to be configured for 1 MHz.
- Objective:
- Although the ADS127L01 works well in SPI mode, I would like to use the I2S interface to take advantage of the functionalities in the Audio.h library, such as audio processing and frequency analysis. In my case, the Teensy would be the slave and the ADS127L01 would be the master of the I2S bus.
- Direct Recording to SD Card:
- I am also trying to record the data received via I2S directly to the native SD Card on the Teensy 4.1, without using an SD card connected via SPI. In the examples I’ve seen, all use an SD card configured via SPI. Is there any way to use the native SD Card on the Teensy 4.1 for this?
Pins I am using:
ADS_PIN | LOCATION | TYPE | DESCRIPTION |
---|---|---|---|
nDRDY/FSYNC | AD_B1_10 / 20 - LRCLK | IN/OUT | Data ready, active low / Frame-sync input |
SCLK | AD_B1_11 / 21 - BCLK | IN/OUT | Serial clock input |
DOUT | B1_00 / 8 - RX | OUT | Serial data input |
Considerations:
- LRCLK is set to 31.250 kHz, as expected.
- BCLK is set to 2 MHz, but I need it to be 1 MHz.
- I would like to know how to configure BCLK correctly using the Audio.h library.
Code:
Code:
#include "Audio.h"
#include <SerialFlash.h>
#include "PCA9535.h"
#include <Wire.h>
#include "main.h"
AudioInputI2Sslave i2sslave1; //xy=318.23333740234375,69.23333740234375
AudioAnalyzeNoteFrequency notefreq1; //xy=550.2333374023438,56.23332977294922
AudioConnection patchCord1(i2sslave1, 1, notefreq1, 0);
PCA9535 expander(pca9535_addr);
void setup() {
Serial.begin(115200);
while (!Serial); // Wait for serial initialization
Wire.begin();
InitGPIO();
AudioMemory(50); // Allocate memory for the audio system
notefreq1.begin(.15);
Serial.println("System initialized, waiting for data...");
}
void loop() {
// Read back fundamental frequency
if (notefreq1.available()) {
float note = notefreq1.read();
float prob = notefreq1.probability();
Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
}
}