Hi,
I am trying to read data from this I2S microphone. The data is I2S, 24-bit, 2’s compliment, MSB first. The data precision is 18 bits; unused bits are zeros.
This is the code for initializing and starting the transfer:
void audioInit(void) { I2S_init(); I2S_Params_init(&i2sParams); i2sParams.trueI2sFormat = true; i2sParams.invertWS = true; i2sParams.isMSBFirst = true; i2sParams.isDMAUnused = true; i2sParams.memorySlotLength = I2S_MEMORY_LENGTH_24BITS; i2sParams.beforeWordPadding = 0; i2sParams.afterWordPadding = 0; i2sParams.bitsPerWord = 32; i2sParams.moduleRole = I2S_MASTER; i2sParams.samplingEdge = I2S_SAMPLING_EDGE_RISING; i2sParams.SD0Use = I2S_SD0_INPUT; i2sParams.SD1Use = I2S_SD1_DISABLED; i2sParams.SD0Channels = I2S_1_CHANNEL; i2sParams.phaseType = I2S_PHASE_TYPE_DUAL; i2sParams.fixedBufferLength = sizeof(buf); i2sParams.startUpDelay = 0; i2sParams.MCLKDivider = 2; i2sParams.samplingFrequency = 24000; i2sParams.readCallback = i2sReadHandler; i2sParams.writeCallback = NULL; i2sParams.errorCallback = i2sErrorHandler; while(1) { i2sHandle = I2S_open(0, &i2sParams); printf("i2sHandle = 0x%x\n", (uint32_t)i2sHandle); List_clearList(&i2sReadList); I2S_Transaction_init(&i2sRead1); i2sRead1.bufPtr = buf; i2sRead1.bufSize = sizeof(buf); List_put(&i2sReadList, (List_Elem*)&i2sRead1); I2S_setReadQueueHead(i2sHandle, &i2sRead1); I2S_startClocks(i2sHandle); I2S_startWrite(i2sHandle); I2S_startRead(i2sHandle); while(1) { if (readStopped) { I2S_stopClocks(i2sHandle); I2S_close(i2sHandle); Task_sleep(OS_TICKS_PER_SECOND*2); continue; } } }
When I execute the first transfer the waveform looks like this:
The data in memory after the transfer is here:
Here are my questions:
1) bitsPerWord is set to 32. If I set to 24 which is what the mic is generating the data is all 0's. Why is that?
2) Looking at the logic analyzer waveform the bits on AD0 are:
0001 0010 1001 1100 0000 0000 0000 0000 (0x12 0x9c 0x00 0x00 0x00 0x00)
What's in memory (starting at 0x2000326f), though, is
0000 0000 1001 1100 0000 0000 1000 0000 (0x00 0x9c 0x00 0x80 0x00)
I am not able to extract the exact data I am looking for. Since the word length is configured for 32-bits I expect the most significant 4 bits are 0 and the least significant 8 bits are 0
according to the mic data-sheet.
3) There are 5x 24-bit cycles prior to the data showing up in memory. If I set startUpDelay to 5 the data show exactly as above but should start on the 6th cycle.
Is there an explanation for this?
Victor