MA1:各个通道一览
DMA2:各个通道一览
1.stm32DMA相关固件库函数说明
第一个参数选择哪一个DMA的哪一个通道
初始化函数
void DMA_Init(DMA_Channel_TypeDef* DMAy_Channelx, DMA_InitTypeDef* DMA_InitStruct);
typedef struct { uint32_t DMA_PeripheralBaseAddr; //外设地址 uint32_t DMA_MemoryBaseAddr; //存储器地址 uint32_t DMA_DIR; //传输方向 //#define DMA_DIR_PeripheralDST //外设作为目标 //#define DMA_DIR_PeripheralSRC //外设作为源 uint32_t DMA_BufferSize; //输出大小 uint32_t DMA_PeripheralInc; //外设地址增量模式 //#define DMA_PeripheralInc_Enable //#define DMA_PeripheralInc_Disable uint32_t DMA_MemoryInc; //存储器地址增量模式 //#define DMA_MemoryInc_Enable //#define DMA_MemoryInc_Disable uint32_t DMA_PeripheralDataSize; //外设数据宽度 字节,半字 //#define DMA_PeripheralDataSize_Byte 字节 //#define DMA_PeripheralDataSize_HalfWord 半字 //#define DMA_PeripheralDataSize_Word 字 uint32_t DMA_MemoryDataSize; //存储器数据宽度 //#define DMA_MemoryDataSize_Byte //#define DMA_MemoryDataSize_HalfWord //#define DMA_MemoryDataSize_Word uint32_t DMA_Mode; //模式选择 //#define DMA_Mode_Circular 循环模式 //#define DMA_Mode_Normal 正常模式 uint32_t DMA_Priority; //通道优先级 //#define DMA_Priority_VeryHigh //#define DMA_Priority_High //#define DMA_Priority_Medium //#define DMA_Priority_Low uint32_t DMA_M2M; //存储器到存储器模式 //#define DMA_M2M_Enable //#define DMA_M2M_Disable }DMA_InitTypeDef;
开启DMA通道
void DMA_Cmd(DMA_Channel_TypeDef* DMAy_Channelx, FunctionalState NewState)
ENABLE or DISABLE.DMA中断配置
void DMA_ITConfig(DMA_Channel_TypeDef* DMAy_Channelx, uint32_t DMA_IT, FunctionalState NewState);
第二个参数设置,中断请求,第三个参数设置,打开还是关闭,ENABLE or DISABLE.
DMA_IT_TC: Transfer complete interrupt mask
DMA_IT_HT: Half transfer interrupt mask
DMA_IT_TE: Transfer error interrupt mask
DMA清除中断挂起
void DMA_ClearITPendingBit(uint32_t DMAy_IT);
DMA获取中断状态
ITStatus DMA_GetITStatus(uint32_t DMAy_IT);
获取传输剩余个数
uint16_t DMA_GetCurrDataCounter(DMA_Channel_TypeDef* DMAy_Channelx);
DMA时钟在AHB总线上
void RCC_AHBPeriphResetCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
2.串口
异步通信,全双工;
串口固件库函数:
1)初始化串口
参数1:USART1, USART2, USART3(同步,异步), UART4 or UART5(异步)
参数2:结构体
void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
typedef struct { uint32_t USART_BaudRate; //波特率 uint16_t USART_WordLength; //有效数据位 //#define USART_WordLength_8b //#define USART_WordLength_9b uint16_t USART_StopBits; //停止位,串口一般为1 //#define USART_StopBits_1 //#define USART_StopBits_0_5 //#define USART_StopBits_2 //#define USART_StopBits_1_5 uint16_t USART_Parity; //校验 //#define USART_Parity_No //没有校验 //#define USART_Parity_Even //偶校验 //#define USART_Parity_Odd //奇校验 uint16_t USART_Mode; //串口模式 //#define USART_Mode_Rx //发送模式 //#define USART_Mode_Tx //接收模式 uint16_t USART_HardwareFlowControl; //流控 //#define USART_HardwareFlowControl_None // 无流控 //#define USART_HardwareFlowControl_RTS //#define USART_HardwareFlowControl_CTS //#define USART_HardwareFlowControl_RTS_CTS } USART_InitTypeDef;
2)打开串口使能:
USART1, USART2, USART3, UART4 or UART5.
第二个参数为:ENABLE or DISABLE.
void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
3)串口中断:
USART1, USART2, USART3, UART4 or UART5.
第二个参数为:
@arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
* @arg USART_IT_LBD: LIN Break detection interrupt
* @arg USART_IT_TXE: Transmit Data Register empty interrupt 发送中断(发送完成)
* @arg USART_IT_TC: Transmission complete interrupt
* @arg USART_IT_RXNE: Receive Data register not empty interrupt 接收中断(收到数据)
* @arg USART_IT_IDLE: Idle line detection interrupt 空闲中断
* @arg USART_IT_PE: Parity Error interrupt
* @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
第三个参数为:ENABLE or DISABLE.
void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
4)发送函数
USART1, USART2, USART3, UART4 or UART5.
第二个参数为要发送的数据:
void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
4)接收函数
uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
接收的数据以返回值的形式接收
5)DMA串口打开
第一个参数: USART1, USART2, USART3, UART4 or UART5.
第二个参数:
@arg USART_DMAReq_Tx: USART DMA transmit request 发送请求
@arg USART_DMAReq_Rx: USART DMA receive request 接收
第三个:
ENABLE or DISABLE.
void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);