help using spdif input. I can't get it to work.

can anyone give me a lead on how to use the SPDIF input for the audio board? I am trying with a RX147L and have it wired to ground, vcc and pin15 running the code below.

I have tried it with a .1uf cap between gnd and vcc as the spec sheet says. It can't be this hard but I'm doing something wrong. I tried two different 147L adaptors.

thanks for any hints!

C:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// Audio system objects (SPDIF-in on pin 15 / RX)
AudioInputSPDIF3    spdifIn;        // Optical/coax SPDIF input
AudioAnalyzePeak    peakL, peakR;   // Peak detectors
AudioConnection     patchCord1(spdifIn, 0, peakL, 0);
AudioConnection     patchCord2(spdifIn, 1, peakR, 0);
// Settings
const float ledThreshold = 0.001f;  // Lower to show very small signals
const int ledPin = 13;              // Teensy 4.0 built-in LED
void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200);
  while (!Serial && millis() < 4000) {
    // wait for Serial Monitor to attach (optional)
  }
  AudioMemory(20);
  Serial.println("Teensy SPDIF (pin 15) peak monitor");
}
void loop() {
  uint32_t now = millis();
  // Heartbeat even if no audio blocks are ready
  static uint32_t lastStatus = 0;
  if (now - lastStatus > 1000) {
    lastStatus = now;
    Serial.print("SPDIF lock=");
    Serial.print(spdifIn.pllLocked() ? "1" : "0");
    Serial.print(" sr=");
    Serial.println(spdifIn.sampleRate());
  }
  if (peakL.available() && peakR.available()) {
    float L = peakL.read();   // 0.0–1.0
    float R = peakR.read();
    bool active = (L > ledThreshold) || (R > ledThreshold);
    digitalWrite(ledPin, active ? HIGH : LOW);
    static uint32_t lastPrint = 0;
    if (now - lastPrint > 100) { // print every ~100 ms
      lastPrint = now;
      Serial.print("Peak L: "); Serial.print(L, 4);
      Serial.print("  R: ");    Serial.println(R, 4);
    }
  }
}
 
Last edited:
Can you please post your code between code tags using the </> button.
Below is what you code looks like when posted in this manner. Much more readable which will help someone to HELP YOU!
C++:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// Audio system objects (SPDIF-in on pin 15 / RX)
AudioInputSPDIF3 spdifIn; // Optical/coax SPDIF input
AudioAnalyzePeak peakL, peakR; // Peak detectors
AudioConnection patchCord1(spdifIn, 0, peakL, 0);
AudioConnection patchCord2(spdifIn, 1, peakR, 0);
// Settings
const float ledThreshold = 0.001f; // Lower to show very small signals
const int ledPin = 13; // Teensy 4.0 built-in LED
void setup() {
    pinMode(ledPin, OUTPUT);
    Serial.begin(115200);
    while (!Serial && millis() < 4000) {
        // wait for Serial Monitor to attach (optional)
    }
    AudioMemory(20);
    Serial.println("Teensy SPDIF (pin 15) peak monitor");
}
void loop() {
    uint32_t now = millis();
    // Heartbeat even if no audio blocks are ready
    static uint32_t lastStatus = 0;
    if (now - lastStatus > 1000) {
        lastStatus = now;
        Serial.print("SPDIF lock=");
        Serial.print(spdifIn.pllLocked() ? "1" : "0");
        Serial.print(" sr=");
        Serial.println(spdifIn.sampleRate());
    }
    if (peakL.available() && peakR.available()) {
        float L = peakL.read(); // 0.0–1.0
        float R = peakR.read();
        bool active = (L > ledThreshold) || (R > ledThreshold);
        digitalWrite(ledPin, active ? HIGH : LOW);
        static uint32_t lastPrint = 0;
        if (now - lastPrint > 100) { // print every ~100 ms
            lastPrint = now;
            Serial.print("Peak L: "); Serial.print(L, 4);
            Serial.print(" R: "); Serial.println(R, 4);
        }
    }
}
 
Last edited:
I think I'm figuring out that a simple SPDIF connection is not what it needs. I don't really know how to use an oscilloscope but that's my next step to try. I'll post the results.
 
It should just be a direct connection to the output pin on the toslink receiver. There's really not much that can go wrong unless you've wired it to the wrong pin, or the audio device isn't sending audio over the optical cable.

You can always try writing a sample that plays something over the Teensy's SPDIF output (pin 14) and loop it back to the input pin (pin 15) to check the software side of things.
 
I just tried your code with a known-working rig, and it's fine, so you probably have a hardware problem somewhere, as implied in post #7.
 
I tested with and without the audio board (then with two other audio boards) it only worked without the board.

I found this information:
it says:
"As when using dual Audio Adaptor Boards, you need to disconnect Teensy Pin 15 from Audio Adaptor Pin 15. Otherwise, the bypass cap on the later kills the high frequency IS0_TXD1 signal. I cut the pin, you can probably also just remove the cap."
 
Ah, yes. You only mentioned the audio board in passing, and it's not used in your code, so I didn't take that into account. I would have forgotton about that cap, anyway, mine's been gone for years...
 
Back
Top