cancel
Showing results for 
Search instead for 
Did you mean: 

USART Clock

bozorgzad
Associate II
Posted on December 28, 2009 at 18:03

USART Clock

6 REPLIES 6
bozorgzad
Associate II
Posted on May 17, 2011 at 13:35

Hi

I have a problem with synchronous USART(on USART3).I have configured related parts, but I have not any output clock whenever I send information via it.(Data can be seen with oscilloscope but clock is not available).

I am using Ride7(7.20.09.0162) as a compiler.

The part of the program which is related to USART configuration is as follow, and I will appreciate if anybody can help me to find my failure.

#define sysclock High

void USART_Configuration(void)

{

USART_InitTypeDef USART_InitStructure;

USART_ClockInitTypeDef USART_ClockInitStructure;

//USART3 configuration

#if(sysclock==High)//36MHz

USART_SetPrescaler(USART3, 0x04);//USART Clock set to 4.5MHz ((APB1CLK=18Mhz)/4)

#elif(sysclock==Low)//4MHz

USART_SetPrescaler(USART3, 0x01);//USART Clock set to 4MHz ((APB1CLK=4Mhz)/1)

#endif

USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;

USART_ClockInitStructure.USART_CPOL = USART_CPOL_High;

USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;

USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable;

USART_ClockInit(USART3,&USART_ClockInitStructure);

USART_InitStructure.USART_BaudRate = Global_Def_USART3_Default_Baud;

USART_InitStructure.USART_WordLength = USART_WordLength_9b;//Word Length = 9 Bits

USART_InitStructure.USART_StopBits = USART_StopBits_1_5;//1.5 stop bit is transmitted at the end of frame

USART_InitStructure.USART_Parity = USART_Parity_Even;//Even parity,When parity is enabled, the computed parity is inserted at the MSB position of the transmitted data (9th bit when the word length is set to 9 data bits; 8th bit when the word length is set to 8 data bits).

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//Tx and Rx enabled

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//Hardware flow control disabled (RTS and CTS signals)

USART_Init(USART3, &USART_InitStructure);

USART_Cmd(USART3, ENABLE);//Enable USART3

}

void RCC_Configuration(void)

{

RCC_DeInit();//RCC system reset(for debug purpose)

RCC_HSEConfig(RCC_HSE_ON);//Enable HSE

HSEStartUpStatus = RCC_WaitForHSEStartUp();//Wait till HSE is ready

if(HSEStartUpStatus == SUCCESS)

{

RCC_PCLK2Config(RCC_HCLK_Div1);//APB2CLK = HCLK

FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);//Enable Prefetch Buffer

#if(sysclock==High)

RCC_HCLKConfig(RCC_SYSCLK_Div1);//AHBCLK = SYSCLK-36Mhz

RCC_PCLK1Config(RCC_HCLK_Div2);//APB1CLK = AHBCLK/2-18Mhz

FLASH_SetLatency(FLASH_Latency_2);//Flash 2 wait state

RCC_PLLConfig(RCC_PLLSource_HSE_Div2,RCC_PLLMul_9);//PLLCLK = 8MHz/2 * 9 = 36 MHz

RCC_PLLCmd(ENABLE);//Enable PLL

while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)//Wait till PLL is ready

{

}

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//Select PLL as system clock source

while(RCC_GetSYSCLKSource() != 0x08)// Wait till PLL is used as system clock source

{

}

#elif(sysclock==Low)

RCC_HCLKConfig(RCC_SYSCLK_Div2);//AHBCLK = SYSCLK/2-8Mhz/2=4Mhz

RCC_PCLK1Config(RCC_HCLK_Div1);//APB1CLK =AHBCLK-4Mhz

FLASH_SetLatency(FLASH_Latency_0);//Flash 0 wait state

RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);

#endif

}

RCC_GetClocksFreq(&RCC_ClocksStatus);

HCLK_Freq=(RCC_ClocksStatus.HCLK_Frequency/800000);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);//TIM2 clock enable

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |

RCC_APB2Periph_AFIO, ENABLE);//Enable GPIOA, GPIOB , GPIOD , GPIIOE and AFIO clocks

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);//Enable GPIOD and AFIO clocks

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);//Enable USART3 clocks

}

void GPIO_Configuration(void)

{

//USART3_Tx

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

//USART3_Rx

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

GPIO_Init(GPIOB, &GPIO_InitStructure);

//USART3_Clk

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOB, &GPIO_InitStructure);

}

tomas23
Associate II
Posted on May 17, 2011 at 13:35

Don't you enable as well some other peripheral, that shares the same pins, like SPI, I2C2 etc.? Setting their clock ON means enabling them...

See errata sheet and use pin remapping if needed.

bozorgzad
Associate II
Posted on May 17, 2011 at 13:35

Thanks for your answer, No, I didnt enable any other shared part with USART3(I2C2 is shared with USART3,and it is disabled(also I checked its clock as well)

tomas23
Associate II
Posted on May 17, 2011 at 13:35

Which MCU do you use? Is it the same as in your other post? Please post complete sales type.

If it's a ''low density'' STM32 (32kB of FLASH and lower), neither I2C2 nor USART3 are available, supported nor tested. You need at least ''medium density'' (64-128 kB FLASH) device for such operation.

bozorgzad
Associate II
Posted on May 17, 2011 at 13:35

Thanks, I am using STM32F101VBT6 which is a medium dencity device and has I2C2 as well as USART3.

tomas23
Associate II
Posted on May 17, 2011 at 13:35

USART1 or 2 in synchronous mode works well? Try as well remapping of USART3 to test whether the CK pin is influenced by something or not. Be aware that after remapping, you need to configure different set of pins.