c - STM32F303 USART Configuration -


i pretty new in arm , try configure uart. board use stm32f3 discovery. @ moment try tx signal on pa9 usart1, interrupt routine rx not written yet. in opinion should see signal on pa9 when use oscilloscope, pin has constant 3v pull-up. used reference manual configuration , initialized registers described. see mistake? code far:

/*----------------------------------------------------------------------------  * cmsis-rtos 'main' function template  *---------------------------------------------------------------------------*/  #define osobjectspublic                     // define objects in main module #include "osobjects.h"                      // rtos object definitions #include "stm32f3xx.h"                  // device header  /*  * defines  */  #define sys_frequency 8000000l //8mhz   /*   * global variables     */   long baudrate=9600;   //----------------------------------------------------------------------------------------------------  void initgpio() {               // initialize peripherals here         //activate red led port         rcc->ahbenr |= rcc_ahbenr_gpioeen;              //enable porte clock         gpioe->moder |= gpio_moder_moder9_0;            //porte9 (led red) output  }   void initusart(long baudrate) {      long baudratio=sys_frequency/baudrate;       //clock      rcc->ahbenr |= rcc_ahbenr_gpioaen;             //enable porta clock      rcc->apb2enr |= rcc_apb2enr_usart1en | rcc_apb2enr_syscfgen;       //enable usart1 clock       //af      gpioa->afr[1] = 0;      gpioa->afr[0] = gpio_afrl_afrl7 & (7u<<8);     //af7 configuration       //tx (pa9)      gpioa->moder |= gpio_moder_moder9_1 ;                                                                      //alternating function, tx (pa9)      gpioa->otyper = 0;                                                                                                             //push-pull      gpioa->ospeedr |= gpio_ospeeder_ospeedr9_0 | gpio_ospeeder_ospeedr9_1;     //fast speed      gpioa->pupdr |= gpio_pupdr_pupdr9_0;                                                                           //pull-up       //rx (pa)      gpioa->ospeedr |= gpio_ospeeder_ospeedr10_0 | gpio_ospeeder_ospeedr10_1; //fast speed       //usart      usart1->cr1 =0;                                                                                                                                        //reset      usart1->cr2 =0;                                                                                                                                        //reset      usart1->cr3 =0;                                                                                                                                        //reset      usart1->brr = baudratio & 0xffff;                                                                                                  //set baudrate 9600      usart1->cr1 |= (usart_cr1_te |usart_cr1_txeie | usart_cr1_rxneie| usart_cr1_re);       //tx, rx enable, interrupts enable      usart1->cr1 |=  usart_cr1_ue;                                                                                                          //enable usart  }   void sendchar(char c) {          while(usart_isr_txe==1);                           //data transfered shift register          usart1->tdr = (c & 0xff);          gpioe->bsrrl = gpio_bsrr_bs_9;      //led on -> bsrrl bit set reset register -> write 1 -> high      osdelay(50);                                 gpioe->bsrrh =  gpio_bsrr_bs_9 ;    //led off      osdelay(50);  }   void sendxthread(void const *argument) {      while(1) {         osdelay(150);         sendchar('x');      }  }   osthreaddef(sendxthread,osprioritynormal,1,0);   //----------------------------------------------------------------------------------------------------  int main (void) {   oskernelinitialize ();                    // initialize cmsis-rtos      //----------------------------------------------------------------------------------------------------     initgpio();     initusart(baudrate);     //----------------------------------------------------------------------------------------------------     // create 'thread' functions start executing,   // example: tid_name = osthreadcreate (osthread(name), null);     osthreadcreate(osthread (sendxthread),null);   oskernelstart ();                         // start thread execution  } 


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -