cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f107vc usart

michaelscott2509
Associate II
Posted on January 23, 2012 at 17:49

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');

#stm32f107-usart
10 REPLIES 10
Posted on January 24, 2012 at 22:17

I really don't know how you're compiling this, or getting it on the board, and I don't have one of these specific boards.

I believe the code as presented should work, as incomplete as it is, if it is pasted in a suitable framework. You could add some code to toggle a GPIO or LED, and send data in a continuously loop. Stick a scope on the board and confirm if you can observe any signals.

Make sure your IDE, or whatever, is downloading code to the board, some IDE's default to a ''simulation'' without copying it to the hardware. Blinking an LED on the hardware would give a clear indication of working code.

I don't use Minicom, but RealTerm would work with 9600 8N1 with no flow control.

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