请问在哪里设置正确的晶震频率

[复制链接]
 楼主| a_bb 发表于 2007-5-10 16:35 | 显示全部楼层 |阅读模式

我的晶震为11.0592MHz,用UART2,修改了keil下的例子。
我在91x_CONF.H中修改了#define _Main_Crystal 25000
改为#define _Main_Crystal 11059
发现串口输出的速率没有变化,是不是需要在其它地方
修改。

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

  UART_DeInit(UART2);
  UART_Init(UART2, &UART_InitStructure);

  /* Enable the UART0 */
  UART_Cmd(UART2, ENABLE);


   GPIO_DeInit(GPIO3);
  /*Gonfigure UART0_Tx pin GPIO3.0*/
//  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;
  GPIO_Init (GPIO3, &GPIO_InitStructure);

  /*Gonfigure UART0_Rx pin GPIO3.1*/
//  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  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);


stf 发表于 2007-5-11 15:22 | 显示全部楼层

91x_uart.c

a_bb 你好,

你调试的时候你可以看这两个寄存器:
UART_IBRD
UART_FBRD

如果你改#define _Main_Crystal 25000改为#define _Main_Crystal 11059 这两个寄存器有没有变化?

上次你给我说你在用keil的ide,我用得不多。 

在"option for target" 好象有一个地方可以配置晶震 "Xtal (Mhz)"

调试的时候你应该用st函数库的代码:

你有没有这两个目录:
*your keil directory*ARMINCSt91x
*your keil directory*ARMRV30LIBSTSTR91x

里面有st函数库的代码。你可以加这一些文件在你的项目里面这样调试会方便多了。你可能也需要改“configuration wizard"的配置。

Best Regards,
Stephane
 楼主| a_bb 发表于 2007-5-11 17:11 | 显示全部楼层

找到了问题,但没解决

谢谢stf
我有以下两个目录,这样调程序就方便了
*your keil directory*ARMINCSt91x :h files
*your keil directory*ARMRV30LIBSTSTR91x : c files

我在程序中加了
i = SCU_GetMCLKFreqValue();
无论我如何修改_Main_Crystal的值(也修改了option for target中的值)
i永远等于25000(10进制)
IBRD = 0x06, FBRD = 0x32

看来还真的是修改的值没起作用!

 楼主| a_bb 发表于 2007-5-11 17:19 | 显示全部楼层

奇怪

按以上得到的IBRD和FBRD及25000K的主频算来
波特率= 230457与str9refmanual中256页的值竟然如此相近
stf 发表于 2007-5-11 17:37 | 显示全部楼层

preprocessor file generation

Keil和IAR在用一样的函数库。除了startup文件以外代码是一样的。

所以我觉得你可能有一个startup文件或者一个preprocessor的问题。

你可以试一是用这个:

Preprocessor (I) File
The preprocessor output file is created when the PREPRINT directive is specified. This file includes the preprocessor output for the specified source file.

The most obvious use for a preprocessor output file is to verify the operation of macros and conditional preprocessor directives.

这样你会这道你编译91x_scu.c的时候_mainCrystal是多少。

Best Regards,
Stephane
 楼主| a_bb 发表于 2007-5-11 18:20 | 显示全部楼层

不会用

Preprocessor (I) File
The preprocessor output file is created when the PREPRINT directive is specified. This file includes the preprocessor output for the specified source file.

不会用呀!在程序里加什么?
还是用命令行?
 楼主| a_bb 发表于 2007-5-14 15:37 | 显示全部楼层

我想问题应该在这里


程序中使用的API函数调用了STR91xR.LIB库,估计在库中
已将晶震频率固定为25M,我加入了91x_scu.c,然后修改

C:KeilARMINCST91x91x_conf.h,再重新编译程序,就
可得到所需的频率。
但问题是更改了根处的配置文件,会对所有的工程有影响,
不同的电路采用不同的频率,所以说此方法还不是一个最优的
办法
您需要登录后才可以回帖 登录 | 注册

本版积分规则

35

主题

98

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部

35

主题

98

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部