cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with USART with stm32f103c8t6 microcontroller

mat25nt
Associate II
Posted on March 25, 2013 at 11:19

Hi everyone!! I'm working on my very first project as engineer with a friend and colleague. We bought th eval board with the f4 and f100 series microcontroller on. We tested our code on both of them and everything's fine. As soon sketched and produced our board and soldered all the components we're not having the stm32f103c8t6 (the same family of the one on the f100 eval board) working on the USART. The other internal and external peripherals are working and we checked for errors or cc on the board or solders.

So we were wondering about if a external crystal oscillator is needed, any other ideas??
11 REPLIES 11
frankmeyer9
Associate II
Posted on March 25, 2013 at 11:47

So we were wondering about if a external crystal oscillator is needed, any other ideas??

That depends on your requirements.

The MCU is running fine on the internal RC oscillator, if you initialize it properly.

The drift related to temperature, aging and tolerances are significantly worse, compared to a quartz. And this affects of course all timers and baudrate settings.

mat25nt
Associate II
Posted on March 26, 2013 at 09:45

Ok, a professor told us and we thought to put an oscillator in the definitive board....but we can't realize what is wrong right now!! As i said before the eval-board with the same MCU is running fine with the code, our not. I forgot to say previously that the same pins of the USART3 (PB10,PB11) are working as GPIO pins but not as USART pins!!

Posted on March 26, 2013 at 12:52

I'm not sure what help you're looking for, or what the exact issue is that you're trying to describe.

If you don't have an external oscillator, then you'll need to change/adapt the code in system_stm32f1xx.c to use the HSI (High Speed Internal) oscillator. The part starts using the HSI at 8 MHz, the accuracy of the clock is adequate for serial comms, and running the part to 64 MHz. For USB, CAN and 72 MHz you need an external crystal. This should work to demonstrate USART3 on an F103 based board

// STM32 USART3 (Tx PB.10, Rx PB.11) - STM32 VLDiscovery - sourcer32@gmail.com
#include ''stm32F10x.h''
#include ''STM32vldiscovery.h''
/**************************************************************************************/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART_Configuration();
while(1)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(USART3, 0x49); // Send 'I'
}
while(1); // Don't want to exit
}
/**************************************************************************************/
void RCC_Configuration(void)
{
// clock for GPIO
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Enable UART clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // PB.10 USART3.TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // PB.11 USART3.RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
/**************************************************************************************/
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USART configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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 configuration */
USART_Init(USART3, &USART_InitStructure);
/* Enable the USART3 */
USART_Cmd(USART3, ENABLE);
}
/**************************************************************************************/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mat25nt
Associate II
Posted on March 26, 2013 at 15:38

Well i think, clive1, you made the point!! We just moved the same code from the eval-board to our board that has no external oscillator. So, by default, in system_stm32f10x.c is assumed an external 8MHz oscillator is used?? If yes, how to change the code to make it work with the HSI? We googled around but didn't managed to find something very clear...(

http://www.oliverbehr.de/?option=com_content&view=article&id=52:stm32

for the site found)

Posted on March 26, 2013 at 15:59

If you are comfortable running off the HSI directly, you could remove all the code from SystemInit(), and disable all the #define SYSCLK_FREQ_xxx lines.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mat25nt
Associate II
Posted on March 26, 2013 at 23:27

Ok, thank you for the help!! Don't understand anyway, you meant to delete all the #define SYSCLK_FREQ_xxx lines in system_stm32f100xxx??

Posted on March 27, 2013 at 00:44

I mean put a '//' in front of those #define lines at the top of the file, and cut the body code from SystemInit(), the result will be that the part starts as usual with the HSI running at 8 MHz, and doesn't change that.

Yes, you could also get more creative and run the PLL at 64 MHz from the 8 MHz HSI. I'm not sure you're ready for that, and I'm not up to edit and test it. Basically it requires selecting HSI/2 as the PLL source, with a multiplier of 16. Wait for it to lock (come ready/stable), and then switch to the PLL, and then wait for the selection to complete.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mat25nt
Associate II
Posted on March 27, 2013 at 11:20

We used this code after commenting all the lines above SystemInit() in system_stm32f10xx.c

void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSI */
RCC_HSICmd(ENABLE); 
if (1)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* 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_HSI_Div2, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while (RCC_GetSYSCLKSource() != 0x08)
{}
}

This should do the trick? Or something is still missing?? Anyway, we're up to redesign the boards to include an external oscillator, but we'd like to make those ones work with the HSI. Thanks for the help!! EDIT: the code is used in main() as the first instruction
Posted on March 27, 2013 at 12:52

HSI should be running by default. The PLL setting here will run the processor at 36 MHz.

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