cancel
Showing results for 
Search instead for 
Did you mean: 

USART1 simple use problem

guillaume2
Associate II
Posted on June 29, 2012 at 10:24

Hello everybody, I begin with CortexM4 STM32F4 on a keil developpement board (MCBSTM32F400) I try to use USART1 in a very simple mode. I take a look to example and discuss forums. My config seems to be good but no signals come out of the board. If someone could help me, it would be very smart.

Here is the config of the USART I take:

/* GPIOB,GPIOF Periph clock enable */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOF, ENABLE);

/*USART1 Periph clock enable*/

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

 /* Configure PB6 PB7 in alternate function */

  

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

/* Connect USART pins to AF */

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1);   // USART1_TX

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);  // USART1_RX

/*Configure USART1 parameters*/

 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;

  USART_Init(USART1,&USART_InitStructure);

  USART_Cmd(USART1,ENABLE);

In th main program I just try to put 'I':

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); // Wait for Empty

USART_SendData(USART1, 0x49); // Send 'I'

Nothing happens, I don't understand

#stm32f4-usart
5 REPLIES 5
Posted on June 29, 2012 at 12:33

Code fragment doesn't appear unreasonable.

Check the jumpers J13 and J14 are in the 2-3 position.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
guillaume2
Associate II
Posted on June 29, 2012 at 12:36

Yeah I have already checked it, but it is a good remark.

guillaume2
Associate II
Posted on June 29, 2012 at 13:03

I finally found the answer, the schematics isn't clear. To connect USART1 on DB9 connector the switch have to be on the left position, regarding the RX3 TX3 silkscreen. PCB error?, schematics error? But now I see my character.

Thanks Clive1

Posted on June 29, 2012 at 13:08

Check the PB6/7 pins don't clash with some other functionality on the board.

Try the alternate USART set up. Confirm that the clocks and pll setup match the hardware on the board, ie is HSE 8, 16 or 25 MHz, and does that correlate with settings in system_stm32f4xx.c

#include ''stm32f4xx.h''
main()
{
/* GPIOB,GPIOF Periph clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOF, ENABLE);
/*USART1 Periph clock enable*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* Configure PB6 PB7 in alternate function */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NONE;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); // USART1_TX
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); // USART1_RX
/*Configure USART1 parameters*/
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;
USART_Init(USART1,&USART_InitStructure);
USART_Cmd(USART1,ENABLE);
while(1)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(USART1, 0x49); // Send 'I'
}
}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 29, 2012 at 13:09

Ok, messages passed on the wire.

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