AnsweredAssumed Answered

stm32f107vc usart

Question asked by scott.michael on Jan 23, 2012
Latest reply on Jan 24, 2012 by Clive One

Hi,

I am trying to get the usart to work on the olimex stm32-p107 board. I setup the GPIO ports and USART, but cannot seem to send, or receive any data. Has anyone has this problem? or any ideas? 

Here is my code:  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
/* Enable USART3 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);

/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);

/* Remap USART, as USART3 is used as alternate pins */
//GPIO_PinRemapConfig(GPIO_FullRemap_USART3, ENABLE);

/* Configure USART 9600 8N1 */
USART_DeInit(USART3);
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_Tx;// | USART_Mode_Rx;
USART_InitStructure.USART_Clock = USART_Clock_Enable;
USART_InitStructure.USART_CPOL = USART_CPOL_Low;
USART_InitStructure.USART_CPHA = USART_CPHA_1Edge;
USART_InitStructure.USART_LastBit = USART_LastBit_Enable;
USART_Init(USART3, &USART_InitStructure);

/* Enable USART3 */
  USART_Cmd(USART3, ENABLE);

/* Send some test data */
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
  USART_SendData(USART3, (u8) 'T');
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, (u8) 'e');
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, (u8) 's');
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, (u8) 't');

Outcomes