DMA循环只是说DMA循环,不没有指定DMA的数据地址。数据DMA到DAC完了后,需要重置数据指针 ...
具体该怎么做呢?我用了你的代码,出来了杂波,不是正玄波,估计是没有重置数组指针,请问这个在什么时候什么地方做这一步动作?谢谢 wambob 发表于 2017-5-26 14:24
DMA循环只是说DMA循环,不没有指定DMA的数据地址。数据DMA到DAC完了后,需要重置数据指针 ...
在哪里操作呢?DMA中断里? 本帖最后由 wambob 于 2017-5-26 20:23 编辑
风905067 发表于 2017-5-26 15:58
在哪里操作呢?DMA中断里?
抱歉,说错了,我的代码是DMA音乐代码,你的是DMA波形。 使用函数
HAL_DAC_Start_DMA(&hdac, DAC通道, (uint32_t*)数组名, 数组大小, 数据长度);
应该就可以了
原理上时一样的,把数组的数据循环DMA到DAC的通道,就产生了波形,波形的频率跟定时器的预装值有关,幅值跟数组的值有关
F722播放音乐数组的代码,你参考下
#include "main.h"
#include "stm32f7xx_hal.h"
/* USER CODE BEGIN Includes */
#define __CLK_TCK 1000
#define AUDIO_FILE_ADDRESS 0x08060000
#define AUDIO_FILE_SIZE 119652
#define PLAY_BUFF_SIZE (16*1000)
#define PLAY_HEADER 0x2C
uint8_t PlayBuff;
__IO int16_t UpdatePointer = -1;
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
DAC_HandleTypeDef hdac;
DMA_HandleTypeDef hdma_dac2;
TIM_HandleTypeDef htim6;
UART_HandleTypeDef huart3;
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_DAC_Init(void);
static void MX_USART3_UART_Init(void);
static void MX_TIM6_Init(void);
//void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac)
//{
//UpdatePointer = PLAY_BUFF_SIZE/2;
//}
//void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac)
//{
//UpdatePointer = 0;
//}
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
//uint32_t PlaybackPosition = PLAY_BUFF_SIZE + PLAY_HEADER;
/* USER CODE END 1 */
/* Enable I-Cache-------------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache-------------------------------------------------------------*/
SCB_EnableDCache();
/* 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_DAC_Init();
MX_USART3_UART_Init();
MX_TIM6_Init();
/* USER CODE BEGIN 2 */
/* Initialize the data buffer */
for(int i=0; i < PLAY_BUFF_SIZE; i+=sizeof(uint8_t))
{
PlayBuff=*((__IO uint8_t *)(AUDIO_FILE_ADDRESS +PLAY_HEADER + i));
}
HAL_TIM_Base_Start(&htim6);
HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_2, (uint32_t*)PlayBuff, PLAY_BUFF_SIZE, DAC_ALIGN_8B_R);
printf("Demo for 21ic Audio Series Article, by zhanzr21 @ 21ic BBS\n");
printf("BSD Style License for my own code\n");
printf("For the library please refer to the license declaim of their own.\n");
printf("DAC + DMA Test For STM32F722 Nucleo Board @ %u MHz\n", SystemCoreClock/1000000);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
/* Wait a callback event */
// while(UpdatePointer==-1);
//
// int position = UpdatePointer;
// UpdatePointer = -1;
// /* Upate the first or the second part of the buffer */
// for(int i = 0; i < PLAY_BUFF_SIZE/2; i++)
// {
// PlayBuff = *(uint8_t *)(AUDIO_FILE_ADDRESS + PlaybackPosition);
// PlaybackPosition+=sizeof(uint8_t);
// }
// /* check the end of the file */
// if((PlaybackPosition+(PLAY_BUFF_SIZE/2)/sizeof(uint8_t)) > AUDIO_FILE_SIZE)
// {
// PlaybackPosition = PLAY_HEADER;
// }
//
// if(UpdatePointer != -1)
// {
// /* Buffer update time is too long compare to the data transfer time */
// Error_Handler();
// }
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
你是用什么编译的,用什么建工程的,我的keil里好像没有文件:stm32f7xx_hal.h,所以也没办法#include "stm32f7xx_hal.h"的, 我用的是STM32F207。 问题解决了,其实我的那个程序是可以的,就是一个小地方没有搞对,谢谢你的帮助。我知道问题在哪里了 。谢谢!!!谢谢谢!!!!!!! 请问你是在哪里工作?是否可以加微信好友,或者QQ好友? 请问你是在哪···‘·‘·‘’’’里工作,是否可以加微##¥信@!#好···友,或者Q·@为好···友??
页:
1
[2]