需要接一个四输入的音频ADC,以前用F413,L452都没有问题,但使用H750自动生成代码,启动后中断一次,中断后出现传输错误,全部清除状态,在中断前,测试各个时钟全部正确。硬件是买的核心板应该没问题。使用ST的工程,他里面只有SAI作为PDM麦克风输入的程序,也是正常的,不知道出现什么问题。
代码初始化代码如下:
static void MX_SAI4_Init(void)
{
/* USER CODE BEGIN SAI4_Init 0 */
/* USER CODE END SAI4_Init 0 */
/* USER CODE BEGIN SAI4_Init 1 */
/* USER CODE END SAI4_Init 1 */
hsai_BlockA4.Instance = SAI4_Block_A;
hsai_BlockA4.Init.Protocol = SAI_FREE_PROTOCOL;
hsai_BlockA4.Init.AudioMode = SAI_MODEMASTER_RX;
hsai_BlockA4.Init.DataSize = SAI_DATASIZE_16;
hsai_BlockA4.Init.FirstBit = SAI_FIRSTBIT_MSB;
hsai_BlockA4.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
hsai_BlockA4.Init.Synchro = SAI_ASYNCHRONOUS;
hsai_BlockA4.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
hsai_BlockA4.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
hsai_BlockA4.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
hsai_BlockA4.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_48K;
hsai_BlockA4.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
hsai_BlockA4.Init.MonoStereoMode = SAI_STEREOMODE;
hsai_BlockA4.Init.CompandingMode = SAI_NOCOMPANDING;
hsai_BlockA4.Init.PdmInit.Activation = ENABLE;
hsai_BlockA4.Init.PdmInit.MicPairsNbr = 2;
hsai_BlockA4.Init.PdmInit.ClockEnable = SAI_PDM_CLOCK1_ENABLE;
hsai_BlockA4.FrameInit.FrameLength = 64;
hsai_BlockA4.FrameInit.ActiveFrameLength = 1;
hsai_BlockA4.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
hsai_BlockA4.FrameInit.FSPolarity = SAI_FS_ACTIVE_HIGH;
hsai_BlockA4.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
hsai_BlockA4.SlotInit.FirstBitOffset = 0;
hsai_BlockA4.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
hsai_BlockA4.SlotInit.SlotNumber = 4;
hsai_BlockA4.SlotInit.SlotActive = 0x0000000F;
if (HAL_SAI_Init(&hsai_BlockA4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SAI4_Init 2 */
/* USER CODE END SAI4_Init 2 */
}
void HAL_SAI_MspInit(SAI_HandleTypeDef* hsai)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
/* SAI4 */
if(hsai->Instance==SAI4_Block_A)
{
/* Peripheral clock enable */
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SAI4A;
PeriphClkInitStruct.PLL2.PLL2M = 11;
PeriphClkInitStruct.PLL2.PLL2N = 346;
PeriphClkInitStruct.PLL2.PLL2P = 32;
PeriphClkInitStruct.PLL2.PLL2Q = 2;
PeriphClkInitStruct.PLL2.PLL2R = 2;
PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_1;
PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
PeriphClkInitStruct.Sai4AClockSelection = RCC_SAI4ACLKSOURCE_PLL2;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
if (SAI4_client == 0)
{
__HAL_RCC_SAI4_CLK_ENABLE();
}
SAI4_client ++;
/**SAI4_A_Block_A GPIO Configuration
PE2 ------> SAI4_MCLK_A
PE4 ------> SAI4_FS_A
PE5 ------> SAI4_SCK_A
PE6 ------> SAI4_SD_A
*/
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF8_SAI4;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* Peripheral DMA init*/
hdma_sai4_a.Instance = BDMA_Channel0;
hdma_sai4_a.Init.Request = BDMA_REQUEST_SAI4_A;
hdma_sai4_a.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_sai4_a.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_sai4_a.Init.MemInc = DMA_MINC_ENABLE;
hdma_sai4_a.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_sai4_a.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_sai4_a.Init.Mode = DMA_CIRCULAR;
hdma_sai4_a.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_sai4_a) != HAL_OK)
{
Error_Handler();
}
/* Several peripheral DMA handle pointers point to the same DMA handle.
Be aware that there is only one channel to perform all the requested DMAs. */
__HAL_LINKDMA(hsai,hdmarx,hdma_sai4_a);
__HAL_LINKDMA(hsai,hdmatx,hdma_sai4_a);
}
}
void BDMA_Channel0_IRQHandler(void)
{
/* USER CODE BEGIN BDMA_Channel0_IRQn 0 */
/* USER CODE END BDMA_Channel0_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_sai4_a);
/* USER CODE BEGIN BDMA_Channel0_IRQn 1 */
/* USER CODE END BDMA_Channel0_IRQn 1 */
} |
下次发完主题帖可以给自己回个帖顶一顶,这样更容易被大家看到,因为更新快,被压下去了,被看到的几率小