I have referred http://microchipdeveloper.com/harmony:i2s-tutorial and am able to configure the I2S and read continuous data from a microphone.
I am facing issue with the microphone data, and have been already discussing it here PIC32MZ: MSB of I2S data from digital microphone is always high. However, that is another issue altogether.
I have configured the I2S on DMA, and am able to continuously read the digital microphone data in my buffer.
My problem is, whenever I add a function to calculate the mean, average or to filter the DC offset from the data, my PIC32MZ program gets stuck.
I get the DMA interrupt, and there-by the I2S digital data once, but after that I never reach the breakpoint where I read the data.
Following is my code for reading data at the DMA interrupt:-
void APP_VOICE_RECORD_LOOP_BufferEventHandler(DRV_I2S_BUFFER_EVENT event,
DRV_I2S_BUFFER_HANDLE handle, uintptr_t context)
{
// The context handle was set to an application specific
// object. It is now retrievable easily in the event handler.
//MY_APP_OBJ myAppObj = (MY_APP_OBJ *) contextHandle;
uint32_t convertedBufferCount = 0;
uint32_t evenCount = 0;
switch(event)
{
case DRV_I2S_BUFFER_EVENT_COMPLETE:
// This means the data was transferred.
appVoiceRecordLoopData.codecClient.rxbufferObject = (uint32_t *) micbuf2;
DRV_I2S_BufferAddRead(appVoiceRecordLoopData.codecClient.handle,
appVoiceRecordLoopData.codecClient.txbufferObject,
appVoiceRecordLoopData.codecClient.rxbufferObject,
appVoiceRecordLoopData.codecClient.bufferSize);
uint32_t receivedBufferSize = appVoiceRecordLoopData.codecClient.bufferSize / sizeof(uint32_t);
for(evenCount = 0; evenCount < receivedBufferSize; evenCount++)
{
if(evenCount%2 == 0 && micbuf2[evenCount] != 0)
{
ConvertedAudioData[convertedBufferCount++] = (micbuf2[evenCount] >> 14);
}
}
//uint32_t average = CalculateAverage(ConvertedAudioData, convertedBufferCount);
appVoiceRecordLoopData.state = APP_VOICE_RECORD_LOOP_STATES_CODEC_WAIT_FOR_BUFFER_COMPLETE;
break;
case DRV_I2S_BUFFER_EVENT_ERROR:
// Error handling here.
break;
case DRV_I2S_BUFFER_EVENT_ABORT:
// Error handling here.
break;
default:
break;
}
}
Code works properly when I comment
//uint32_t average = CalculateAverage(ConvertedAudioData, convertedBufferCount);
However, when I uncomment this function, code never reaches here the second time.
Any suggestions what I might be doing wrongly here?
Thanks in advance