AnsweredAssumed Answered

I²S on STM32F411

Question asked by Ecochard.Florent.001 on Jun 30, 2015
Latest reply on Jun 30, 2015 by Ecochard.Florent.001
Hi!
I'm trying to communicate with a CS4344 DAC via I²S but I can't get it to work.
I followed the steps on the STM32's HAL reference but I guess I made one or several mistakes as I don't get any output on any of the I²S pins.

Here is my code : 
01.#include "mbed.h"
02. 
03.I2S_InitTypeDef CS4344_conf;
04.I2S_HandleTypeDef CS4344;
05.GPIO_InitTypeDef SDIN;
06.GPIO_InitTypeDef SCLK;
07.GPIO_InitTypeDef LRCLK;
08.GPIO_InitTypeDef MCLK;
09.uint16_t buf[2] = {0x1245, 0x6842};
10. 
11.int main() {
12.    CS4344_conf.Mode = I2S_MODE_MASTER_TX;
13.    CS4344_conf.Standard = I2S_STANDARD_PHILIPS;
14.    CS4344_conf.DataFormat = I2S_DATAFORMAT_16B;
15.    CS4344_conf.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
16.    CS4344_conf.AudioFreq = I2S_AUDIOFREQ_96K;
17.    CS4344_conf.CPOL = I2S_CPOL_LOW;
18.    CS4344_conf.ClockSource = I2S_CLOCK_PLL;
19.    CS4344_conf.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE;
20.     
21.    CS4344.Instance = SPI3;
22.    CS4344.Init = CS4344_conf;
23.     
24.    HAL_I2S_MspInit (&CS4344);
25.     
26.    //-------- Enable the SPIx interface clock.
27.    __HAL_RCC_SPI3_CLK_ENABLE();
28.    __HAL_RCC_GPIOA_CLK_ENABLE();
29.    __HAL_RCC_GPIOB_CLK_ENABLE();
30.    __HAL_I2S_ENABLE(&CS4344);
31.     
32.    //-------- I2S pins configuration:
33.    SDIN.Pin = GPIO_PIN_5;
34.    SDIN.Mode = GPIO_MODE_AF_PP;
35.    SDIN.Pull = GPIO_PULLUP;
36.    SDIN.Alternate = GPIO_AF6_SPI3;
37.     
38.    SCLK.Pin = GPIO_PIN_3;
39.    SCLK.Mode = GPIO_MODE_AF_PP;
40.    SCLK.Pull = GPIO_PULLUP;
41.    SCLK.Alternate = GPIO_AF6_SPI3;
42.     
43.    LRCLK.Pin = GPIO_PIN_15;
44.    LRCLK.Mode = GPIO_MODE_AF_PP;
45.    LRCLK.Pull = GPIO_PULLUP;
46.    LRCLK.Alternate = GPIO_AF6_SPI3;
47.     
48.    MCLK.Pin = GPIO_PIN_10;
49.    MCLK.Mode = GPIO_MODE_AF_PP;
50.    MCLK.Pull = GPIO_PULLUP;
51.    MCLK.Alternate = GPIO_AF6_SPI3;
52.     
53.    HAL_GPIO_Init (GPIOB, &SDIN);
54.    HAL_GPIO_Init (GPIOB, &SCLK);
55.    HAL_GPIO_Init (GPIOB, &MCLK);
56.    HAL_GPIO_Init (GPIOA, &LRCLK);
57.     
58.    // ------------- Program the Mode, Standard, Data Format, MCLK Output, Audio frequency and Polarity using HAL_I2S_Init() function.
59.    //HAL_I2S_MspInit (&CS4344);
60.     
61.    HAL_I2S_Init (&CS4344);
62. 
63.    while(1) {
64.        HAL_I2S_Transmit (&CS4344, buf, 2, 1000);
65. 
66.    }
67.}

What am I doing wrong? all the other example codes on the internet are using a different HAL (the functions don't match to the ones in the reference...)

Outcomes