2007-09-28 02:05 AM
2011-05-17 12:34 AM
hai iamanil,
we are using MCBSTR9 Evaluation Board. now we are facing a problem on UART.we are not even to transmit the data to Hyperterminal. i have used u'r program, but it is not working. in u'r program u were used m=4,n=192,p=3. with these values my program is not working. how much Fpll did u set? i have changed these values as m=25,n=192,p=3 for getting Fpll 48Mhz. my Xtal value is 25Mhz. when i execute my code i am getting the following ..U}[W¿u}mou»¿U}[W¿Â¿o}u{wu{mmo}oëà in Hyperterminal. if i send the data 00-ff , then i am getting ascii values of FF,FD,FB,FB,F7,F5,F7,F7,EF,ED,EB,EB,EF,ED,EF. in hyperterminal. here i am sending my code please have a glance of this code and give u'r sugessions. and i am requesting u to send the working example of UART. /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** * File Name : main.c * Author : MCD Application Team * Date First Issued : 05/18/2006 : Version 1.0 * Description : Main program body ******************************************************************************** * History: * 05/24/2006 : Version 1.1 * 05/18/2006 : Version 1.0 ******************************************************************************** * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. *******************************************************************************/ /* Includes ---------------*/ #include ''91x_lib.h'' /* Private typedef --------*/ /* Private define ---------*/ #define TxBufferSize (countof(TxBuffer) - 1) #define RxBufferSize 0xFF /* Private macro ----------*/ #define countof(a) (sizeof(a) / sizeof(*(a))) /* Private variables ------*/ UART_InitTypeDef UART_InitStructure; u8 TxBuffer[] = ''UART Example: UART - Hyperterminal\n\r''; u8 RxBuffer[RxBufferSize]; u8 NbrOfDataToTransfer = TxBufferSize; u8 TxCounter = 0; u8 RxCounter = 0; // **************************************************************** // Phase Lock Loop (PLL) setting // **************************************************************** #define PLL_M 25 // M (1 <= M <= 255) value for phase lock loop #define PLL_N 192 // N (1 <= N <= 255) value for phase lock loop #define PLL_P 3 // P (1 <= P <= 5) value for phase lock loop // **************************************************************** // clocks divisor setting // **************************************************************** #define RCLK_Divisor SCU_RCLK_Div1 // Reference clock divisor #define HCLK_Divisor SCU_HCLK_Div1 // ARM high speed bus divisor #define PCLK_Divisor SCU_PCLK_Div2 // ARM Peripheral bus divisor #define FMICLK_Divisor SCU_FMICLK_Div1 // FMI divisor /* Private function prototypes -------------*/ void SCU_Configuration(void); void GPIO_Configuration(void); /* Private functions ------*/ /******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main() { u8 i; #ifdef DEBUG debug(); #endif SCU_MCLKSourceConfig(SCU_MCLK_OSC); SCU_PLLFactorsConfig(PLL_N, PLL_M, PLL_P); SCU_PLLCmd(ENABLE); SCU_MCLKSourceConfig(SCU_MCLK_PLL); SCU_RCLKDivisorConfig(RCLK_Divisor); SCU_HCLKDivisorConfig(HCLK_Divisor); SCU_PCLKDivisorConfig(PCLK_Divisor); /* Configure the system clocks */ SCU_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); UART_InitStructure.UART_WordLength = UART_WordLength_8D; UART_InitStructure.UART_StopBits = UART_StopBits_1; UART_InitStructure.UART_Parity = UART_Parity_No ; UART_InitStructure.UART_BaudRate = 115200; UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; UART_InitStructure.UART_Mode = UART_Mode_Tx;//_Rx; UART_InitStructure.UART_FIFO = UART_FIFO_Enable; UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */ UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */ UART_DeInit(UART1); UART_Init(UART1, &UART_InitStructure); /* Enable the UART1 */ UART_Cmd(UART1, ENABLE); UART_LoopBackConfig(UART1, DISABLE); TxCounter = 0; //while(1){ while(NbrOfDataToTransfer--) { UART_SendData(UART1, TxBuffer[TxCounter++]); while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET); } for(i=0;iNbrOfDataToTransfer = TxBufferSize; TxCounter = 0; //} //do //{ //if((UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)&&(RxCounter < RxBufferSize)) //{ //RxBuffer[RxCounter] = UART1->DR; //UART_SendData(UART1, RxBuffer[RxCounter++]); //} // //}while((RxBuffer[RxCounter - 1] != '\r')&&(RxCounter != RxBufferSize)); while (1); } /******************************************************************************* * Function Name : SCU_Configuration * Description : Configures the system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ void SCU_Configuration(void) { /* Enable the UART1 Clock */ SCU_APBPeriphClockConfig(__UART1, ENABLE); SCU_APBPeriphClockConfig(__GPIO3, ENABLE); } /******************************************************************************* * Function Name : GPIO_Configuration * Description : Configures the different GPIO ports. * Input : None * Output : None * Return : None *******************************************************************************/ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; //GPIO_DeInit(GPIO3); ///*Gonfigure UART1_Rx pin GPIO3.2*/ //GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; //GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; //GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; //GPIO_Init (GPIO3, &GPIO_InitStructure); GPIO_DeInit(GPIO3); /*Gonfigure UART1_Tx pin GPIO3.3*/ GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2 ; GPIO_Init (GPIO3, &GPIO_InitStructure); } /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ thanks in advance raj.2011-05-17 12:34 AM
Hi anuradha,
to work with 48 Mhz you have to configure the clock as follow: SCU_PLLFactorsConfig(192, 25, 3); SCU_PLLCmd(ENABLE); SCU_RCLKDivisorConfig(SCU_RCLK_Div1); SCU_HCLKDivisorConfig(SCU_HCLK_Div1); SCU_PCLKDivisorConfig(SCU_PCLK_Div2); SCU_FMICLKDivisorConfig(SCU_FMICLK_Div1); SCU_MCLKSourceConfig(SCU_MCLK_PLL); so you have to enable the PLL before selecting the source clock . This configuration works well for me: I've obtained 48Mhz frequency and I was able to send data to hyperterminal. I hope this can be usefull for you. Best regards mirou2011-05-17 12:34 AM
Hi anuradha,
I tested your code with MCB-STR9 board and it works well for me. May be you configured wrong the hyperteminal utility. You find attached the hyperteminal configuration that I've used. Best regards mirou2011-05-17 12:34 AM
hai mirou,
i have used u'r hyper terminal file but it is also same as my file. thank u to conformed that my program is working. i have tried it in some other system (Hyperterminal), but no use. i could not find the mistake where actual problem is? please send me the complete project so that i will find my problem whether it is in Startup code or some where else. its better for me to have a working program. Thanks for u'r constant help. regards raj. [ This message was edited by: anuradha on 28-12-2006 06:24 ] [ This message was edited by: anuradha on 28-12-2006 08:10 ]2011-05-17 12:34 AM
hai mirou,
we are using MCB-STR9 Vers.3 Evaluation Board. On which board u r tested my code? according to program i think so there is no mistake. what are the other areas which may cause problem? please send me the UART working Example project file. thanks & Regards Raj.2011-05-17 12:34 AM
hai Zouh,
yes we are using crossover cable (2-3, 3-2, 5-5 of db connector). we are using Keil uVision3.03a software for Debug. did u check my code? regards raj.