1
\$\begingroup\$

I made a STM32H7B0 prototype board to test the Cirrus CS4271 Audio codec (datasheet for the CS4271).

I'm having issue configuring it via I2C. It doesn't respond to any I2C messages. It seems stuck in power-down mode.

I attached the corresponding schematics. I'm generating the clocks via the STM32.

In STM32CubeIDE I have SA1 configured as Master with Master Clock Out, I2S standard, 24 bits, 32Khz. I2C is set in Standard Mode at 100Khz. SDA/SCL lines have 5K1 pull-up to 3.3V.

And this the basic code I'm running to test it:

 HAL_StatusTypeDef halStatus;
 // Initialise SAIs (to start clocks, so that codec PLL locks)
 halStatus = HAL_SAI_Init(&hsai_BlockA1);
 if ( halStatus != HAL_OK ) { Error_LED(); }
 // Start SAI DAC transmission
 halStatus = HAL_SAI_Transmit_DMA(&hsai_BlockA1, (uint8_t *) dacBuf, AUDIO_BUFFER_SIZE);
 if ( halStatus != HAL_OK ) { Error_LED(); }
 // Codec RST to low, wait for clocks to stabilize
 HAL_GPIO_WritePin(CODEC_NRST_GPIO_Port, CODEC_NRST_Pin, GPIO_PIN_RESET);
 HAL_Delay(100);
 // Bring Codec RST high to leave reset
 HAL_GPIO_WritePin(CODEC_NRST_GPIO_Port, CODEC_NRST_Pin, GPIO_PIN_SET);
 HAL_Delay(1);
 uint8_t data = 0x03; // CPEN=1, PDN=1
 halStatus = HAL_I2C_Mem_Write(&hi2c1, (0x10 << 1), 0x07, I2C_MEMADD_SIZE_8BIT, &data, 1, 1000);
 if (halStatus != HAL_OK) {
 uint32_t errorCode = hi2c1.ErrorCode;
 Error_LED();
 }

The HAL_I2C_Mem_Write returns an HAL_Error with code 4 (ACKF error). I checked the SDA/SCL on the oscilloscope and I can see the write command with no response.

codec schematic

asked Apr 3 at 21:05
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You are using (0x48 << 1) as the address, but that can't be the correct address.

The data sheet says the upper six bits must be 001000 so a single bit is on, and thus it will not translate to 0x48 in any way as it has two bits on, regardless of AD0 address bit or being represented as 7-bit or 8-bit address.

I'd say the address is 0x20 in 8-bit format and 0x10 in 7-bit format.

answered Apr 3 at 21:22
\$\endgroup\$
1
  • \$\begingroup\$ Looks like you were right! 0x10 works! One detail is that I need a HAL_Delay(10) after I put RST to high otherwise it doesn't acknowledge even though in the datasheet they say that the command should be sent in the next 10ms after setting RST to high. \$\endgroup\$ Commented Apr 4 at 0:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.