找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 12671|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

在STM32上如果不使用外部晶振,OSC_IN和OSC_OUT的接法

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:80436 發(fā)表于 2015-5-20 14:09 | 只看該作者 回帖獎(jiǎng)勵(lì) |正序?yàn)g覽 |閱讀模式
如果使用內(nèi)部RC振蕩器而不使用外部晶振,請(qǐng)按照下面方法處理:
1)對(duì)于100腳或144腳的產(chǎn)品,OSC_IN應(yīng)接地,OSC_OUT應(yīng)懸空。
2)對(duì)于少于100腳的產(chǎn)品,有2種接法:
  2.1)OSC_IN和OSC_OUT分別通過10K電阻接地。此方法可提高EMC性能。
  2.2)分別重映射OSC_IN和OSC_OUT至PD0和PD1,再配置PD0和PD1為推挽輸出并輸出'0'。此方法可以減小功耗并(相對(duì)上面2.1)節(jié)省2個(gè)外部電阻。
--------------------------------------------------------------------------------
以下是在ST英文網(wǎng)站FAQ上抄下的詳細(xì)解釋:
    1)  In 100 and 144 packages,  the OSC_IN /OSC_Out pins are a dedicated pins for HSE and mapped respectively on pins 12, 13 and pins 23, 24 for LQFP packages. Although, for BGA 100 and BGA 144 packages, they are mapped respectively on pins C1,D1 and pins D1,E1. In this case the recommended configuration is:
OSC_In pin must be connected to ground as it is always an input pin
OSC_Out must be left not connected as it is always an output pin.

     2)  In LQFP48 and LQFP64 packages,  the OSC_IN/OSC_Out pins are mapped on pins 5,6 whereas in the VFQFPN36 package they are mapped on pins 2,3. However the PD0 and PD1 functionality can be remapped by software on these pins.  There are two possible configurations:
Hardware configuration: Connect the OSC_IN/OSC_Out pins to ground through a 10K pull down resistors.
Software configuration: First, the OSC_IN/OSC_Out pins are left not connected on PCB layout. Then, remap the PD0 and PD1 functionality by software on these pins and configure the PD0/PD1 to Output push-pull forced to 0 logic level(Data Register = 0). This will maintain those I/Os to a fixed level minimizing Noise and external stress on these pins.

     The software configuration is recommended to reduce the power consumption and saves cost by avoiding the use of external pull down resistors as the I/O is already connected to the ground internally. Whereas the hardware configuration is recommended to increase the EMC performance.

STM32中如何使用PC14和PC15
     在STM32的數(shù)據(jù)手冊(cè)的管腳分配圖中可以看到:PC14與OSC32_IN公用一個(gè)引腳,PC15與OSC32_OUT公用一個(gè)引腳,它們的使用方法如下:
當(dāng)LSE(低速外部時(shí)鐘信號(hào))開啟時(shí),這兩個(gè)公用管腳的功能是OSC32_IN和OSC32_OUT。
當(dāng)LSE(低速外部時(shí)鐘信號(hào))關(guān)閉時(shí)這兩個(gè)公用管腳的功能是PC14和PC15。
    備用區(qū)域控制寄存器(RCC_BDCR)的LSEON用于控制LSE的開啟或關(guān)閉。關(guān)于這個(gè)寄存器的用法請(qǐng)參看《STM3210x技術(shù)參考手冊(cè)》。
--------------------------------------------------------------------------------
作為GPIO輸出的配置過程:
(1).使能GPIOC時(shí)鐘
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

(2).配置GPIOC
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOC, &GPIO_InitStructure);
(3).然后寫高寫低
  GPIO_WriteBit(GPIOC, GPIO_Pin_14, Bit_SET);
   GPIO_WriteBit(GPIOC, GPIO_Pin_15, Bit_SET);
   GPIO_WriteBit(GPIOC, GPIO_Pin_14, Bit_RESET);
   GPIO_WriteBit(GPIOC, GPIO_Pin_15, Bit_RESET);
     以上代碼跑在兩個(gè)板子上,一個(gè)是backup區(qū)域里的RCC_DBCR的LSEON為0,即LSE關(guān)閉,以上(3)的操作從示波器上看到了電平相應(yīng)變換;另外一個(gè)板子,backup區(qū)域里的RCC_DBCR的LSEON為1,即LSE打開,則以上(3)的操作從示波器上看到無效。
--------------------------------------------------------------------------------
作為GPIO輸入的配置過程:
  只是把以上的(2)稍微改一下,(3)就不用了
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOC, &GPIO_InitStructure);
   外部連接為:在PC14引腳焊了一個(gè)電阻,電阻另一端通過跳線在上拉到3.3V和下拉到地的兩種情況下,讀出GPIOC_IDR.14分別為"1"和"0"。
--------------------------------------------------------------------------------
作為外部中斷輸入的配置過程:
1.時(shí)鐘使能
// + osc32_in/out --> pc14/15
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC |RCC_APB2Periph_AFIO, ENABLE);
   注意要使能AFIO的時(shí)鐘哦
2.中斷配置

  // + for EXTI on PC.14 at falling edge

   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
   NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);
3. GPIO配置同上
4. EXTI配置
// + for PC14 EXTI @ falling edge
   GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource14);
   EXTI_InitStructure.EXTI_Line = EXTI_Line14;
   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
   EXTI_Init(&EXTI_InitStructure);
5. 中斷處理ISR
void EXTI15_10_IRQHandler(void)
{
   if(EXTI_GetITStatus(EXTI_Line14) != RESET)
   {

     EXTI_ClearITPendingBit(EXTI_Line14);
   }
}
     在中斷處設(shè)置斷點(diǎn),只要按下key,就進(jìn)入中斷,跑出中斷,再按key,再次進(jìn)入,屢試不爽,試驗(yàn)完成~~~


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表