2021-02-11 08:03 AM
Hello,
I am trying to use the PDM 2 PCM library to read in a MEMS microphone and am having some difficulty understanding the code below.
If I wanted simply output the converted PCM data over a UART, what would need to be done to do this?
My assumption is the PCM data is MidBuffer which is a uint16 bit array of 16 PCM samples?
I think the callbacks are also confusing me. What is going on during these callbacks?
Thanks for any information.
while (1)
{
if (rxstate==1)
{
PDM_Filter(&pdmRxBuf[0],&MidBuffer[0], &PDM1_filter_handler);
for (int i=0; i<16;i++)
{
FifoWrite(MidBuffer[i]);
}
if (fifo_w_ptr-fifo_r_ptr > 128) fifo_read_enabled=1;
rxstate=0;
}
if (rxstate==2)
{
PDM_Filter(&pdmRxBuf[64],&MidBuffer[0], &PDM1_filter_handler);
for (int i=0; i<16;i++)
{
FifoWrite(MidBuffer[i]);
}
rxstate=0;
}
if (txstate==1) {
if (fifo_read_enabled==1)
{
for (int i=0; i<64;i=i+4) //64
{
uint16_t data = FifoRead();
txBuf[i] = data;
txBuf[i+2] = data;
}
}
txstate=0;
}
if (txstate==2)
{
if (fifo_read_enabled==1)
{
for (int i=64; i<128;i=i+4)
{
uint16_t data = FifoRead();
txBuf[i] = data;
txBuf[i+2] = data;
}
}
txstate=0;
}
void HAL_I2S_TxHalfCpltCallback (I2S_HandleTypeDef *hi2s) {
txstate = 1;
}
void HAL_I2S_TxCpltCallback (I2S_HandleTypeDef *hi2s) {
txstate = 2;
}
void HAL_I2S_RxHalfCpltCallback (I2S_HandleTypeDef *hi2s) {
rxstate = 1;
}
void HAL_I2S_RxCpltCallback (I2S_HandleTypeDef *hi2s) {
rxstate = 2;
}