看了好多遍,感觉没啥问题啊
void USART1_CFG(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* USART2 TX-->A.2 RX-->A.3 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
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_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 250000;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
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 ; //DMX512这里只发送数据
USART_Init(USART1, &USART_InitStructure);
// USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// DMA_Cmd(DMA1_Channel4, ENABLE); /* USART1 Tx */
// DMA_Cmd(DMA1_Channel5, ENABLE); /* USART1 Rx */
USART_Cmd(USART2, ENABLE);
}
/*******************************************************************************
* Function Name : DMA_INIT
* Description : Configures the DMA for USART1.
* Input : None
* Return : None
*******************************************************************************/
void DMA_INIT(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_DeInit(DMA1_Channel4);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&USART1->DATAR); /* USART2->DATAR:0x40004404 */
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)Tx_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = DMX_CHN;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel4, &DMA_InitStructure);
// DMA_DeInit(DMA1_Channel5);
// DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&USART2->DATAR);
// DMA_InitStructure.DMA_MemoryBaseAddr = (u32)RxBuffer1;
// DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
// DMA_InitStructure.DMA_BufferSize = TxSize2;
// DMA_Init(DMA1_Channel5, &DMA_InitStructure);
}
void DMX_Init() //初始化 主函数调用
{
USART1_CFG();
DMA_INIT();
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);//|USART_DMAReq_Rx
}
static void USART_Send9Data(void)
{
uint16_t tmp;
DMA_Cmd(DMA1_Channel4, DISABLE); /* USART1 Tx */
for(tmp=0;tmp
{
Tx_Buffer[tmp] = (uint16_t)DMX_SendData[tmp]+0x0100; //数据第9位为高
}
DMA_Cmd(DMA1_Channel4, ENABLE); /* USART1 Tx */
}