Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Problem with MQS output in combination with SPI input

  1. #1
    Junior Member
    Join Date
    Jun 2020

    Problem with MQS output in combination with SPI input

    Hi together,
    currently I am working on a recording device for ultrasonic sounds with a sampling rate of 500 kS/s.
    The ADC is a 16 bit ADC from Michrochip with 1MS/s sampling rate and an SPI interface.
    To be able to use the Audio library I created my own input class by modifying the input_i2s class.

    I am able to read and record audio signals at 500 kS/s. So far so good.
    My idea was to use the MQS output as a monitoring output just to hear if the mike is working or not.

    But I am encountering a very strange behaviour. The MQS outputs delivers output signal even if it is not configured at all.

    I'm using this simple test sketch:

    #include <Arduino.h>
    #include <Audio.h>
    //control pre amplifier
    #define PIN_AMP_0        15      // enable feedback resistor
    #define PIN_AMP_1        29      // enable feedback resistor
    #define PIN_AMP_2        16      // enable feedback resistor
    #define PIN_AMP_3        30      // bridge high pass
    AudioInputSpiMono        m_audioIn;   // SPI input
    void setup() {
      pinMode(PIN_AMP_0, OUTPUT);
      pinMode(PIN_AMP_1, OUTPUT);
      pinMode(PIN_AMP_2, OUTPUT);
      pinMode(PIN_AMP_3, OUTPUT);
      digitalWrite(PIN_AMP_0, 1);
      digitalWrite(PIN_AMP_1, 1);
      digitalWrite(PIN_AMP_2, 1);
      digitalWrite(PIN_AMP_3, 1);
    void loop() {
      // put your main code here, to run repeatedly:
    The MQS is not configured. No patch cable connected, nothing.
    But I can hear the input signal on the headphone. This is not what I want because I need to do some audio processing before outputting the signal to the headphones..

    What I found out is that the the transfer from the input to the MQS is not done by DMA.
    Even if I disable DMA transfer (comment out all related code), the effect is still there.

    At the end of the method begin() of the Spi input class I added the following lines:

      I2S1_RCSR = 0;
      I2S1_RCR2 |= I2S_RCR2_BCP;  //polarity bit clock: rising edge
    // set word width to 16 bit
       uint16_t ww = 15;
      I2S1_RCR4 &= ~I2S_RCR4_SYWD(31); // as soon as I comment these two lines
      I2S1_RCR4 |= I2S_RCR4_SYWD(ww);  // the effect diappears
      I2S1_RCR5 = I2S_RCR5_WNW(ww) | I2S_RCR5_W0W(ww) | I2S_RCR5_FBT(ww);  
    As soon I comment out the lines handling I2S1_RCR4, the effect disappears. There must be some kind of internal
    hardware connection between I2S1 I am using to read the ADC and I2S3 which is used for MQS.

    Does anybody here has an advice or an idea how to fix this?
    I appreciate any advice or reply, I'm lost with this issue at the moment.

    In the attachment I added the full code of the modified input class.

    Attached Files Attached Files

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Wow, that's a strange problem.

    Before I look into this, could you do a quick test? Try connecting 1K resistors from pin 10 to GND and pin 12 to GND. If MQS really is driving those pins, it should easily be able to deliver 3mA current into those resistors.

    The idea is to quickly rule out the possibility your amplifier has a very sensitive input and make sure the sound you're hearing isn't due to some other effect, like coupling from other signals.

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Hi Paul,
    thank you so much for helping me out of my box of thinking! I was completely trapped because I thought it must be a software issue...
    Of course it was NOT a software problem, I hat a broken wire between my analog circuit and the teensy that caused the strange behaviour. (Should have used my scope on this a bit earlier...)

    So thanks again for your quick response and I apologize for my misleading question.


  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Glad you found the problem.

    This really is the hardest thing, troubleshooting both driver-level software & new hardware at the same time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts