cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072 Discovery USART2 not transmitting

bgorsline
Associate II
Posted on September 23, 2015 at 05:08

Having trouble getting USART2 working on both of mySTM32F072 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.


#include ''main.h''

#include ''stm32f0xx_usart.h''

#include ''stm32f0xx.h''

#include ''stm32f072b_discovery.h''


int main(void)

{

USART_InitTypeDef USART_InitStructure;

GPIO_InitTypeDef GPIO_InitStructure;


RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);


RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART4,ENABLE);


/* Configure USART1 pins: Rx PA10 (connect ftdi orange) and Tx PA9 (connect ftdi yellow) (AF1) ----*/

GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);


/* Configure USART2 pins: Rx PA3 (orange) and Tx PA2 (yellow) (AF1) ---- */

GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);


/* Configure USART3 pins: Rx PB11 (orange) and Tx PB10 (yellow) (AF4) ----*/

GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_4);

GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_4);


/* Configure USART4 pins: Rx PA1 (orange) and Tx PA0 (yellow) (AF4) -----*/

GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_4);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_4);



/* set up port A GPIO */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_9|GPIO_Pin_10;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART 1,2,4 */


/* set up port B GPIO */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_10; /* USART3 */

GPIO_Init(GPIOB, &GPIO_InitStructure);



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;


USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1,ENABLE);

USART_Init(USART2, &USART_InitStructure);

USART_Cmd(USART2,ENABLE);

USART_Init(USART3, &USART_InitStructure);

USART_Cmd(USART3,ENABLE);

USART_Init(USART4, &USART_InitStructure);

USART_Cmd(USART4,ENABLE);


while(1)

{

while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

USART_SendData(USART1, '1');

while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);

USART_SendData(USART2, '2');

while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);

USART_SendData(USART3, '3');

while (USART_GetFlagStatus(USART4, USART_FLAG_TXE) == RESET);

USART_SendData(USART4, '4');

}

}

Pointers much appreciated. #stm32 #usart
2 REPLIES 2
Posted on September 23, 2015 at 05:57

Solder Bridges on the DISCO?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bgorsline
Associate II
Posted on September 25, 2015 at 04:54

Bingo.

Several pins on this Discovery board are used for the touch sensor, including PA2 and PA3. Did the recommended mods and USART2 works now. 

Thanks for the pointer.