24Bit DAC (CS4344) - Page 1
Forum section: electronics / general

author: alizare368
author_rank: Regular Contributor
timestamp: January 10, 2019, 01:13:04 pm
content: Hi-AllI use CS4344 on my board and connected to stm32f401 as I2S2.I connected the pins to stm32f401.SDIN to I2S2_SDSCLK to I2S2_CKLRCK to I2S2_WSMCK to I2S2_MCKSTM32cube I2S configuration :mode:master transmitdata and format :16bit data and on 16 bit formataudio frequency:48KHzclok polarity :lowc code example after INIT:HAL_I2S_Transmit(&hi2s2,(uint16_t *)sai_buf,512,1000);why does not work?and DAC output connect to TDA2822 (audio AMP)And TDA2822 output connect to speaker computer.Why speed sound run is slow?

author: Buriedcode
author_rank: Super Contributor
timestamp: January 10, 2019, 04:01:33 pm
content: The trouble with setting it all up, writing code and seeing if the whole thing works is, if it doesn't work you dont' know which part. Software or hardware.I would start by verifying that the micro is generating the required signals, preferably when a button is hit or something. A scope or logic analyzer is required.A very cheap way of debugging - just to see if *any* signals are sent is to use a bicolour LED, or back-to-back LED's hooked to the IO, with two 1K resistors. This way you can see when the pin is high, low, or a pulse train (like SCLK). It is far from ideal as it won't give any timing information, and you would need to continuously send signals to the DAC to see any changes.That will at least give you a yes/no on the software side, but wont' tell you whats wrong if you see nothing.Also, post your init and main routines.edit: typos

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 10, 2019, 04:29:41 pm
content: One thing I have no clue about is how MCLK's frequency is configured by STM32Cube. Do you have an oscilloscope? Refer to page 12 of the datasheet.

author: hamster_nz
author_rank: Super Contributor
timestamp: January 10, 2019, 06:03:31 pm
content: I have got exactly this part on my bench at the moment, and it is working fine, but from an FPGA.Do you have a logic analyser or scope, or a frequency counter? If so, check the frequency of the clocks.What load are you driving? These parts won't drive a speaker or earbuds directly.... I am using old powered computer speakers.

author: newbrain
author_rank: Super Contributor
timestamp: January 10, 2019, 07:30:36 pm
content: Quote from: alizare368 on January 10, 2019, 01:13:04 pmIf this is your actual code, look closely at the second parameter: are you sure that's what you really mean?

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 10, 2019, 10:49:56 pm
content: Quote from: newbrain on January 10, 2019, 07:30:36 pmProbably not indeed.

author: alizare368
author_rank: Regular Contributor
timestamp: January 11, 2019, 08:22:31 am
content: HiThank you for your help.I send sample code to you.

author: alizare368
author_rank: Regular Contributor
timestamp: January 15, 2019, 02:00:03 pm
content: Hi,I have made some improvements to my code,here is my new settings,The I2S init functionCode:static void MX_I2S2_Init(void){/* USER CODE BEGIN I2S2_Init 0 *//* USER CODE END I2S2_Init 0 *//* USER CODE BEGIN I2S2_Init 1 *//* USER CODE END I2S2_Init 1 */hi2s2.Instance = SPI2;hi2s2.Init.Mode = I2S_MODE_MASTER_TX;hi2s2.Init.Standard = I2S_STANDARD_PHILIPS;hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B;hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;hi2s2.Init.AudioFreq = 44100;hi2s2.Init.CPOL = I2S_CPOL_LOW;hi2s2.Init.ClockSource = I2S_CLOCK_PLL;hi2s2.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE;if (HAL_I2S_Init(&hi2s2) != HAL_OK){Error_Handler();}/* USER CODE BEGIN I2S2_Init 2 *//* USER CODE END I2S2_Init 2 */}And this is my main functionCode:int main(void){/* USER CODE BEGIN 1 */static FRESULT myfres=1;uint32_t bt;/* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_DMA_Init();MX_I2S2_Init();/* USER CODE BEGIN 2 */myfres=disk_initialize(0);myfres=f_mount(0, &fs);myfres=f_open(&myfile, "1.wav",FA_READ);myfres=f_read(&myfile,&sai_buf,sample_no,&bt);myfres=f_read(&myfile,&sai_buf,sample_no,&bt);index_buf++;h_res=HAL_I2S_Transmit_DMA(&hi2s2,sai_buf,sample_no);/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */if(refill){refill=0;myfres=f_read(&myfile,&sai_buf[index_buf%2],sample_no,&bt);}}/* USER CODE END 3 */}and this is my callback function for the I2SCode:void HAL_I2S_TxCpltCallback( I2S_HandleTypeDef * hi2s ){refill=1;HAL_I2S_Transmit_DMA(hi2s,sai_buf[index_buf%2],sample_no);index_buf++;}The problem is that the I2S callback would be called 8 times before comming back to main to refill the next buffer,Do you have any Idea? I'm really in trouble and do not know what to do