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
jjcote
Associate II
Posted on May 17, 2011 at 13:45

You're using USART2, but you're enabling the clock for USART1.  Try this instead:

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

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

Hi Alex,

What do you mean by ttl <> USB, are you using USB/USART adapter between host and target ?

Slim

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

Thank you for the reply. Still no output .. I now deleted everything and have just a main() with the following code. I connected PA2 to a FTDI ttl<>USB and (I double-checked the pins and functionality of the FTDI and that part works).

I need help ...

I converted it all to USART1 (I don't really care which USART I use since I have access to all 3). This is all I have in my program - no other code... What am I missing?

void main(void) {

  USART_InitTypeDef USART_InitStructure;

  USART_ClockInitTypeDef  USART_ClockInitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);

  USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;

  USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;

  USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;

  USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;

  USART_ClockInit(USART1, &USART_ClockInitStructure);

  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;

  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_0;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  USART_Init(USART1, &USART_InitStructure);

  USART_Cmd(USART1, ENABLE);

while(1)

    USART_SendData(USART1,'A');

 

}

Maybe there is something else wrong -- perhaps if I had a piece of code that was guaranteed to work (ie tested) I could isolate whatever else I messed up... All I need is being able to send 'A's out to PA2 ... (I'm using IAR5 by the way)
alexsardo9
Associate II
Posted on May 17, 2011 at 13:45

I have a TTLUSB converter between the Cortex-M3 Pa2 and a side pc with hyperterminal. hyperterminal works and I can echo the characters if i short RX+TX on the converter so that is not the problem. I think the problem is my lack of understanding or having an eample (complete) on how to transmit 1 character from the Cortex-M3 through PA2 ...
sgomes
Associate II
Posted on May 17, 2011 at 13:45

Not sure if this is your problem but with that tight while loop you are sending very very fast.  In fact, you are over writing the transmit buffer WAY before the character is sent out.  Add a line to wait for TC or TXE to become set.

Secondly, if that is all your code, where are you setting up the system clock?

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

That is all the code that is left once I took everything else out of the program. My goal (and need for help) is to have just a basic main which transmits 1 character (or anything) over PA2. The Board has a Cortex-M3 and 8mhz clock (LCD buttons etc). The project is a hand-me-down from another developer that has left the company. My task is to pick it up and finish it. My goal was to have just a main with serial-tx and then figure the integration later but I am struggling with this serial comms issue. What did I forget? What should I add to my 'main'?

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

You've switched to USART1, but you're still setting up the pins for USART2.  USART1 should be on PB6/PB7.  If you want to use PA2/PA3, I think you have to use USART2.

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

Well perhaps this is where the whole confusion may be (or not)...

I was under the impression that you could use any port for any pin and any purpose ...

My idea was to use PA2 to transmit data and PA0 to receive since these are the only 2 ports left.

If my thinking was wrong, what port do i need to use for TX/RX using USART1? is PA2 still ok for TX?
Posted on May 17, 2011 at 13:45

USART1 Comes out of PA.9 (Tx), with PA.10 (Rx)

This works at 115200 baud.

-Clive

int main(void)

{

  USART_InitTypeDef USART_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);

  USART_InitStructure.USART_BaudRate = 115200;

  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_9; // UART1 Tx PA.9

  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_10; // UART1 Rx PA.10

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  USART_Init(USART1, &USART_InitStructure);

  USART_Cmd(USART1, ENABLE);

    while(1)

    USART_SendData(USART1,'A');

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..