2026-02-06 11:16 AM - edited 2026-02-06 1:56 PM
I am trying to capture data from the LINE_IN (blue jack on board), but I am not receiving the correct input. I evaluated my output at the oscilloscope and noticed that I am not receiving the sinusoid I am injecting; the frequency is correct, but the data appears clipped, as shown in the picture. I tried to reduce the Vpp, but it just started getting noisy instead of giving the correct input.
My second test was to record on the sd card, and the problem persisted; I am only getting data above zero and noise
I am using the BSP library stm32h735g_discovery_audio.c, and to get the correct frequency that I was inputting, I modified these values in the BSP_AUDIO_IN_Init
mx_config.FrameLength = 64;//changed: prev:128
mx_config.ActiveFrameLength = 32;//changed /An changed the number of slots like this:
hsai->SlotInit.SlotNumber = 4; /* WM8994 TDM mode: 4 slots */
I also tried to modify these registers from the audio codec directly, but nothing seems to make it work:
* Disable mute on IN1L_TO_MIXINL and +30dB on IN1L PGA output */
//tmp = 0x0035;
//ret += wm8994_write_reg(&pObj->Ctx, WM8994_INPUT_MIXER_3, &tmp, 2);
/* CHANGE! MIXOUTR_MIXINR_VOL set to 0 (mute)
* +30db removed : 0x0020 instead of 0x0035 */
tmp = 0x0020;
ret += wm8994_write_reg(&pObj->Ctx, WM8994_INPUT_MIXER_3, &tmp, 2);
/* Disable mute on IN1R_TO_MIXINL, Gain = +30dB */
//ret += wm8994_write_reg(&pObj->Ctx, WM8994_INPUT_MIXER_4, &tmp, 2);
/* CHANGE! MIXOUTL_MIXINL_VOL set to 0 (mute)
* +30db removed : 0x0020 instead of 0x0035 */
tmp = 0x0020;
ret += wm8994_write_reg(&pObj->Ctx, WM8994_INPUT_MIXER_4, &tmp, 2);:
/* Enable VMID and Master Bias - Critical for LINE_IN to capture negative cycle */
tmp = 0x0007;
ret += wm8994_write_reg(&pObj->Ctx, WM8994_PWR_MANAGEMENT_1, &tmp, 2);Does anyone have experienced the same issue and have suggestions on how to solve this problem? This is how I am initializing the input and output.
int Audio_LoopbackInit(void)
{
BSP_AUDIO_Init_t AudioInInit;
BSP_AUDIO_Init_t AudioOutInit;
/* Configure audio INPUT (LINE_IN) */
AudioInInit.Device = AUDIO_IN_DEVICE_ANALOG_LINE1; /* LINE_IN jack */
AudioInInit.ChannelsNbr = 2; /* Stereo */
AudioInInit.SampleRate = AUDIO_FREQUENCY_48K;
AudioInInit.BitsPerSample = AUDIO_RESOLUTION_16B;
AudioInInit.Volume = 100;
/* Instance 0 = SAI/LINE_IN (NOT Instance 2 which is DFSDM/digital mics) */
if (BSP_AUDIO_IN_Init(0, &AudioInInit) != BSP_ERROR_NONE)
{
return -1; /* Failed - check codec I2C connection */
}
/* Configure audio OUTPUT (Headphone) */
AudioOutInit.Device = AUDIO_OUT_DEVICE_HEADPHONE;
AudioOutInit.ChannelsNbr = 2;
AudioOutInit.SampleRate = AUDIO_FREQUENCY_48K;
AudioOutInit.BitsPerSample = AUDIO_RESOLUTION_16B;
AudioOutInit.Volume = 50;
if (BSP_AUDIO_OUT_Init(0, &AudioOutInit) != BSP_ERROR_NONE)
{
return -2; /* Failed */
}
return 0;
}EDIT: The problem was this function, I needed to configure the BSP_AUDIO_OUT_Init first