I'm Trying to enable DMA1 with USART1 in stm32f103c8 but it does not work . i enabled the usart to work as transmitter . and then enabled the DMA1 and make this configuration to it 1-enable the DMA1 clock from RCC. 2-disabled the DMA1 Channel . 3-set the DMA1 channel periority as very high periority. 4-make the direction of DMA1 channel from memory to peripheral. 5-make the memory size and peripheral size as byte. 6-enable memory increment and disable peripheral increment. 7-disable circular mode. 8-set the DMA interrupt for transfer complete. 7-set the memory address buffer and set the peripheral address as usart1 data register. 8-set the number of times to dma transfer as 6 . 9-enable the DMA1 channel interrupt in the NVIC. 10-enable the DMAT in the usart1 to make the usart work with the DMA1 11-enable the DMA1 to Start work.
after all this configuration the DMA does not work but the usart work successfully . in the main code i make intialize the usart1 and then intialize the DMA1 as me said up and then empty while(1) . the terminal did not receive the string in the memory and the DMA did not go to the handler that mean the DMA does not work never why ?
u8 Buffer[6] = "hesham";
int main(void){
/*--------------------------------------------------------------------------------------------*/
RCC_VidInit();
RCC_VidEnablePeripheralClock( APB2_BUS , IOPA_EN ); //Enable PORTA Clock
RCC_VidEnablePeripheralClock( APB2_BUS , USART1_EN ); //Enable USART1 Clock
RCC_VidEnablePeripheralClock( AHB_BUS , DMA1_EN ); //Enable DMA1 Clock
/*--------------------------------------------------------------------------------------------*/
NVIC_VidEnableIRQ( 14 ); //Enable The DMA1Channel4 Interrupt Inside The NVIC
/*-------------------------------GPIO Configuration Of Tx And Rx------------------------------*/
CLR_BIT( GPIOA->CRH , 4 ); SET_BIT( GPIOA->CRH , 5 ); //PIN9 (TX) Output With 2MHZ Speed
CLR_BIT( GPIOA->CRH , 6 ); SET_BIT( GPIOA->CRH , 7 ); //Make Pin9 Alternative Func PushPull
CLR_BIT( GPIOA->CRH , 8 ); CLR_BIT( GPIOA->CRH , 9 ); //Pin10 (RX) Input
SET_BIT( GPIOA->CRH , 10 ); CLR_BIT( GPIOA->CRH , 11 ); //Make Pin10 Floating Input
/*-----------------------------------------------USART1 Configuration--------- ---------------*/
//Using The Deafult M Size = 8 bit And 1 Stop bit
USART1->BRR = 0x341 ; //Set The BaudRate = 9600 Of External Oscillator = 8MHZ
SET_BIT( USART1->CR3 , 7 ); //Enable Usart To Work With DMA As Transmitter (DMAT bit)
SET_BIT( USART1->CR1 , 3 ); SET_BIT( USART1->CR1 , 13 ); //Enable The Transmitter (TE Bit) and Enable The USART (UE bit)
/*-----------------------------------------------DMA1 Channel 4 Configuration-----------------*/
CLR_BIT( DMA1_CHANNEL4->CCR , 0 ); //Disable The DMA To Access The Registers
SET_BIT( DMA1_CHANNEL4->CCR , 1 ); //Enable The Trnasmit Complete Interrupt (TCIE)
SET_BIT( DMA1_CHANNEL4->CCR , 4 ); //DMA Direction Is From Memory To Peripheral
CLR_BIT( DMA1_CHANNEL4->CCR , 5 ); //Disable Circular
CLR_BIT( DMA1_CHANNEL4->CCR , 6 ); //Disable Peripheral Increment
SET_BIT( DMA1_CHANNEL4->CCR , 7 ); //Enable Memory Increment
CLR_BIT( DMA1_CHANNEL4->CCR , 8 ); CLR_BIT( DMA1_CHANNEL4->CCR , 9 ); //Peripheral Size = BYTE
CLR_BIT( DMA1_CHANNEL4->CCR , 10 ); CLR_BIT( DMA1_CHANNEL4->CCR , 11 ); //Memory Size = BYTE
SET_BIT( DMA1_CHANNEL4->CCR , 12 ); SET_BIT( DMA1_CHANNEL4->CCR , 13 ); //Channel Priority = Very High
CLR_BIT( DMA1_CHANNEL4->CCR , 14 ); //Disable Memory To Memory Mode
DMA1_CHANNEL4->CPAR = (u32)USART1->DR ; //The Address Of Peripheral is Usart Data Reg
DMA1_CHANNEL4->CMAR = Buffer ; //The Address Of Memory is Buffer
DMA1_CHANNEL4->CNDTR = 6 ; //The Number Of Transfer Item Is = The Size Of Buffer = 6
//Clear The DMA1 Flags Of Channel 4
SET_BIT( DMA1->IFCR , 12 );SET_BIT( DMA1->IFCR , 13 );SET_BIT( DMA1->IFCR , 14 );SET_BIT( DMA1->IFCR , 15 );
SET_BIT( DMA1_CHANNEL4->CCR , 0 ); //Enable The DMA To Work
/*--------------------------------------------------------------------------------------------*/
while(1);
return 0;
}
and this is the handler of the DMA
void DMA1_Channel4_IRQHandler(void){
if( (GET_BIT( DMA1->ISR , 13 )) == 1 ){ //Checking About Transfer Complete Flag Of DMA
//Clear The DMA1 Flags Of Channel 4
SET_BIT( DMA1->IFCR , 12 );SET_BIT( DMA1->IFCR , 13 );SET_BIT( DMA1->IFCR , 14 );SET_BIT( DMA1->IFCR , 15 );
}
}
can someone help me please ?