Switching between microphone and I2S for VS1053

Writing software that inputs and/or outputs audio and performs DSP algorithms such as filters, new codecs or audio effects.
Post Reply
AlanSbor
User
Posts: 2
Joined: Wed 2022-05-25 17:49

Switching between microphone and I2S for VS1053

Post by AlanSbor »

Good afternoon!

According to my scheme, VS1053 receives a signal from ESP32 via I2S - it works, everything is fine.
I want to add an FM receiver to the circuit and transmit the signal to the microphone input in stereo.

How to disable - stop receiving a signal from I2S and start receiving a signal from a microphone input?

Code: Select all

The algorithm should be like this:

1. Do we work with web radio?
                                               Yes -> continue to transfer data.
                                               No -> We switched to FM radio ?
                                                          Yes -> Stop I2S stream, switch to mic input, start processing.
                                                          No -> Show the status on the screen.
I am attaching the diagram.

Alan Sbor.
Attachments
VS1053 multiplexor.jpg
VS1053 multiplexor.jpg (254.58 KiB) Viewed 1429 times
User avatar
pasi
VLSI Staff
Posts: 2092
Joined: Thu 2010-07-15 16:04

Re: Switching between microphone and I2S for VS1053

Post by pasi »

How did you manage that?

vs1053/vs1063 can only send to I2S in master mode, they cannot receive I2S data.

Did you mean you're sending data from the ESP32 through SDI?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
AlanSbor
User
Posts: 2
Joined: Wed 2022-05-25 17:49

Re: Switching between microphone and I2S for VS1053

Post by AlanSbor »

Good evening !

You are absolutely right - sending data from the ESP32 via SDI.

I am attaching a code example.

How can I switch to microphone input to pass the signal from the fm receiver through the VS1053 to the amplifier?

Code: Select all

void VS1053::begin()
{
  pinMode      ( dreq_pin,  INPUT ) ;                   // DREQ is an input
  pinMode      ( cs_pin,    OUTPUT ) ;                  // The SCI and SDI signals
  pinMode      ( dcs_pin,   OUTPUT ) ;
  digitalWrite ( dcs_pin,   HIGH ) ;                    // Start HIGH for SCI en SDI
  digitalWrite ( cs_pin,    HIGH ) ;
  if ( shutdown_pin >= 0 )                              // Shutdown in use?
  {
    pinMode ( shutdown_pin,   OUTPUT ) ;
  }
  if ( shutdownx_pin >= 0 )                            // Shutdown (inversed logic) in use?
  {
    pinMode ( shutdownx_pin,   OUTPUT ) ;
  }
  output_enable ( false ) ;                            // Disable amplifier through shutdown pin(s)
  delay ( 100 ) ;
  // Init SPI in slow mode ( 0.2 MHz )
  VS1053_SPI = SPISettings ( 200000, MSBFIRST, SPI_MODE0 ) ;
  SPI.setDataMode ( SPI_MODE0 ) ;
  SPI.setBitOrder ( MSBFIRST ) ;
  //printDetails ( "Right after reset/startup" ) ;
  delay ( 20 ) ;
  //printDetails ( "20 msec after reset" ) ;
  if ( testComm ( "Slow SPI, Testing VS1053 read/write registers..." ) )
  {
    // Most VS1053 modules will start up in midi mode.  The result is that there is no audio
    // when playing MP3.  You can modify the board, but there is a more elegant way:
    wram_write ( 0xC017, 3 ) ;                            // GPIO DDR = 3
    wram_write ( 0xC019, 0 ) ;                            // GPIO ODATA = 0
    delay ( 100 ) ;
    //printDetails ( "After test loop" ) ;
    softReset() ;                                         // Do a soft reset
    // Switch on the analog parts
    write_register ( SCI_AUDATA, 44100 + 1 ) ;            // 44.1kHz + stereo
    // The next clocksetting allows SPI clocking at 5 MHz, 4 MHz is safe then.
    write_register ( SCI_CLOCKF, 6 << 12 ) ;              // Normal clock settings
    // multiplyer 3.0 = 12.2 MHz
    //SPI Clock to 4 MHz. Now you can set high speed SPI clock.
    VS1053_SPI = SPISettings ( 5000000, MSBFIRST, SPI_MODE0 ) ;
    write_register ( SCI_MODE, _BV ( SM_SDINEW ) | _BV ( SM_LINE1 ) ) ;
    testComm ( "Fast SPI, Testing VS1053 read/write registers again..." ) ;
    delay ( 10 ) ;
    await_data_request() ;
    endFillByte = wram_read ( 0x1E06 ) & 0xFF ;
    dbgprint ( "endFillByte is %X", endFillByte ) ;
    //printDetails ( "After last clocksetting" ) ;
    delay ( 100 ) ;
  }
}
Alan Sbor
User avatar
pasi
VLSI Staff
Posts: 2092
Joined: Thu 2010-07-15 16:04

Re: Switching between microphone and I2S for VS1053

Post by pasi »

Two options:
1) Switch to encoding mode. You get the ADC monitoring through the analog output, but you don't need to read out the encoded data.
2) Use the VS1053b ADMixer plugin to mix the ADC input(s) to the decoded signal. If you don't want both at the same time, stop sending the data to decode (so the decoder stops its output), use the pause mode (vs1053b-patches), or reduce the volume to the decoded audio from SCI_VOL (but don't turn volume so low that analog would be powered off).
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
Post Reply