AnsweredAssumed Answered

STM32F072 Discovery USART2 not transmitting

Question asked by gorsline.bret on Sep 23, 2015
Latest reply on Sep 25, 2015 by gorsline.bret
Having trouble getting USART2 working on both of my STM32F072 Discovery boards. USART 1, 3, and 4 work fine. 

Here's a test program that fires off the port number in a loop. It's basically similar to what's posted in other snippets in this forum and elsewhere, but has the pin numbers for this chip (at least I think the pin numbers are correct for F072RB). The FTDI cable reads ports 1,3, and 4 into TeraTerm, but must not be understanding something about 2. Checked the common APB1 vs APB2 issue. Tried the alternate USART2 pins PA14 and PA15, but that caused grief with the bootloader.

01.#include "main.h"
02.#include "stm32f0xx_usart.h"
03.#include "stm32f0xx.h"
04.#include "stm32f072b_discovery.h"
05. 
06.int main(void)
07.{
08.  USART_InitTypeDef USART_InitStructure;
09.  GPIO_InitTypeDef GPIO_InitStructure;
10. 
11.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
12.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
13. 
14.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
15.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
16.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
17.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART4,ENABLE);
18. 
19.  /* Configure USART1 pins:  Rx PA10 (connect ftdi orange) and Tx PA9 (connect ftdi yellow) (AF1) ----*/
20.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
21.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
22. 
23.  /* Configure USART2 pins:  Rx PA3 (orange) and Tx PA2 (yellow) (AF1) ---- */
24.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
25.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
26. 
27.  /* Configure USART3 pins:  Rx PB11 (orange) and Tx PB10 (yellow) (AF4) ----*/
28.  GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_4);
29.  GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_4);
30. 
31.  /* Configure USART4 pins:  Rx PA1 (orange) and Tx PA0 (yellow) (AF4) -----*/
32.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_4);
33.  GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_4);
34. 
35. 
36.  /* set up port A GPIO */
37.  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_9|GPIO_Pin_10;
38.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
39.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
40.  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
41.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
42.  GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART 1,2,4 */
43. 
44.  /* set up port B GPIO */
45.  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_11 | GPIO_Pin_10; /* USART3 */
46.  GPIO_Init(GPIOB, &GPIO_InitStructure);
47. 
48. 
49.  USART_InitStructure.USART_BaudRate = 9600;
50.  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
51.  USART_InitStructure.USART_StopBits = USART_StopBits_1;
52.  USART_InitStructure.USART_Parity = USART_Parity_No;
53.  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
54.  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
55. 
56.  USART_Init(USART1, &USART_InitStructure);
57.  USART_Cmd(USART1,ENABLE);
58.  USART_Init(USART2, &USART_InitStructure);
59.  USART_Cmd(USART2,ENABLE);
60.  USART_Init(USART3, &USART_InitStructure);
61.  USART_Cmd(USART3,ENABLE);
62.  USART_Init(USART4, &USART_InitStructure);
63.  USART_Cmd(USART4,ENABLE);
64. 
65.  while(1)
66.  {
67.   while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
68.   USART_SendData(USART1, '1');
69.   while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
70.   USART_SendData(USART2, '2');
71.   while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
72.   USART_SendData(USART3, '3');
73.   while (USART_GetFlagStatus(USART4, USART_FLAG_TXE) == RESET);
74.   USART_SendData(USART4, '4');
75.  }
76.}


Pointers much appreciated.


 

Outcomes