Unable to read from SPH0645LM4H microphone

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to read from SPH0645LM4H microphone

2,286 Views
niranjan_rao
Contributor II

Hello, I am trying to record audio from SPH0645LM4H MEMS microphone using K82 - series MCU (Master).

The data sheet of the mic says that, no codec is needed and the audio data can be read directly from the mic through I2S  interface.

The mic data can be read when  SEL and WS llines are high. 

But I am unable to read any data, can you guys please help me with this?

Thank you 

SPH0645LM4H data sheet: http://www.knowles.com/kor/content/download/5988/105771/version/4/file/SPH0645LM4H-BRevB.PDF 

0 Kudos
6 Replies

1,260 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

As Cutworth said that the bit width is 32 bits instead of 16 bits. BTW, the code you refered is based on Sgtl5000, which has I2C port so that Kinetis can configure the Sgtl5000. But the SPH0645LM4H does not have I2C interface, so the I2C code is unnecessary. The data you received is from two slots, but only one slot is valid, another is invalid.

BR

Xiangjun Rong

0 Kudos

1,260 Views
niranjan_rao
Contributor II

Hi,

There was a small confusion in the code I sent previously, I am sorry.

Can you please check the code attached here?

#include <fsl_port.h>
#include <fsl_gpio.h>
#include <fsl_debug_console.h>
#include <fsl_sai.h>
#include <dbgutil.h>
#include <timer.h>

bool isFinished = false;
uint32_t temp[2000];
sai_handle_t rxHandle = {0};

static sai_config_t config;
sai_transfer_format_t format;
sai_transfer_t xfer;

static void callback(I2S_Type *base, sai_handle_t *handle, status_t status, void *userData)
{
if (kStatus_SAI_RxIdle == status)
{
isFinished = true;
}
}

void sai_init(sai_config_t config)
{
PRINTF("Enable I2S pins...\r\n");

CLOCK_EnableClock(kCLOCK_PortA);

// DM_DO (Data) and // DM_WS (FS, Word/Frame Sync)
port_pin_config_t pin_config = {0};

pin_config.pullSelect = kPORT_PullDown;
pin_config.mux = kPORT_MuxAlt6;

PORT_SetPinConfig(PORTA, 15U, &pin_config); //DO
PORT_SetPinConfig(PORTA, 16U, &pin_config); //WS

PORT_SetPinMux(PORTA, 17U, kPORT_MuxAlt6); // DM_CLK (MCLK/BCLK)

PORT_SetPinMux(PORTA, 18U, kPORT_MuxAsGpio); // DM_SEL

const gpio_pin_config_t OUT = {kGPIO_DigitalOutput, 0};
GPIO_PinInit(GPIOA, 18U, &OUT);

PRINTF("Configuring SAI...\r\n");

SAI_RxGetDefaultConfig(&config);
config.protocol = kSAI_BusI2S;
config.syncMode = kSAI_ModeAsync;
SAI_RxInit(I2S0, &config);

/* Configure the audio format */
format.bitWidth = kSAI_WordWidth32bits;
format.channel = 0U;
format.sampleRate_Hz = kSAI_SampleRate32KHz;
format.masterClockHz = 64U * format.sampleRate_Hz;
format.protocol = config.protocol;
format.stereo = kSAI_Stereo;
format.watermark = FSL_FEATURE_SAI_FIFO_COUNT / 2U;

SAI_TransferRxCreateHandle(I2S0, &rxHandle, callback, NULL);
SAI_TransferRxSetFormat(I2S0, &rxHandle, &format, CLOCK_GetCoreSysClkFreq(), format.masterClockHz);
}


void error(char *msg) {
PRINTF("ERROR: %s\r\n", msg);
while(true) {}
}

int main (void)
{
board_init();
board_console_init(BOARD_DEBUG_BAUD);

sai_init(config);

PRINTF("Listening...\r\n");

xfer.data = (uint8_t *) temp;
xfer.dataSize = sizeof(temp);

GPIO_WritePinOutput(GPIOA, 18U, true);

PRINTF("%x\r\n", SAI_TransferReceiveNonBlocking(I2S0, &rxHandle, &xfer));

GPIO_WritePinOutput(GPIOA, 18U, false);

while (isFinished != true) {}

PRINTF("FINISHED.\r\n");
dbg_xxd("AUDIO", xfer.data, xfer.dataSize);

while(true)
{
delay(10000);
}

return 0;
}

0 Kudos

1,260 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Niranjan,

I have downloaded file from the link, From hardware connection, you should connect the follwing signals if you use only one mic.

connect the SAI_Rx_BCLK of K82 to CLK of Mic

connect the SAI_Rx_SYNC of K82 to WS of Mic

connect the SAI_Rx_DATA of K82 to DATA of Mic with 100 ohm pull-down resistor.

connect the SELECT of Mic to GND or 3.3V, either one is okay.

From software, you can program the SAI receiver in master mode, 32 bits width, two slots. I suppose that the code of SAI has issue, can you see the signal of SAI_Rx_SYNC and SAI_Rx_BCLK  via a scope?

BR

Xiangjun Rong

0 Kudos

1,260 Views
niranjan_rao
Contributor II

Hello xiangjun.rong,

I modified the example code to receive PCM data from the mic and I don't receive any data

I have attached my code.

Thank you 

0 Kudos

1,260 Views
cutworth
NXP Employee
NXP Employee

Hi Niranjan,

I looked at your code, your configuration for SAI clock is not correct. In your code, you configured the sample rate as 16kHz. But you should configure it to in between 32kHz to 64kHz. 

Please check the following comment in the MEMS microphone.

The Over Sampling Rate is fixed at 64 therefore the WS signal must be BCLK/64 and synchronized to the BCLK. Clock frequencies from 2.048Mhz to 4.096MHz are supported so sampling rates from 32KHz to 64KHz can be had by changing the clock frequency.

Also the bit width configured is not correct as well. From the timing diagram in the microphone spec, you need to configure bit width to 32bit.

Hao

0 Kudos

1,260 Views
niranjan_rao
Contributor II

Hi Xiangjun,

Thank you, I can see the SAI_Rx_SYNC and SAI_Rx_BCLK   signals via scope. I can also see some data signal in the SAI_Rx data line 

0 Kudos