本文整理汇总了C++中USART_DMACmd函数的典型用法代码示例。如果您正苦于以下问题:C++ USART_DMACmd函数的具体用法?C++ USART_DMACmd怎么用?C++ USART_DMACmd使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了USART_DMACmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MicoUartSend
OSStatus MicoUartSend( mico_uart_t uart, const void* data, uint32_t size )
{
/* Reset DMA transmission result. The result is assigned in interrupt handler */
uart_interfaces[uart].tx_dma_result = kGeneralErr;
MicoMcuPowerSaveConfig(false);
uart_mapping[uart].tx_dma_stream->CR &= ~(uint32_t) DMA_SxCR_CIRC;
uart_mapping[uart].tx_dma_stream->NDTR = size;
uart_mapping[uart].tx_dma_stream->M0AR = (uint32_t)data;
USART_DMACmd( uart_mapping[uart].usart, USART_DMAReq_Tx, ENABLE );
USART_ClearFlag( uart_mapping[uart].usart, USART_FLAG_TC );
DMA_Cmd( uart_mapping[uart].tx_dma_stream, ENABLE );
#ifndef NO_MICO_RTOS
mico_rtos_get_semaphore( &uart_interfaces[ uart ].tx_complete, MICO_NEVER_TIMEOUT );
#else
while(uart_interfaces[ uart ].tx_complete == false);
uart_interfaces[ uart ].tx_complete = false;
#endif
while ( ( uart_mapping[ uart ].usart->SR & USART_SR_TC ) == 0 )
{
}
DMA_Cmd( uart_mapping[uart].tx_dma_stream, DISABLE );
USART_DMACmd( uart_mapping[uart].usart, USART_DMAReq_Tx, DISABLE );
MicoMcuPowerSaveConfig(true);
return uart_interfaces[uart].tx_dma_result;
//#endif
}
示例2: DMA_Configuration
void DMA_Configuration(void)
{
DMA_DeInit(DMA1_Channel6);
/* Enable the USART Rx DMA request */
USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // Receive //DMA_DIR_PeripheralDST
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)read_parameters_android;
DMA_InitStructure.DMA_BufferSize = sizeof(read_parameters_android);
DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t) &(USART2->RDR);
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_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel6, &DMA_InitStructure);
USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);
DMA_ITConfig(DMA1_Channel6, DMA_IT_TC, ENABLE);
DMA_ITConfig(DMA1_Channel6, DMA_IT_HT, ENABLE);
DMA_Cmd(DMA1_Channel6, ENABLE);
}
示例3: DMA_USART_ReInit
void DMA_USART_ReInit()
{
DMA_Cmd(DMA1_Stream6, DISABLE);
USART_DMACmd(USART2,USART_DMAReq_Tx,DISABLE);
DMA_Init(DMA1_Stream6, &DMA_InitStructure);
USART_DMACmd(USART2,USART_DMAReq_Tx,ENABLE);
DMA_Cmd(DMA1_Stream6, ENABLE);
}
示例4: pingpong_usart1_rx_dma_int
void pingpong_usart1_rx_dma_int(void)
{
if(!dma1_ch5_mode_is_circular())
{
USART_DMACmd(USART1, USART_DMAReq_Rx, DISABLE);
DMA_Cmd(DMA1_Channel5, DISABLE);
}
#if DMA_Circular
if(PINGPONG_BUF_NO0 == PingPongBuf_Free_No)
{
DMA1_Channel5->CMAR = (unsigned int)&pingpongbuf[0]; // DMA_MemoryBaseAddr;
PingPongBuf_Free_No = PINGPONG_BUF_NO1;
//usart1_dma_write(pingpongbuf[1], PINGPONG_BUFSIZE, usart1_dma_tx_done_callback);
}
else
{
DMA1_Channel5->CMAR = (unsigned int)pingpongbuf[1]; // DMA_MemoryBaseAddr;
PingPongBuf_Free_No = PINGPONG_BUF_NO0;
//usart1_dma_write(pingpongbuf[1], PINGPONG_BUFSIZE, usart1_dma_tx_done_callback);
}
PINGPONG_BUF_OK = TRUE;
#else // DMA Mode Normal
if(PINGPONG_BUF_NO0 == PingPongBuf_Free_No)
{
PingPongBuf_Free_No = PINGPONG_BUF_NO1;
//usart1_dma_write(pingpongbuf[1], PINGPONG_BUFSIZE, usart1_dma_tx_done_callback);
#if 1
DMA1_Channel5->CMAR = (unsigned int)pingpongbuf[0]; // DMA_MemoryBaseAddr;
DMA1_Channel5->CNDTR = PINGPONG_BUFSIZE; // DMA_BufferSize;
DMA_Cmd(DMA1_Channel5, ENABLE);
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
#else
dma1_ch5_peri2mem_start((unsigned char *)(&USART1->DR), pingpongbuf[0], PINGPONG_BUFSIZE);
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
#endif
}
else
{
PingPongBuf_Free_No = PINGPONG_BUF_NO0;
//usart1_dma_write(pingpongbuf[0], PINGPONG_BUFSIZE, usart1_dma_tx_done_callback);
#if 1
DMA1_Channel5->CMAR = (unsigned int)pingpongbuf[1]; // DMA_MemoryBaseAddr;
DMA1_Channel5->CNDTR = PINGPONG_BUFSIZE; // DMA_BufferSize;
DMA_Cmd(DMA1_Channel5, ENABLE);
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
#else
dma1_ch5_peri2mem_start((unsigned char *)(&USART1->DR), pingpongbuf[1], PINGPONG_BUFSIZE);
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
#endif
}
PINGPONG_BUF_OK = TRUE;
#endif
}
示例5: uart_Init
static int uart_Init(const uart_cfg_t *cfg)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef uartinfo;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
#ifdef CONFIG_STM32F10X_CL
/*configure PD5<uart2.tx>, PD6<uart2.rx>*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
#else
/*configure PA2<uart2.tx>, PA3<uart2.rx>*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
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_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
#endif
/*init serial port*/
USART_StructInit(&uartinfo);
uartinfo.USART_BaudRate = cfg->baud;
USART_Init(uart, &uartinfo);
#ifdef ENABLE_TX_DMA
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
uart_SetupTxDMA(uart_fifo_tx, 0);
USART_DMACmd(uart, USART_DMAReq_Tx, ENABLE);
uart_fifo_tn = 0;
uart_fifo_tp = 0;
#endif
#ifdef ENABLE_RX_DMA
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
uart_SetupRxDMA(uart_fifo_rx, RX_FIFO_SZ);
USART_DMACmd(uart, USART_DMAReq_Rx, ENABLE);
uart_fifo_rn = 0;
#endif
USART_Cmd(uart, ENABLE);
return 0;
}
示例6: USART_DMA_Config
void USART_DMA_Config(void)
{
/* USART configuration -----------------------------------------------------*/
USART_Config();
/******************************************************************
DMA TX
*******************************************************************/
/* Prepare the DMA to transfer the transaction command (2bytes) from the
memory to the USART */
DMA_DeInit(USARTx_TX_DMA_STREAM);
DMA_InitStructure.DMA_Channel = USARTx_TX_DMA_CHANNEL;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)TxBuffer_dma;
DMA_InitStructure.DMA_BufferSize = (uint16_t)24;
DMA_Init(USARTx_TX_DMA_STREAM, &DMA_InitStructure);
DMA_ITConfig(USARTx_TX_DMA_STREAM, DMA_IT_TC , ENABLE);
/* Enable the USART DMA requests */
USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE);
/* Clear the TC bit in the SR register by writing 0 to it */
USART_ClearFlag(USARTx, USART_FLAG_TC);
/******************************************************************
DMA RX
*******************************************************************/
#if 1
DMA_DeInit(USARTx_RX_DMA_STREAM);
DMA_InitStructure.DMA_Channel = USARTx_RX_DMA_CHANNEL;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)RxBuffer_dma;
DMA_InitStructure.DMA_BufferSize = (uint16_t)24;
DMA_Init(USARTx_RX_DMA_STREAM, &DMA_InitStructure);
/****** DMA ÖжÏÅäÖà ************************/
DMA_ITConfig(USARTx_RX_DMA_STREAM, DMA_IT_TC , ENABLE);
/* Enable the USART Rx DMA request */
USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE);
/* Enable the DMA RX Stream*/
DMA_Cmd(USARTx_RX_DMA_STREAM, ENABLE);
#endif
}
示例7: USART_DMACmd
void CmdUnit_t::IStartTx(void) {
IDmaIsIdle = false;
// Start DMA
USART_DMACmd(USART1, USART_DMAReq_Tx, DISABLE);
DMA_Cmd(UART_DMA_CHNL, DISABLE);
UART_DMA_CHNL->CMAR = (uint32_t) PBuf; // Set memory base address
UART_DMA_CHNL->CNDTR = TxIndx; // Set count to transmit
DMA_Cmd(UART_DMA_CHNL, ENABLE);
USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
// Switch to next buf
PBuf = (PBuf == TXBuf1)? TXBuf2 : TXBuf1;
TxIndx = 0;
}
示例8: platform_uart_transmit_bytes
OSStatus platform_uart_transmit_bytes( platform_uart_driver_t* driver, const uint8_t* data_out, uint32_t size )
{
OSStatus err = kNoErr;
platform_mcu_powersave_disable();
#ifndef NO_MICO_RTOS
mico_rtos_lock_mutex( &driver->tx_mutex );
#endif
require_action_quiet( ( driver != NULL ) && ( data_out != NULL ) && ( size != 0 ), exit, err = kParamErr);
/* Clear interrupt status before enabling DMA otherwise error occurs immediately */
clear_dma_interrupts( driver->peripheral->tx_dma_config.stream, driver->peripheral->tx_dma_config.complete_flags | driver->peripheral->tx_dma_config.error_flags );
/* Init DMA parameters and variables */
driver->last_transmit_result = kGeneralErr;
driver->tx_size = size;
driver->peripheral->tx_dma_config.stream->CR &= ~(uint32_t) DMA_SxCR_CIRC;
driver->peripheral->tx_dma_config.stream->NDTR = size;
driver->peripheral->tx_dma_config.stream->M0AR = (uint32_t)data_out;
USART_DMACmd( driver->peripheral->port, USART_DMAReq_Tx, ENABLE );
USART_ClearFlag( driver->peripheral->port, USART_FLAG_TC );
driver->peripheral->tx_dma_config.stream->CR |= DMA_SxCR_EN;
/* Wait for transmission complete */
#ifndef NO_MICO_RTOS
mico_rtos_get_semaphore( &driver->tx_complete, MICO_NEVER_TIMEOUT );
#else
while( driver->tx_complete == false );
driver->tx_complete = false;
#endif
while ( ( driver->peripheral->port->SR & USART_SR_TC ) == 0 )
{
}
/* Disable DMA and clean up */
USART_DMACmd( driver->peripheral->port, USART_DMAReq_Tx, DISABLE );
driver->tx_size = 0;
err = driver->last_transmit_result;
exit:
#ifndef NO_MICO_RTOS
mico_rtos_unlock_mutex( &driver->tx_mutex );
#endif
platform_mcu_powersave_enable();
return err;
}
示例9: DMA_Configuration
//DMA配置:
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* DMA clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);//DMA1
/* DMA1 Channel7 (triggered by USART2 Tx event) Config */
DMA_DeInit(DMA1_Channel7);
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40004404;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)USART2_SEND_DATA;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 512;
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_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel7, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel7, DMA_IT_TC, ENABLE);
DMA_ITConfig(DMA1_Channel7, DMA_IT_TE, ENABLE);
/* Enable USART2 DMA TX request */
USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
DMA_Cmd(DMA1_Channel7, DISABLE);
/* DMA1 Channel6 (triggered by USART1 Rx event) Config */
DMA_DeInit(DMA1_Channel6);
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40004404;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)USART2_RECEIVE_DATA;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 512;
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_Medium;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel6, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel6, DMA_IT_TC, ENABLE);
DMA_ITConfig(DMA1_Channel6, DMA_IT_TE, ENABLE);
/* Enable USART2 DMA RX request */
USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);
DMA_Cmd(DMA1_Channel6, ENABLE);
}
示例10: UART_DMA_Rx_Enable
void UART_DMA_Rx_Enable(void)
{
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
DMA_Cmd(DMA1_Channel5, DISABLE );
DMA_SetCurrDataCounter(DMA1_Channel5,UART_RX_BUFFER_SIZE);
DMA_Cmd(DMA1_Channel5, ENABLE);
}
示例11: RCC_AHBPeriphClockCmd
void Usart::enableDmaRead()
{
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_DeInit(theConfig.DMA_Channel);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) & (USARTx->DR);
DMA_InitStructure.DMA_MemoryBaseAddr =(u32)USART_defaultBuf;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = DMA_BUFSIZE;
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_Medium;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(theConfig.DMA_Channel, &DMA_InitStructure);
DMA_ITConfig(theConfig.DMA_Channel,DMA_IT_TC,ENABLE );
USART_DMACmd(USARTx,USART_DMAReq_Rx,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = theConfig.DMA_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA_Cmd(theConfig.DMA_Channel,ENABLE);
}
示例12: ZPH01_USART_Configuration
//串口配置
void ZPH01_USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate=9600; //波特率设置
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_Rx|USART_Mode_Tx; //收发模式
USART_Init(USART1,&USART_InitStructure); //初始化配置
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //使能串口中断
USART_Cmd(USART1,ENABLE); //使能串口
USART_ClearFlag(USART1,USART_FLAG_TC); //清除发送完成标志
USART_InitStructure.USART_BaudRate=9600; //波特率设置
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_Rx|USART_Mode_Tx; //收发模式
USART_Init(USART2,&USART_InitStructure); //初始化配置
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE); //使能串口接收中断
//USART_ITConfig(USART2, USART_IT_IDLE,DISABLE); //先失能串口空闲中断
USART_Cmd(USART2,ENABLE); //使能串口
USART_ClearFlag(USART2,USART_FLAG_TC); //清除发送完成标志
/* Enable or Disable USART DMA RX request */
USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);
}
示例13: DMA_usart3_Configuration
void DMA_usart3_Configuration(void)
{
DMA_InitTypeDef DMA_TX_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
DMA_DeInit(DMA1_Stream3);
DMA_TX_InitStructure.DMA_Channel = DMA_Channel_4;
DMA_TX_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; // Transmit
DMA_TX_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&(USART3->DR));
DMA_TX_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_TX_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_TX_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_TX_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_TX_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_TX_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_TX_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_TX_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_TX_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_TX_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream3, &DMA_TX_InitStructure);
USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
DMA_ITConfig(DMA1_Stream3, DMA_IT_TC, ENABLE);
DMA_Cmd(DMA1_Stream3, ENABLE);
}
示例14: send_data_to_WBTDS01
/**
* @brief 发数据给蓝牙模块
* @param[in] unsigned char *pData 要发送的数据
* @param[in] int length 要发送数据的长度
*/
static void send_data_to_WBTDS01(const unsigned char *pData, unsigned short length)
{
//while(length--)
//{
// USART_SendData(USART2, *pData++);
// while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
// {
// }
//}
//while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET){};
/* disable DMA */
DMA_Cmd(DMA1_Channel7, DISABLE);
/* set buffer address */
memcpy(wbtd_send_buff,pData,length);
DMA1_Channel7->CMAR = (u32)&wbtd_send_buff[0];
/* set size */
DMA1_Channel7->CNDTR = length;
USART_DMACmd(USART2, USART_DMAReq_Tx , ENABLE);
/* enable DMA */
DMA_Cmd(DMA1_Channel7, ENABLE);
while(DMA1_Channel7->CNDTR);
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET){};
}
示例15: USART1_Config
/**
* @brief USART1 GPIO 配置,工作模式配置。115200 8-N-1
* @param 无
* @retval 无
*/
void USART1_Config(uint32_t BaudRate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* USART1 GPIO config */
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USART1 mode config */
USART_InitStructure.USART_BaudRate = BaudRate;
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_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
/* 使能串口2接收中断 */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ClearFlag(USART1,USART_FLAG_TC);//先清除一下发送中断标志位,会解决第一个字节丢失的问题。
USART_Cmd(USART1, ENABLE);
USART1_NVIC_Configuration(ENABLE);
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);
}