cancel
Showing results for 
Search instead for 
Did you mean: 

USART1 trnsmission problem

madhu13
Associate III
Posted on August 20, 2010 at 09:20

USART1 trnsmission problem

8 REPLIES 8
Posted on May 17, 2011 at 14:03

You are not enabling the GPIOA unit or the pins correctly, and as you are not setting up the AHB/APB clocks from their defaults, the baud rate is going to be wrong (ie not 9600)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
madhu13
Associate III
Posted on May 17, 2011 at 14:03

i hope the peripheral clock is 8MHz by default now i calculated value to be written in BRR reg for 8MHz now my code is working fine and the present code is as follows... is it the right configuration?????????

main()

{

 RCC_Config();

 GPIO_Config();

 USART1->BRR=0x341;

 USART1->CR1=0x0000004D;   //TCIE(transmit complete interrupt enable)

 USART1->CR2=0x800;    //eable clock

 USART1->CR1|=0x2000;

 NVIC->ISER[1] = 0x25;//USART1_IRQChannel //(1 << (USART1_IRQChannel & 0x1F));//0x00000020;

 USART1->CR1|=0x00002000;

 USART1->DR='1';

 ch='A';

 while(1)

 { 

  if (temp==1)

  {

   temp=0;

   USART1->DR=ch; 

  }

 }

 }

void RCC_Config(void)

{

  RCC->APB2ENR=0x00004000;

}

void GPIO_Config(void)

{

   AFIO->MAPR=0x00000000;

   GPIOA->CRH=0x00000490;  

}

     

void USART1_IRQHandler(void)

{

 if ((USART1->SR & USART_FLAG_TC))

 {

  temp=1;

  USART1->SR&=0XFFBF; 

 }     

} Regards

Madhuri

Andrew Neil
Evangelist III
Posted on May 17, 2011 at 14:03

''i hope the peripheral clock is 8MHz...''

 

Hope is not a good basis for software development!

You need to confirm this for sure by studying the Datasheet, User Manuals, etc...

madhu13
Associate III
Posted on May 17, 2011 at 14:03

sorry for using the word hope...i no if we are not configuring PLL then by default the peripheral clock will be at 8MHz only...am I right...???

Madhuri...

Posted on May 17, 2011 at 14:03

At reset clocks are at 8 MHz, 9600 baud divider is 833 (0x341) correct.

Need to enable clocks on GPIO(A). Should leave other GPIO bits as input/default, and set PA.9 to fast edge AF.

Generally you should write all bit (know what they do) or mask in the bits you actually want to use against the current contents.

Changing the AFIO mapping seems overkill, if you do it you must enable the AFIO clock.

 

void RCC_Config(void)

{

  RCC->APB2ENR |=0x00004004; // USART1 and GPIOA

}

void GPIO_Config(void)

{

   AFIO->MAPR=0x00000000; // Need AFIO clock enabled for this to work

   GPIOA->CRH =(GPIOA->CRH & 0xFFFFF00F) | 0x000004B0;  

}
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
madhu13
Associate III
Posted on May 17, 2011 at 14:03

Ok i will do that thank you for the suggession....and can you giude me in configuring PLL..i read the manual but i amlittle confused to start configuration and selecting the HSE,HSI and PLL's please help

Thanks and Regards

Madhuri

Posted on May 17, 2011 at 14:03

Is there a reason you cannot use the ST firmware library, and supplied examples?

With the HSE you need to ensure it is enabled, and then up and running before selecting it. Similarly with the PLL you must pick the correct source, multipliers and dividers to get the clock rate you want, you must wait for the PLL to attain lock before switching to it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
madhu13
Associate III
Posted on May 17, 2011 at 14:03

i have all the examples but right now i dont have the hardware and also i just want to write simple codes and test in Keil IDE and run them in Evaluation mode...with code size limit 32K. I tried to run the examples but it gives a pop up message ''No ULINK Device Found'' and also ''Error:Torget DLL has been canceled. Debugger aborted!''.