cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 USART notworking

aruns06
Associate II
Posted on November 07, 2014 at 06:37

Hi,

I am trying to some data from STM32FO devboard(Standard board from ST- MB1304) to PC via usart1. I have created the project in Keil. Data is not transmitting from STM32 to PC. First I thought that code is not running. To check that I have added an led blinking program and then checked. The led starts blinking, but no data via usart. Don't know what went wrong. I think there might be the problem with clock configuration...The code is given below.

int main()
{ 
init_usart();
while(1)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{
USART_SendData(USART1, 'X');
}
}
}
void init_usart()
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_0);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_0);
/* Configure USART1 pins: Rx and Tx ----------------------------*/
GPIO_InitStructure.GPIO_Pin = 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_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);
}

.Any suggestions.... #stm32f0-usart
6 REPLIES 6
chen
Associate II
Posted on November 07, 2014 at 10:31

Hi

''I am trying to some data from STM32FO devboard(Standard board from ST- MB1304)''

Quick search did not find the board (MB1304) you are referring to.

Are you referring to this one :

http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF253215?sc=internet/evalboard/product/253215.jsp

If so, the USART output levels are not RS232 (+/- 12V).

You need to use a level converter (eg MAX232).

aruns06
Associate II
Posted on November 07, 2014 at 10:50

Yes I am using the same board.

2.I am using FTDI converter to connect the board with PC. So I think that will not be an issue.......

chen
Associate II
Posted on November 07, 2014 at 11:21

''2.I am using FTDI converter to connect the board with PC. So I think that will not be an issue.......''

What do you mean 'FTDI converter' ?

Pre-assembled converter boards usually convert RS232 (level ie +-12V) to USB from what I know of them.

A bare FTDI device (chip) will take logic (5V or 3V) levels.

Have you checked with a scope if anything is coming out of GPIO_A IO 9 and 10 ?

aruns06
Associate II
Posted on November 07, 2014 at 11:34

As far as I know, I can connect the said Rx and Tx of  ftdi converter to corresponding Tx and Rx pins of the controller and watch the output in serial terminal. (I m doing the same with F1 discovery board also)

I have not checked the output with scope. Do you have any suggestions in the clock configuration part???

chen
Associate II
Posted on November 07, 2014 at 11:44

''Do you have any suggestions in the clock configuration part???''

The only thing that looks different from the code I here which works is ''

GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_0);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_0);

'' Check that 'GPIO_AF_0' selects the correct alternate function.
manukharshan
Associate II
Posted on June 20, 2015 at 19:57

change as shown inside while loop

USART_SendData(USART1, 'X');

 while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)  { }