I need to use stm uart module

0

I would like to use usart communication on STM by using following code. I take this code from website.There are two buffers that stores rx and tx values. I can transmit data from tx buffer but when I connect GPIOB10 and GPIOB11(rx and tx pins) each other. I couldn't see datas that I am sending from tx buffer in rx buffer. Can you show me what am I doing wrong?

#include "stm32f4xx.h"

char RxBuf[128];     
char TxBuf[128];     
int cntr=0;          
unsigned char WAdr,RAdr; 

void SystemInitt(){
unsigned int i;
      for (i=0;i<0x00100000;i++);       
      RCC->CFGR |= 0x00009400;         
      RCC->CR |= 0x00010000;             
      while (!(RCC->CR & 0x00020000)); 
      RCC->PLLCFGR = 0x07402A04;      
      RCC->CR |= 0x01000000;             
      while(!(RCC->CR & 0x02000000));  
      FLASH->ACR = 0x00000605;         
      RCC->CFGR |= 0x00000002;          
      while ((RCC->CFGR & 0x0000000F) != 0x0000000A);
      RCC->AHB1ENR |= 0x0000001F;     
      GPIOD->MODER  = 0x55550000;     
      GPIOD->OSPEEDR= 0xFFFFFFFF;    
}

void USART3_IRQHandler(){
volatile int Sts;
     Sts=USART3->SR;
     RxBuf[WAdr]=USART3->DR;
     WAdr=(WAdr+1)&0x7F;
     cntr++;
}

void UsartInit()
{
     WAdr=0;RAdr=0;

      RCC->APB1ENR|=0x00040000;    
      RCC->APB1RSTR|=0x00040000;  
      GPIOB->AFR[1]=0x07777700;     
      GPIOB->MODER|=0x2AA00000;    

      RCC->APB1RSTR&=~0x00040000; 
      USART3->BRR=0x1112;               
      USART3->CR1|=0x0000202C;              
      USART3->CR3|=0x80;                
      NVIC->ISER[1]|=0x80;              
}


int main()
{
      volatile int i;
      UsartInit();
      RCC->AHB1ENR |= 0x00200000;        
      RCC->AHB1RSTR|= 0x00200000;        
      for(i=0;i<0x1FF;i++);
      RCC->AHB1RSTR&=~0x00200000;        
      DMA1_Stream4->M0AR=(int)&TxBuf[0]; 
      DMA1_Stream4->PAR=(int)&USART3->DR;
      DMA1_Stream4->FCR&=~0xFFFFFF40;
      DMA1_Stream4->CR=(DMA1_Stream4->CR & 0xF0100000)| 0x0E000440;

      for(i=0;i<128;i++) TxBuf[i]=i+1;  
      DMA1_Stream4->NDTR=50;             
      USART3->SR&=~0x40;                 
      DMA1_Stream4->CR|=1;                

      while(1);
}
c
uart
stm32f4discovery
asked on Stack Overflow Apr 25, 2019 by FurkanAltay

1 Answer

0

Thanks your advice but I didnt use cube mx . I have use direct register access method

answered on Stack Overflow Apr 26, 2019 by FurkanAltay

User contributions licensed under CC BY-SA 3.0