cancel
Showing results for 
Search instead for 
Did you mean: 

USART on ST32 Issues

alexsardo9
Associate II
Posted on April 02, 2010 at 04:52

USART on ST32 Issues

#usart1-dead
15 REPLIES 15
alexsardo9
Associate II
Posted on May 17, 2011 at 13:45

I am using STM32F103VBT6

jjcote
Associate II
Posted on May 17, 2011 at 13:45

Which part/package are you using exactly?

Posted on May 17, 2011 at 13:45

USART2 at 9600 would work like this

int main(void)

{

  USART_InitTypeDef USART_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

  USART_InitStructure.USART_BaudRate = 9600;

  USART_InitStructure.USART_WordLength = USART_WordLength_8b;

  USART_InitStructure.USART_StopBits = USART_StopBits_1;

  USART_InitStructure.USART_Parity = USART_Parity_No ;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // UART2 Tx PA.2

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // UART2 Rx PA.3

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  USART_Init(USART2, &USART_InitStructure);

  USART_Cmd(USART2, ENABLE);

    while(1)

    USART_SendData(USART2,'A');

}

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

clive, thank you for the examples. I think since I have access to PA2 I will cut/paste the second example at 9600bps. Do I need to do anything else like setting up closks or any other woodo? Also, do you think that the since the ST is a 3v device that there could be some logic-level issues when using it with a ttl converter? In any case, thanks everyone for your help, at least now I have a starting code that works -- when I get back to work I'll get the scope and check the levels.

Thanks again.
Posted on May 17, 2011 at 13:45

The clocks would only be need to be setup explicitly if you were using synchronous serial modes. The code fragment provided for USART1 was all that was needed on the device. I wasn't remapping the USART so the AFIO clocks might be overkill, I usually enable them, ST does so in the boot loader.

My USART1 is connected up to a debug terminal via a FTDI DLP-RXTX, these boards have a solder jumper so you can switch the IO between 5V, or the voltage (3V/3.3V) supplied by the STM32

http://www.dlpdesign.com/dlptxrx-v12-ds.pdf

A quick check of the manual suggests that the USART1 pins are 5V tolerant, the

USART2

pins are NOT.

-Clive

Edit: USART2 pins can be remapped to PD.5/PD.6 on the LQFP100 package, these pins are 5V tolerant. I don't have the ST decoder wheel to hand so not sure that is your part, other than it's a Medium Density part.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
alexsardo9
Associate II
Posted on May 17, 2011 at 13:45

Clive,

5v Tollerance would be preferred (since It'll be driving fiber optic transcievers) I'll solder up pin 68,69 (PA9/PA10) and give it a try -- I'll let you know.

Alex