Author Topic: CS4344 (24 bit DAC)  (Read 1079 times)

0 Members and 1 Guest are viewing this topic.

Offline alizare368Topic starter

  • Regular Contributor
  • *
  • Posts: 56
  • Country: de
CS4344 (24 bit DAC)
« on: January 17, 2019, 09:51:13 am »
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
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14297
  • Country: fr
Re: CS4344 (24 bit DAC)
« Reply #1 on: January 17, 2019, 05:19:48 pm »
A couple remarks:
* Could you show the declaration of 'sai_buf'? And the value of 'sample_no'?
* I'm assuming you're doing some kind of ping-pong (double buffering), but I need to make sure you got it right.
* The "f_read(&myfile,&sai_buf[index_buf%2],sample_no,&bt)" call: have you timed how long it takes? If it takes longer than the playing of one buffer through I2S, then you're screwed and that would explain your problem.
 

Offline alizare368Topic starter

  • Regular Contributor
  • *
  • Posts: 56
  • Country: de
Re: CS4344 (24 bit DAC)
« Reply #2 on: January 20, 2019, 01:17:16 pm »
Hi
the call back function problem has been resolved  but the audio output is not clear.
the part of the audio output is placed in the file below. :( :(  |O
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf