cancel
Showing results for 
Search instead for 
Did you mean: 

PROBLEM WITH STM32F103RB USART2

bluewaters213
Associate III
Posted on February 15, 2013 at 22:22

Hello,

I can't seems to get USART2 to work.There is nothing in TX (PA2) & RX(PA3) Pin when view with a logic analyzer.I think I am missing something in my code..I need help.

#include ''stm32f10x.h''

#include <stdio.h>

void Init_SysClock(void);

void Init_RCC(void);

void Init_USART(void);

void USART_PutChar(uint8_t ch);

void USART_PutString(uint8_t * str);

uint8_t text [] = ''STM32VLDISCOVERY tutorial\n\rhttp://en.radzio.dxp.pl/stm32vldiscovery/\n\r\n\r'';

int main(void)

{

  vu32 dly;

  Init_SysClock();              //Initialize GPIO & Peripherals Clocks

  Init_RCC();                   //Initialize GPIO

  Init_USART();

  while(1)

    {

    USART_PutString(text);

    for(dly = 0; dly < 1000000; dly++);

    }

}

void USART_PutChar(uint8_t ch)

{

while(!(USART2->SR & USART_SR_TXE));

USART2->DR = ch;

}

void USART_PutString(uint8_t * str)

{

while(*str != 0)

{

USART_PutChar(*str);

str++;

}

}

//USART2_TX=> PA2 | USART2_RX=> PA3

void Init_USART(void)

{

  //Enable USART, TX & RX

  USART2->CR1 |= USART_CR1_UE | USART_CR1_TE | USART_CR1_RE;

  USART2->BRR = (PCLK / 9600);  //Baud Rate = 9600kps

}

void Init_SysClock(void)

{

  /*Enable Alternate Function,GPIOA,GPIOB,GPIOC, GPIOD & TIMER1, ADC1 & ADC2 Clock Clock*/

  RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |

                  RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN | RCC_APB2ENR_TIM1EN |

                  RCC_APB2ENR_ADC1EN | RCC_APB2ENR_ADC2EN;

  /*Enable TIMER2, TIMER3,I2C1  & USART2 Clock*/

  RCC->APB1ENR |= RCC_APB1ENR_TIM2EN | RCC_APB1ENR_TIM3EN |RCC_APB1ENR_I2C1EN |

                  RCC_APB1ENR_TIM4EN | RCC_APB1ENR_USART2EN;

  RCC->AHBENR = RCC_AHBENR_DMA1EN ;   //DMA1 clock enable

}

void Init_RCC(void)

{

//PARTIAL REMAP TIM1=>CH1/PA8,CH2/PA9,CH3/PA10,CH4/PA11,CH1N/PA7,CH2N/PB0,CH3N/PB1

    AFIO->MAPR |= AFIO_MAPR_TIM1_REMAP_PARTIALREMAP | AFIO_MAPR_TIM2_REMAP |

                  AFIO_MAPR_USART1_REMAP ;   //REMAP USART1=>TX/PB6,RXPB7

   //PA2, PA7 Alternate Function Push Pull Output | PA0, PA3 Input Floating

    GPIOA->CRL = 0xA4444B44;

    GPIOA->CRH = 0x4444AAAA;  //PA8 - PA11 Alternate Function Push Pull Output

    //PB0 & PB1 =>Alt Function Push Pull O/P | PB6-PB7 Alt Function Open Drain

    GPIOB->CRL = 0xFF4444AA;

    GPIOB->CRH = 0x44444433;    //Configure PB8 & PB9 as Output (Push Pull)

    GPIOC->CRL = 0x44440000;  //GPIOC0- GPIOC3 Analog Input

}

Regards

Slim
0 REPLIES 0