Skip to main content
Tank2005
Associate
March 19, 2019
Solved

I2S master transfer signal is something wrong

  • March 19, 2019
  • 2 replies
  • 1046 views

My environment is Nucleo-F446RE with STM32CubeMX 5.1 / TrueSTUDIO 9.3.

​

I created an I2S master transmit test program. [Full project archive is

here]

  • Transmission Mode / Mode Master Transmit
  • Communication Standard / LSB First(Right Justified)
  • Data and Frame Format / 16 Bits Data on 16 Bits Frame
  • Selected Audio Frequency / 48KHz(*I2S cloks is 61.44(8MHz /5 * 192 /5)MHz)

​

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
#define I2S_CODE 0b1010110011110000
 
#define I2S_BUFFER_SIZE 64
#define I2S_BUFFER_HALF_SIZE (I2S_BUFFER_SIZE / 2)
uint16_t buffer[I2S_BUFFER_SIZE];
 
void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
{
	uint16_t *sp = buffer;
	for(int i = 0; i < I2S_BUFFER_HALF_SIZE; i++) *(sp++) = I2S_CODE;
}
 
void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s)
{
	uint16_t *sp = buffer + I2S_BUFFER_HALF_SIZE;
	for(int i = 0; i < I2S_BUFFER_HALF_SIZE; i++) *(sp++) = 0x00;
}
 
void StartI2STransfer()
{
 memset (buffer, 0, sizeof(buffer));
 HAL_I2S_Transmit_DMA(&hi2s2, buffer, I2S_BUFFER_SIZE * sizeof(uint16_t));
}
/* USER CODE END 0 */
 
int main(void)
{
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 StartI2STransfer();
 while (1)
 {
 /* USER CODE END WHILE */
 
 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}

However, STM32F4 outputs a same signal twice.

For example, in this program, I put the I2S signal as "10101100111100001010110011110000...". But a output signal is "10101100101011001111000011110000..." like this image.

​

​0690X0000088EAcQAM.png

​

Please tell me how to solve this problem.

​

This topic has been closed for replies.
Best answer by Piranha
  1. In DMA configuration You have peripheral and memory data sizes set to byte, but with 16-bit data both of them should be half-word.
  2. HAL_I2S_Transmit_DMA function's 3rd parameter is data item count (total for both channels) not byte count.

2 replies

Piranha
PiranhaBest answer
Principal III
March 19, 2019
  1. In DMA configuration You have peripheral and memory data sizes set to byte, but with 16-bit data both of them should be half-word.
  2. HAL_I2S_Transmit_DMA function's 3rd parameter is data item count (total for both channels) not byte count.
Tank2005
Tank2005Author
Associate
March 20, 2019

After changing a parameter to "Half Word", that signal was output as I expected. Thank you so much.

0690X0000088M7gQAE.png

0690X0000088M7lQAE.png