cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 Discovery Board -- I2C communication with audio codec

sjpatel1992
Associate II
Posted on July 14, 2015 at 16:34

Hi all!

I am trying to configure the WM8994 Audio Codec on the STM32F7 Discovery Board to output the sound picked up by the two mics to the headphone output jack. I have used ST's code generation tool to generate the initialization code for I2C3 as well as SAI2 peripherals. I am using the HAL I2C library to read from and write to the audio codec's registers. For many of the registers, when I first try to write a value into a register, and then read back from the same register, I get 0. Below is my function that reads a register and then writes a user specified value into the register

void
Audio_Codec_I2C_Memory_Write( uint16_t Memory_Address, uint16_t Change_Bits, uint16_t Change)
{
while
(HAL_I2C_IsDeviceReady(&hi2c3, I2C_Address, 1,1) == HAL_OK)
{
HAL_I2C_Mem_Read(&hi2c3, I2C_Address, Memory_Address, I2C_MEMADD_SIZE_16BIT, Data, 2, 1);
break
;
}
Data[1] = (Data[1] & ~(uint8_t)((Change_Bits & 0x00FF))) | (uint8_t)((Change & 0x00FF));
Data[0] = (Data[0] & ~(uint8_t)(((Change_bits & 0xFF00)>>8))) | (uint8_t)(((Change & 0xFF00)>>8));
while
(HAL_I2C_IsDeviceReady(&hi2c3, I2C_Address, 1,1) == HAL_OK)
{
HAL_I2C_Mem_Write(&hi2c3, I2C_Address, Memory_Address, I2C_MEMADD_SIZE_16BIT, Data, 2, 1);
break
;
}
Data[0] = 0; 
//reset
Data[1] = 0;
}

Am I using the I2C function calls correctly? Thanks for the help
0 REPLIES 0