打印
[Cortex-M0技术交流]

LPC1114的多个GPIO同时输出us级波形情况

[复制链接]
2245|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 狂的风雨 于 2012-12-18 23:21 编辑

本人最近接触LPC1114单片机,发现多个GPIO口同时做输出,且us级波形时一直出现异常,波形如下:




源码主要是:
1)void SystemInit ()是system_LPC11xx.c中自带的,外边晶振为12MHz。
2)GPIO口的初始化主要是如下
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6);       /* 初始化GPIO AHB时钟         */
/*PD0-PD2,PCLR引脚*/
LPC_IOCON->JTAG_TDO_PIO1_1 &= ~0x07;         /* 将P1.1初始化为GPIO功能     */
LPC_IOCON->JTAG_TDO_PIO1_1 |= 0x01;

LPC_IOCON->JTAG_TMS_PIO1_0 &= ~0x07;         /* 将P1.0初始化为GPIO功能      */
LPC_IOCON->JTAG_TMS_PIO1_0 |= 0x01;


LPC_IOCON->JTAG_TDI_PIO0_11 &= ~0x07;        /* 将P0.11初始化为GPIO功能     */
LPC_IOCON->JTAG_TDI_PIO0_11 |= 0x01;


/*设置PD0-PD2,PCLR(DD)如图为输出口*/
GPIOSetDir(1,1,1);         /* 将P1.1设置为输出口    PD0   */
GPIOSetDir(1,0,1);         /* 将P1.0设置为输出口    PD1   */
GPIOSetDir(0,11,1);         /* 将P0.11设置为输出口  PD2    */
GPIOSetDir(2,11,1);         /* 将P2.11设置为输出口   DD   */

3)GPIOSetValue函数如下:
void GPIOSetValue( uint8_t portNum, uint8_t bitPosi, uint8_t bitVal )
{
  /* if bitVal is 1, the bitPosi bit is set in the GPIOShadowPortx. Then
   * GPIOShadowPortx is written to the I/O port register. */

  LPC_GPIO[portNum]->MASKED_ACCESS[(1<<bitPosi)] = (bitVal<<bitPosi);
  return;

}
4)main函数如下:
int main (void)
{
  /*系统初始化*/
  SystemInit();
/*通道板初始化*/
  GPIOInit();
while(1)
  {
/*PD0-PD2,PCLR输出值*/
GPIOSetValue(1,1,1);      
GPIOSetValue(1,0,1);        
GPIOSetValue(0,11,1);         
GPIOSetValue(2,11,0);
delay_us(500);
    GPIOSetValue(1,1,0);      
GPIOSetValue(1,0,0);        
GPIOSetValue(0,11,0);         
GPIOSetValue(2,11,1);
delay_us(500);
  };
}

注:该工程仅完成如上4个IO口的输出,且没有使用IO中断。
如上图所示,当延时时间越长输出的波形看不出来异常,但当延时时间为20us-10us 甚至更小时就会出现混乱。
分析代码没发现逻辑问题,就是一直找不到原因。请问各路大侠们有没遇到,怎么解决的,谢谢回复!
以下是我用的system_LPC11xx.c
#include <stdint.h>
#include "LPC11xx.h"


#define CLOCK_SETUP           1
#define MAIN_PLL_SETUP        1
#define MAIN_CLKSRCSEL_Val    0x00000001
#define MAIN_PLL_M_Val        0x00000003
#define MAIN_PLL_P_Val        0x00000001
#define SYS_AHB_DIV_Val       1   /* 1 through 255, typical is 1 or 2 or 4 */

/*
//-------- <<< end of configuration section >>> ------------------------------
*/

/*----------------------------------------------------------------------------
  DEFINES
*----------------------------------------------------------------------------*/
   
/*----------------------------------------------------------------------------
  Define clocks
*----------------------------------------------------------------------------*/
#define XTAL        (12000000UL)        /* Oscillator frequency               */
#define OSC_CLK     (      XTAL)        /* Main oscillator frequency          */
#define IRC_OSC     ( 4000000UL)        /* Internal RC oscillator frequency   */
#define WDT_OSC     (  250000UL)        /* WDT oscillator frequency           */

/*----------------------------------------------------------------------------
  Clock Variable definitions
*----------------------------------------------------------------------------*/
uint32_t ClockSource = IRC_OSC;
uint32_t SystemFrequency = IRC_OSC; /*!< System Clock Frequency (Core Clock)  */
uint32_t SystemAHBFrequency = IRC_OSC;

/**
* Misc. clock generation modules
*
* @param  none
* @return none
*
* @brief  Setup the microcontroller system.
*         Initialize the System and update the SystemFrequency variable.
*/
void Main_PLL_Setup ( void )
{
  uint32_t regVal;

  ClockSource = OSC_CLK;
  LPC_SYSCON->SYSPLLCLKSEL = MAIN_CLKSRCSEL_Val;   /* Select system OSC */
  LPC_SYSCON->SYSPLLCLKUEN = 0x01;                 /* Update clock source */
  LPC_SYSCON->SYSPLLCLKUEN = 0x00;                 /* toggle Update register once */
  LPC_SYSCON->SYSPLLCLKUEN = 0x01;
  while ( !(LPC_SYSCON->SYSPLLCLKUEN & 0x01) ); /* Wait until updated */

  regVal = LPC_SYSCON->SYSPLLCTRL;
  regVal &= ~0x1FF;
  LPC_SYSCON->SYSPLLCTRL = (regVal | (MAIN_PLL_P_Val<<5) | MAIN_PLL_M_Val);
  
  /* Enable main system PLL, main system PLL bit 7 in PDRUNCFG. */
  LPC_SYSCON->;PDRUNCFG &= ~(0x1<<7);
  while ( !(LPC_SYSCON->SYSPLLSTAT & 0x01) ); /* Wait until it's locked */

  LPC_SYSCON->MAINCLKSEL = 0x03;  /* Select PLL clock output */
  LPC_SYSCON->MAINCLKUEN = 0x01;  /* Update MCLK clock source */
  LPC_SYSCON->MAINCLKUEN = 0x00;  /* Toggle update register once */
  LPC_SYSCON->MAINCLKUEN = 0x01;
  while ( !(LPC_SYSCON->MAINCLKUEN & 0x01) ); /* Wait until updated */

  LPC_SYSCON->SYSAHBCLKDIV = SYS_AHB_DIV_Val; /* SYS AHB clock, typical is 1 or 2 or 4 */
#if MAIN_PLL_SETUP
  SystemFrequency = ClockSource * (MAIN_PLL_M_Val+1);
#else
  SystemFrequency = ClockSource;
#endif
  SystemAHBFrequency = (uint32_t)(SystemFrequency/SYS_AHB_DIV_Val);
  return;
}

/**
* Initialize the system
*
* @param  none
* @return none
*
* @brief  Setup the microcontroller system.
*         Initialize the System and update the SystemFrequency variable.
*/
void SystemInit (void)
{
  uint32_t i;

#ifdef __DEBUG_RAM   
  LPC_SYSCON->SYSMEMREMAP = 0x1;  /* remap to internal RAM */
#else
#ifdef __DEBUG_FLASH   
  LPC_SYSCON->SYSMEMREMAP = 0x2;  /* remap to internal flash */
#endif
#endif

#if (CLOCK_SETUP)                       /* Clock Setup */
  /* bit 0 default is crystal bypass,
  bit1 0=0~20Mhz crystal input, 1=15~50Mhz crystal input. */
  LPC_SYSCON->SYSOSCCTRL = 0x00;

  /* main system OSC run is cleared, bit 5 in PDRUNCFG register */
  LPC_SYSCON->;PDRUNCFG &= ~(0x1<<5);
  /* Wait 200us for OSC to be stablized, no status
  indication, dummy wait. */
  for ( i = 0; i < 0x100; i++ );

#if (MAIN_PLL_SETUP)
  Main_PLL_Setup();  
#endif

#endif /* endif CLOCK_SETUP */
  /* System clock to the IOCON needs to be enabled or
  most of the I/O related peripherals won't work. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16);
  return;
}


相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

1

帖子

0

粉丝