problems with i2s_rx_dma Mikroe
Hi
I am trying to use the new libraries "hugh pyle" i2s_thru_dma_wm8731 but I'm having problems with the card "mikroE" because i only hear one headset with some noise when i speak in the microphone. Someone with the same problem?
this is the code that I am using.
Code:
Code:
/* TODO synchronous receive only if we choose it explicitly */
/*
I2S digital audio demonstrator for Teensy 3.0
Interfaces using Wolfson WM8731 codec.
This example is a "play through delay" test, using I2S with DMA.
Reads input into a circular buffer, writes output from the same buffer,
If the buffer size is DMA_BUFFER_SIZE (128 by default), this is "straight through".
*/
/*
To use the Mikro proto board (as master): set clock type to I2S_CLOCK_EXTERNAL
Note: this board doesn't have line-in connections.
SCK -> Teensy 9 (I2S0_TX_BCLK)
MISO -> Teensy 13
MOSI -> Teensy 3 (I2S0_TXD0). Can also be switched to pin 22.
ADCL -> Teensy 12
DACL -> Teensy 4 (I2S0_TX_FS). Can also be switched to pin 23 or 25
SDA -> Teensy 18 (I2C0_SDA)
SCL -> Teensy 19 (I2C0_SCL)[CODE]
3.3V -> Teensy 3.3v
GND -> Teensy GND
*/
//Settings for MikroE prototype board
#define CLOCK_TYPE (I2S_CLOCK_EXTERNAL)
#define CODEC_INTERFACE_FLAGS (WM8731_INTERFACE_FORMAT(I2S) | WM8731_INTERFACE_WORDLEN(bits16) | WM8731_INTERFACE_MASTER)
#define CODEC_BITRATE (WM8731_SAMPLING_RATE(hz48000))
#define CODEC_ANALOG_FLAGS (WM8731_ANALOG_DACSEL | WM8731_ANALOG_MICBOOST | WM8731_ANALOG_INSEL)
/* Wolfson audio codec controlled by I2C */
/* Library here:
https://github.com/hughpyle/machinesalem-arduino-libs/tree/master/WM8731 */
#include <Wire.h>
#include <WM8731.h>
/* I2S digital audio */
#include <i2s.h>
/* Circular buffer for audio samples, interleaved left & right channel */
const uint16_t buffersize = DMA_BUFFER_SIZE; // must be a multiple of DMA_BUFFER_SIZE
volatile int16_t buffer[buffersize];
uint16_t nTX = 0;
uint16_t nRX = 0;
/* --------------------- DMA I2S Receive, we get callback to read 2 words from the FIFO ----- */
void dma_rx_callback( int16_t *pBuf, uint16_t len )
{
while( len>0 )
{
buffer[nRX++] = *pBuf++;
buffer[nRX++] = *pBuf++;
len--;
len--;
}
if( nRX>=buffersize ) nRX=0;
}
/* --------------------- DMA I2S Transmit, we get callback to put 2 words into the FIFO ----- */
void dma_tx_callback( int16_t *pBuf, uint16_t len )
{
while( len>0 )
{
*pBuf++ = buffer[nTX++];
*pBuf++ = buffer[nTX++];
len--;
len--;
}
if( nTX>=buffersize ) nTX=0;
}
/* ----------------------- begin -------------------- */
void setup()
{
Serial.println( "Initializing");
delay(5000);
Serial.println( "Initializing." );
delay(1000);
WM8731.begin( low, CODEC_BITRATE, CODEC_INTERFACE_FLAGS );
WM8731.setActive();
//WM8731.set()
// WM8731.setOutputVolume( 127 );
WM8731.set( 0x04, 0x15 );
Serial.println( "Initialized I2C Codec" );
delay(1000);
I2SRx0.begin( CLOCK_TYPE, dma_rx_callback );
Serial.println( "Initialized I2S RX with DMA" );
I2STx0.begin( CLOCK_TYPE, dma_tx_callback );
Serial.println( "Initialized I2S TX with DMA" );
// Before starting tx/rx, set the buffer pointers
nRX = 0;
nTX = 0;
I2STx0.start();
I2SRx0.start();
}
/* --------------------- main loop ------------------ */
void loop()
{
/* do nothing */
}[/CODE]
I hope you can help