#include "debug.h"
#include "ch32v30x_gpio.h"
#include "ch32v30x_rcc.h"
/* Global typedef */
/* Global define */
#define TxBufferSize 24
#define RxBufferSize 24
/* Global Variable */
u8 TxBuffer[TxBufferSize]={
??????? 0x0000, 0x0000, 0x0000, 0x0000,
??????? 0x0001, 0x0001, 0x0001, 0x0001,
??????? 0x0002, 0x0002, 0x0002, 0x0002,
??????? 0x0003, 0x0003, 0x0003, 0x0003,
??????? 0x0004, 0x0004, 0x0004, 0x0004,
??????? 0x0005, 0x0005, 0x0005, 0x0005,
};
u8 RxBuffer[RxBufferSize];
u16 data[6];
/*********************************************************************
?* @fn????? USARTx_CFG
?*
?* @brief?? Initializes the USART2 & USART3 peripheral.
?*
?* @return? none
?*/
void USART2_init(void)
{
??? GPIO_InitTypeDef? GPIO_InitStructure = {0};
??? USART_InitTypeDef USART_InitStructure = {0};
??? USART_ClockInitTypeDef USART_ClockInitStruct={0};
??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE );
??? RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
??? /* USART2 TX-->A.2?? RX-->A.3 CLK-->A.4*/
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
??? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
??? GPIO_Init(GPIOA, &GPIO_InitStructure);
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
??? GPIO_Init(GPIOA, &GPIO_InitStructure);
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
??? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
??? GPIO_Init(GPIOA, &GPIO_InitStructure);
??? USART_InitStructure.USART_BaudRate = 115200;
??? USART_InitStructure.USART_WordLength = USART_WordLength_8b;
??? USART_InitStructure.USART_StopBits = USART_StopBits_1;
??? USART_InitStructure.USART_Parity = USART_Parity_No;
??? USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
??? USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
??? USART_Init(USART2, &USART_InitStructure);
??? USART_ClockInitStruct.USART_Clock = USART_Clock_Enable;
??? USART_ClockInitStruct.USART_CPOL = USART_CPOL_Low;
??? USART_ClockInitStruct.USART_CPHA = USART_CPHA_1Edge;
??? USART_ClockInitStruct.USART_LastBit = USART_LastBit_Enable;
??? USART_ClockInit(USART2,&USART_ClockInitStruct);
}
//****************************************************
void DMAx_init(void)
{
??? DMA_InitTypeDef DMA_InitStructure = {0};
??? RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
??? DMA_DeInit(DMA1_Channel7);
??? DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&USART2->DATAR); /* USART2->DATAR:0x40004404 */
??? DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&TxBuffer[0];
??? DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
??? DMA_InitStructure.DMA_BufferSize = TxBufferSize;
??? DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
??? DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
??? DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
??? DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
??? DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
??? DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
??? DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
??? DMA_Init(DMA1_Channel7, &DMA_InitStructure);
??? DMA_ClearFlag(DMA1_FLAG_TC7);
??? DMA_ITConfig(DMA1_Channel7, DMA1_IT_TC7, ENABLE);
}
//*********************************************************************
void DMA1_Channel7_IRQHandler_Init(void)
{
??? NVIC_InitTypeDef NVIC_InitStructure;
??? NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel7_IRQn;?? //使能DMA1_Channel7中斷通道
??? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;? //設置搶占優(yōu)先級為0
??? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;???????? //設置子優(yōu)先級為0
??? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;??????????? //使能外部中斷通道
??? NVIC_Init(&NVIC_InitStructure);??????????????????????????? //中斷優(yōu)先級分組初始化
//? NVIC_EnableIRQ(DMA1_Channel7_IRQn);
}
//*********************************************************************
void ERAM_UsartDam_Init(void)//ERAM 存儲器初始化
{
??? USART2_init();
??? USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
??? USART_Cmd(USART2, ENABLE);
??? DMAx_init();
??? DMA1_Channel7_IRQHandler_Init();
??? DMA_Cmd(DMA1_Channel7, ENABLE); /* USART2 Tx */
??? NVIC_SetPendingIRQ(DMA1_Channel7_IRQn);//模擬接收到一幀數(shù)據(jù),中斷;
}
//*********************************************************************
void DMA1_Channel7_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
//********************************************************************
void DMA1_Channel7_IRQHandler(void)
{
??? DMA_ClearITPendingBit(DMA1_Channel7_IRQn);/* Clear Flag */
??? while(1);
}
/*********************************************************************
?*/
int main(void)
{
??? ERAM_UsartDam_Init();
??? while(1)
??????? {
?????????? while(DMA_GetCurrDataCounter(DMA1_Channel7)!=0)
?????????????? {
?????????????????? data[0] = DMA_GetCurrDataCounter(DMA1_Channel7);;
?????????????? }
??????? }
}
查看: 748
回復: 1
CH32V307,USART2使用DMA1_CH7發(fā)送完成后,DMA中斷不能正常觸發(fā),不知道是那里有問題,求各位大神幫忙看看;謝謝?。?
熱門產(chǎn)品 :
CH585: 集成高速USB和NFC的藍牙MCU
問題已解決,沒有仔細看說明,給諸位填麻煩了!!中斷沒有使能。
請勿發(fā)布廣告和違法內(nèi)容, 代碼可以選擇編輯器代碼語言格式, 更易他人閱讀幫助您, 或者留下聯(lián)系方式,以便更好更快服務您
只有登錄才能回復,可以選擇微信賬號登錄