Author Topic: 24Bit DAC (CS4344)  (Read 2744 times)

0 Members and 1 Guest are viewing this topic.

Offline alizare368Topic starter

  • Regular Contributor
  • *
  • Posts: 56
  • Country: de
24Bit DAC (CS4344)
« on: January 10, 2019, 01:13:04 pm »
Hi-All
I use CS4344 on my board and connected to stm32f401 as I2S2.
I connected the pins to stm32f401.
SDIN to I2S2_SD
SCLK to I2S2_CK
LRCK to I2S2_WS
MCK  to I2S2_MCK

STM32cube I2S configuration :
mode:master transmit
data and format :16bit data and on 16 bit format
audio frequency:48KHz
clok polarity :low

c code example after INIT:
HAL_I2S_Transmit(&hi2s2,(uint16_t *)sai_buf[0],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?
 :(
   
« Last Edit: January 15, 2019, 01:06:26 pm by alizare368 »
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1613
  • Country: gb
Re: 24Bit DAC (CS4344)
« Reply #1 on: January 10, 2019, 04:01:33 pm »
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
« Last Edit: January 10, 2019, 05:22:47 pm by Buriedcode »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14490
  • Country: fr
Re: 24Bit DAC (CS4344)
« Reply #2 on: January 10, 2019, 04:29:41 pm »
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.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: 24Bit DAC (CS4344)
« Reply #3 on: January 10, 2019, 06:03:31 pm »
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.
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 
The following users thanked this post: alizare368

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1720
  • Country: se
Re: 24Bit DAC (CS4344)
« Reply #4 on: January 10, 2019, 07:30:36 pm »
HAL_I2S_Transmit(&hi2s2,(uint16_t *)sai_buf[0],512,1000);
If this is your actual code, look closely at the second parameter: are you sure that's what you really mean?
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14490
  • Country: fr
Re: 24Bit DAC (CS4344)
« Reply #5 on: January 10, 2019, 10:49:56 pm »
HAL_I2S_Transmit(&hi2s2,(uint16_t *)sai_buf[0],512,1000);
If this is your actual code, look closely at the second parameter: are you sure that's what you really mean?

Probably not indeed. ::)
 

Offline alizare368Topic starter

  • Regular Contributor
  • *
  • Posts: 56
  • Country: de
Re: 24Bit DAC (CS4344)
« Reply #6 on: January 11, 2019, 08:22:31 am »
Hi
Thank you for your help.
I send sample code to you.
« Last Edit: January 11, 2019, 08:31:25 am by alizare368 »
 

Offline alizare368Topic starter

  • Regular Contributor
  • *
  • Posts: 56
  • Country: de
Re: 24Bit DAC (CS4344)
« Reply #7 on: January 15, 2019, 02:00:03 pm »
Hi,
I have made some improvements to my code,here is my  new settings,

The I2S init function
Code: [Select]
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 function

Code: [Select]
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[0],sample_no,&bt);
myfres=f_read(&myfile,&sai_buf[1],sample_no,&bt);
index_buf++;
h_res=HAL_I2S_Transmit_DMA(&hi2s2,sai_buf[0],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 I2S

Code: [Select]
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 |O |O |O
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf