cancel
Showing results for 
Search instead for 
Did you mean: 

USART problem

piotr2
Associate
Posted on February 17, 2014 at 14:24

Hi!

I tried to establish USART connection between my STM32F103RB with PC and I cannot do it. I searched many topics and forums and tried different possiblities and nothing worked.

I also tried to make a USART connection on my board (between USART1 and USART2) and it worked fine. Unfortunately after rewiring cables to connect USART1 with ZL4USB (this is board with opto-isolation using FT232R) I send and receive some rubbish.

I'd be grateful for getting some help.

#usart-stm32
13 REPLIES 13
matthias23
Associate II
piotr2
Associate
Posted on February 17, 2014 at 15:23

Thanks for quick answer. I thought that might be a problem. But in other program using same clock initilization I manage to get some sinusoidal signal with desired frequency (checked in oscilloscope). In this second program I'm using timers though...

Is there a way of checking clock correctness apart from using oscilloscope (I can't do it now) or what is the correct way of setting the clock? Here is my clock initialization (same in both mentioned programs):

void clk_init(void) {
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET) {}
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { }
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while (RCC_GetSYSCLKSource() != 0x08) {}
}

And my usart configuration (I think it's rather standard):

void USART_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 ; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate=4800; 
USART_InitStructure.USART_Mode=USART_Mode_Rx | USART_Mode_Tx; 
USART_InitStructure.USART_Parity=USART_Parity_No; 
USART_InitStructure.USART_StopBits=USART_StopBits_1; 
USART_InitStructure.USART_WordLength=USART_WordLength_8b; 
SART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_Init(USART1,&USART_InitStructure);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
//Uruchomienie USART1
USART_Cmd(USART1,ENABLE);
}

Posted on February 17, 2014 at 16:30

Is there a way of checking clock correctness apart from using oscilloscope (I can't do it now) or what is the correct way of setting the clock?

If you have to figure by eye, then perhaps using a timer to toggle an LED at 1 Hz, would certainly allow you to assess gross errors in timing.

Manually you could walk the code and project settings. Specifically that of HSE_VALUE which is used in the math to compute the baud rate. You could also try running the part directly from the HSI without the PLL.

The CMSIS structure normally has the clocks configured via SystemInit() in system_stm32fxxx.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chen
Associate II
Posted on February 17, 2014 at 16:36

Hi

''I tried to establish USART connection between my STM32F103RB with PC and I cannot do it.''

''I also tried to make a USART connection on my board (between USART1 and USART2) and it worked fine.''

I hope you used a RS232 level convertor (such as aMAX232). The PC serial port will be at around +/-12V.

The poor STM32 is working at 0 and 3.3V  !!

(Do not worry, you can usually get away with it if you do not leave it connected for too long. The fact that it still worked USART1 - 2 is a good indication the ports are not damaged)

pafshan
Associate II
Posted on February 22, 2014 at 05:28

I am new to this forum and also new to the STM32f100 uC.

I recently bought two STM32f100 value line discovery boards and am able to program it for some simple functions.

I can download the code to the flash memory from board A to board B through the built-in ST link on board A.

I am also able to download the program to the flash memory of the discovery board using uart through RXD and TXD (PA9 and PA10) with the help of 'flash loader demo' program from ST.

However I am having trouble trying to download the program to my own application uC (the same one as on the discovery board) with either ST-line or uart. For uart, I provided the 3.3V and GND externally, connected the PA9 and PA10, put BOOT0 to high. But the program keeps saying that 'no response from the target,....'

Any one has the similar experience and knows what the problem might be? Your help is greatly appreciated!

Thanks,

Posted on February 22, 2014 at 06:16

Given the fact set, I'd probably have you check the VDDA, needs to be powered as it supplies the power-on-reset, then check the state of NRST pin.

The behaviour of the Flash Demonstrator could be cross-checked manually using something like RealTerm to send 0x7F at 9600 8E1, and observe if you get the 0x79.

Other than that, supplies, opens, shorts, pin 1 orientation..
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pafshan
Associate II
Posted on February 22, 2014 at 19:34

Clive1,

Thanks for your help. The VDDA is connected to the 3.3V and the NRST pin is put on momentary low at reset.

However when I issued 7f (and 0x7f since I am not sure what is the correct format) at the RealTerm, I observed the TXD turned yellow briefly, but the RXD never change and nothing showed up on the display. I am afraid there is no response from the chip. Any clue?

Thanks,

Steve

Posted on February 23, 2014 at 01:37

Right now it doesn't sound like anything is running, I'd have to review a schematic of what you've implemented.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pafshan
Associate II
Posted on February 23, 2014 at 02:46

I will make the schematics and send to you shortly.

One thing I forget to mention: I purchased the proto board and solder the chip on it myself. Instead of reflowing it, I used my solder iron and tap-soldering all pins very lightly and quickly. Could it be possible that the pins/chip might be damaged during the process?