cancel
Showing results for 
Search instead for 
Did you mean: 

Uart application

ezrab
Associate II
Posted on October 06, 2010 at 15:35

hi

i was tring to activate USART3 On Port C PC10,PC11.

 

i used this configuration :

USART3->CR1 = 0x0C; //Receiver enable, Transmitter enable, USART disable

    USART3->CR2 = 0x0;

    USART3->BRR=156;//9600 at 24Mhz

   setsystemclock(); //set system clock to 24Mhz

 

    AFIO->MAPR|=0x10;//port remap as uart //PC10 TX PC11 RX

    GPIOC->CRH=0x4B00; //PC11 in input floating mode for RX. PC10 Alternative Output TX.

    RCC->APB2ENR |=0x40000;

 USART3->CR1 |=2000; //Uart Enable;

  while(1)

  {

   while(TxCounter < 30)

  {

    /* Send one byte from USARTy to USARTz */

      USART3->DR =( TxBuffer[TxCounter] & (uint16_t)0x01FF);

      while(((USART3->SR)&0x40)>0);//wait transmition complete

    TxCounter++;

    /* Loop until USARTy DR register is empty */

  }

  TxCounter=0;

  //GPIOC->ODR=0x3ffff;

  //GPIOC->ODR=0x0;

  }

but for some reason  it does not work??

can you help?

thanks.
15 REPLIES 15
Posted on October 10, 2010 at 15:37

i determine the value without assuming the inital value.right?

 

Correct, but now imagine you don't have a monolithic application, but one where different routines initialize different pieces of hardware and don't make assumptions about what other hardware has already been enabled, but simply enable the hardware they need. For example USART1 and GPIOA.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ezrab
Associate II
Posted on October 11, 2010 at 09:06

hi.

thanks for all your help.

i have another question.

how did you get to the number 0x9c4?

what is the math behind it?

thanks.

Posted on October 11, 2010 at 16:46

how did you get to the number 0x9c4?

24,000,000 / 9,600 = 2,500 = 0x9C4

This uses the fact that while the USART is using a 1/16th clock it also represents the baud rate divider with a 4-bit fixed point fractional component.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stephenflowers9
Associate
Posted on October 22, 2010 at 10:08

I also had problems getting USART2 working.  I followed the guidance on this thread and solved the problem but cant help feel I am missing some documentation where it implicitly says to enable the clocks first? I`m new to ARM processors but not to programming

joa
Associate II
Posted on October 22, 2010 at 10:36

From ''RM0041 Reference Manual'' for stm32f100xx, last paragraph in section 2.1:

After each device reset, all peripheral clocks are disabled (except for the SRAM and FLITF).

 

Before using a peripheral you have to enable its clock in the RCC_AHBENR,

 

RCC_APB2ENR or RCC_APB1ENR register.

 

Posted on October 22, 2010 at 14:47

I also had problems getting USART2 working.  I followed the guidance on this thread and solved the problem but cant help feel I am missing some documentation where it implicitly says to enable the clocks first? I`m new to ARM processors but not to programming

 

It is a synchronous part, unless the parts are clocked they are non-functional and non-responsive. CMOS parts draw the majority of their current when signals transition, if you turn off clocks it will consume less power, unused peripherals are turned off to save power.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..