WM8731 issues

Status
Not open for further replies.

john-mike

Well-known member
I'm having issues getting stereo sound in and out of the Mikro WM87311 board

This is based on the "WM8731mikrosine_codec" example
Code:
//    Mikroe   Teensy 3.1
//    ------   ----------
//     SCK         9
//     MISO       13
//     MOSI       22
//      ADCL       ??
//     DACL       23
//     SDA        18
//     SCL        19
//     3.3V      +3.3V
//     GND        GND

uint32_t prev0;

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioInputI2Sslave       i2ss1;          //xy=114,152
AudioSynthWaveform       waveform1;      //xy=127,271
AudioMixer4              mixer1;         //xy=320,249
AudioOutputI2Sslave      i2ss2;          //xy=501,212

AudioConnection          patchCord1(i2ss1, 0, mixer1, 0);
AudioConnection          patchCord2(i2ss1, 1, mixer1, 1);
AudioConnection          patchCord3(waveform1, 0, mixer1, 2);
AudioConnection          patchCord4(mixer1, 0, i2ss2, 0);
AudioConnection          patchCord5(mixer1, 0, i2ss2, 1);

AudioControlWM8731master wm8731m1;       //xy=657,495



void setup() {
  wm8731m1.enable();
  wm8731m1.inputLevel(.8);

  AudioMemory(15);

  waveform1.begin(WAVEFORM_SINE);
  waveform1.frequency(440);
  waveform1.amplitude(1);

  wm8731m1.volume(.8);

  pinMode(2, INPUT_PULLUP);
}


void loop() {
  byte d2 = digitalRead(2);
  mixer1.gain(2, 0);


  if (d2 == 0) {
    mixer1.gain(0, 1);
    mixer1.gain(1, 0);
  }

  if (d2 == 1) {
    mixer1.gain(0, 0);
    mixer1.gain(1, 1);
  }


  if ((millis() - prev0) > 250 && 1 == 1) {
    prev0 = millis();

    Serial.print(AudioProcessorUsageMax());
    Serial.print(" ");
    Serial.println(AudioMemoryUsageMax());
    Serial.println();

    AudioProcessorUsageMaxReset();
    AudioMemoryUsageMaxReset();



  }

}

Left line in, left headphone out and left line out work. No right channels do.
I have wired the line ins and outs myself and am very sure of the connections.

This is based on the MikroSine example so I used AudioInputI2Sslave. I don't understand why this works since the WM8731 is in master mode on the Mikro board, right?
Doesn't this mean the moed are mixed?

How would you co about using this in master mode, just like the sgtl5000? The CLKOUT pin of the WM8731 going to pin 11 of the teensy? I tried that and just got static on both channels.


I've been using the sgtl5000 but would really like to get this one working as it can be DC-coupled.

Thanks!
 
Ok finally got my head around all the master/slave clocks using these pages. (Which don't seem to be linked from anywhere?)
http://www.pjrc.com/teensy/td_libs_AudioInputI2S.html
http://www.pjrc.com/teensy/td_libs_AudioOutputI2S.html

Using a breakout I connected the WM8731 with this code and it all seems to be working just as the SGTL5000 would. With an i2c OLED too!
https://www.instagram.com/p/BBlmx-bPFyg/

Code:
/*
  wm8731    Teensy 
  3         9
  4         22
  5&7       23
  6         13 
  21&22     GND
  23        18
  24        19
  25        11

*/

uint32_t prev0;

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>


AudioControlWM8731 wm8731m1;       //xy=657,495

AudioInputI2S       i2s_in;          //xy=114,152
AudioSynthWaveform       waveform1;      //xy=127,271
AudioSynthWaveform       waveform2;      //xy=127,271
AudioMixer4              mixer1;         //xy=320,249
AudioOutputI2S      i2s_output;          //xy=501,212



AudioConnection          patchCord5(waveform1, 0, mixer1, 1);
AudioConnection          patchCord61(waveform2, 0, mixer1, 0);
AudioConnection          patchCord62(mixer1, 0, i2s_output, 0);
AudioConnection          patchCord63(mixer1, 0, i2s_output, 1);



void setup() {
  AudioNoInterrupts();

  Serial.begin(9600);
  //  while (!Serial) { }  delay(1000);
  AudioMemory(15);

  wm8731m1.enable();
  wm8731m1.inputLevel(.8);
  wm8731m1.volume(.8);


  waveform1.begin(WAVEFORM_SINE);
  waveform1.frequency(440);
  waveform1.amplitude(.5);

  waveform2.begin(WAVEFORM_SINE);
  waveform2.frequency(220);
  waveform2.amplitude(.4);

  pinMode(2, INPUT_PULLUP);

  AudioInterrupts();

}

void loop() {


}
 
Using a breakout I connected the WM8731 with this code and it all seems to be working just as the SGTL5000 would. With an i2c OLED too!

but this is simply slave mode (= ie code is slave) ? yeah, this seems to be working no problem, except control_wm8731.cpp might not be in an entirely perfect shape.

IIRC, i had to add a few lines to control_wm8731.cpp to make the inputs work, too, but it looks like Paul has pulled it into the Audio library repo meanwhile.

fwiw, here's a litte record test
 
Last edited:
but this is simply slave mode (= ie code is slave) ?
This was kinda my main issue, who was master or slave.
Plus not being able to run either the arduino codec shield or mikro board reliably as slave.

In the code posted the control and i2s are setup as a slave to the teensy.

except control_wm8731.cpp might not be in an entirely perfect shape.
Control seems to be good. Input and output volumes work. I added this to get DC coupled input working at full range:

Code:
bool AudioControlWM8731::dcCouple(unsigned int reg, unsigned int val)
{
	write(WM8731_REG_DIGITAL, 0x01);   // DAC unmuted and ADCHPD off which enables dc coupled line in
	 
	write(WM8731_REG_RLINEIN, 0x17);  //0db, unmuted
	write(WM8731_REG_LLINEIN, 0x17);

        write(WM8731_REG_LHEADOUT, 0x79);  //0db, unmuted
	write(WM8731_REG_RHEADOUT, 0x79);

		return true;
}

Also having
Code:
	write(WM8731_REG_RESET, 0);
At the beginning of "enable" helped if you re powering digital off of 3v3. Otherwise it won't reset when the teesny does.
 
Control seems to be good. Input and output volumes work.

yeah, as i said, works for all practical purposes. when i first tried it a couple of months ago, inputLevel(float n) wasn't functional but it's there now; what i meant by "not entirely perfect" is not absolutely every register option might be in there and fully functional.

as for the teensy-is-slave-wm8731-is-master thing, i've never tried but i'm using a/the mikroe driver in a different project and that defaults to 48kHz; ie there's a 12.288 MHz crystal on there -- don't know whether the audio library automatically adjusts. probably not.
 
Last edited:
Status
Not open for further replies.
Back
Top