How to use external crystal oscillator lpc11c24

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use external crystal oscillator lpc11c24

1,877 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by emielzij on Tue May 05 07:05:50 MST 2015
I want to use the external crystal with the lpc11c24 for critical timing applications.

I found some code to do that at: https://eewiki.net/display/microcontroller/Getting+Started+with+NXP%27s+LPC11XX+Cortex-M0+ARM+Microc...

The code is implemented as follows:

#include "LPC11xx.h"

int main(void) {
//CONNECT SYSTEM OSCILLATOR TO CLKOUT PIN: This allows measurement with o-scope.
LPC_IOCON->PIO0_1        &= 0xFFFFFFF8;       //clear FUNC bits (sec. 7.4.4)
LPC_IOCON->PIO0_1        |= 0x01;             //set FUNC bits to CLKOUT function (sec. 7.4.4)
LPC_GPIO0->DIR           |= 0x01;             //set CLKOUT pin to output (sec. 12.3.2)
LPC_SYSCON->CLKOUTCLKSEL = 0x3;               //sec. 3.5.21
LPC_SYSCON->CLKOUTUEN    = 0;                 //"CLKOUTUEN" has to be toggled for "CLKOTUCLKSEL" to accept the value written to it
LPC_SYSCON->CLKOUTUEN    = 1;                 //"CLKOUTUEN" has to be toggled for "CLKOTUCLKSEL" to accept the value written to it
LPC_SYSCON->CLKOUTDIV    = 1;                 //set divider to 1 (sec. 3.5.23)


 //USE EXTERNAL CRYSTAL TO GENERATE INTERNAL SYSTEM CLOCK
    LPC_SYSCON->SYSAHBCLKDIV             = 0x1;       //set clock divider for core to 1
    LPC_SYSCON->MAINCLKSEL               &= ~(0x03);  //set “main clock” to IRC oscillator, if not system will lock up when PLL turns off!(sec. 3.5.11)
    LPC_SYSCON->MAINCLKUEN               &= ~(1);     //write a zero to the MAINCLKUEN register (sec. 3.5.12), necessary for MAINCLKSEL to update
    LPC_SYSCON->MAINCLKUEN               |= 1;        //write a one to the MAINCLKUEN register (sec. 3.5.12), necessary for MAINCLKSEL to update
    LPC_SYSCON->SYSPLLCLKSEL             = 0x01;      //connect system oscillator to SYSTEM PLL (sec. 3.5.9)
    LPC_SYSCON->SYSPLLCLKUEN             &= ~(1);     //write a zero to SYSPLLUEN register (sec. 3.5.10), necessary for SYSPLLCLKSEL to update
    LPC_SYSCON->SYSPLLCLKUEN             |= 1;        //write a one to SYSPLLUEN register (sec. 3.5.10), necessary for SYSPLLCLKSEL to update
    LPC_SYSCON->PDRUNCFG                 |= (1<<7);   //power down the PLL before changing divider values (sec 3.5.35)
    LPC_SYSCON->SYSPLLCTRL               = 0x23;      //set MSEL = 0x00011 and PSEL = 0x01 (sec 3.5.3 and table 46 of sec. 3.11.4.1)
    LPC_SYSCON->PDRUNCFG                 &= ~(1<<7);  //power up PLL after divider values changed (sec. 3.5.35)
    while((LPC_SYSCON->SYSPLLSTAT & 1) == 0);         //wait for PLL to lock
    LPC_SYSCON->MAINCLKSEL               = 0x03;      //set system oscillator to the output of the PLL (sec. 3.5.11)
    LPC_SYSCON->MAINCLKUEN               &= ~(1);     //write a zero to the MAINCLKUEN register (sec. 3.5.12), necessary for MAINCLKSEL to update
    LPC_SYSCON->MAINCLKUEN               |= 1;        //write a one to the MAINCLKUEN register (sec. 3.5.12)

     LPC_IOCON->PIO0_7           &= ~(0x10);    //NOT REQUIRED, turn off pull up (sec 7.4.19)
     LPC_GPIO0->DIR              |= (1<<7);     //set pin direction to output (sec 12.3.2)
     unsigned int i = 0;

     while(1){                      //infinite loop

          LPC_GPIO0->DATA           |= (1<<7);    //set pin high (sec 12.3.1)
          for(i=0; i<0xFFFFF; ++i);               //arbitrary delay
          LPC_GPIO0->DATA           &= ~(1<<7);   //set pin low (sec 12.3.1)
          for(i=0; i<0xFFFFF; ++i);               //arbitrary delay

     }
      return 0 ;
}


But the led is not blinking if this code is running. Also there is no clock signal on the 0_1 pin.
If the part of the code where the external crystal is configured is exclude from the code, the led blinks normally and I measure the correct clock frequency of 48MHz at PIO0_1.
0 Kudos
14 Replies

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by emielzij on Thu May 07 12:47:28 MST 2015
Thank you, I am able to program the developmentboard again :)

Uploaded the same code but somehow it didn't lock up this time  :~ Although I cleaned some typedef structs in the mean time...

But the code isn't doing what I am expecting.
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu May 07 12:22:00 MST 2015
Then boot into ISP  :O
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by emielzij on Thu May 07 12:18:22 MST 2015

Quote: [b
R2D2[/b]]That depends how fast you are...



About 30 minutes... 


I ended up with the following code:

#include "LPC11xx.h"

typedef struct {/*!< SYSCTL Structure */
__IO uint32_t  SYSMEMREMAP;/*!< System Memory remap register */
__IO uint32_t  PRESETCTRL;/*!< Peripheral reset Control register */
__IO uint32_t  SYSPLLCTRL;/*!< System PLL control register */
__I  uint32_t  SYSPLLSTAT;/*!< System PLL status register */
__IO uint32_t  USBPLLCTRL;/*!< USB PLL control register, LPC11UXX only*/
__I  uint32_t  USBPLLSTAT;/*!< USB PLL status register, LPC11UXX only */
__I  uint32_t  RESERVED1[2];
__IO uint32_t  SYSOSCCTRL;/*!< System Oscillator control register */
__IO uint32_t  WDTOSCCTRL;/*!< Watchdog Oscillator control register */
__IO uint32_t  IRCCTRL;/*!< IRC control register, not on LPC11UXX and LPC11EXX */
__IO uint32_t  LFOSCCTRL;/*!< LF oscillator control, LPC11AXX only */
__IO uint32_t  SYSRSTSTAT;/*!< System Reset Status register           */
__I  uint32_t  RESERVED2[3];
__IO uint32_t  SYSPLLCLKSEL;/*!< System PLL clock source select register */
__IO uint32_t  SYSPLLCLKUEN;/*!< System PLL clock source update enable register*/
__IO uint32_t  USBPLLCLKSEL;/*!< USB PLL clock source select register, LPC11UXX only */
__IO uint32_t  USBPLLCLKUEN;/*!< USB PLL clock source update enable register, LPC11UXX only */
__I  uint32_t  RESERVED3[8];
__IO uint32_t  MAINCLKSEL;/*!< Main clock source select register*/
__IO uint32_t  MAINCLKUEN;/*!< Main clock source update enable register*/
__IO uint32_t  SYSAHBCLKDIV;/*!< System Clock divider register */
__I  uint32_t  RESERVED4;
__IO uint32_t  SYSAHBCLKCTRL;/*!< System clock control register */
__I  uint32_t  RESERVED5[4];
__IO uint32_t  SSP0CLKDIV;/*!< SSP0 clock divider register   */
__IO uint32_t  USARTCLKDIV;/*!< UART clock divider register   */
__IO uint32_t  SSP1CLKDIV;/*!< SSP1 clock divider register, not on CHIP_LPC110X, CHIP_LPC11XXLV */
__I  uint32_t  RESERVED6[8];
__IO uint32_t  USBCLKSEL;/*!< USB clock source select register, LPC11UXX only */
__IO uint32_t  USBCLKUEN;/*!< USB clock source update enable register, LPC11UXX only */
__IO uint32_t  USBCLKDIV;/*!< USB clock source divider register, LPC11UXX only */
__I  uint32_t  RESERVED7;
__IO uint32_t  WDTCLKSEL;/*!< WDT clock source select register, some parts only */
__IO uint32_t  WDTCLKUEN;/*!< WDT clock source update enable register, some parts only */
__IO uint32_t  WDTCLKDIV;/*!< WDT clock divider register, some parts only */
__I  uint32_t  RESERVED8;
__IO uint32_t  CLKOUTSEL;/*!< Clock out source select register, not on LPC1102/04 */
__IO uint32_t  CLKOUTUEN;/*!< Clock out source update enable register, not on LPC1102/04 */
__IO uint32_t  CLKOUTDIV;/*!< Clock out divider register, not on LPC1102/04 */
__I  uint32_t  RESERVED9[5];
__I  uint32_t  PIOPORCAP[2];/*!< POR captured PIO status registers, index 1 on LPC1102/04 */
__I  uint32_t  RESERVED10[18];
__IO uint32_t  BODCTRL;/*!< Brown Out Detect register */
__IO uint32_t  SYSTCKCAL;/*!< System tick counter calibration register */
__I  uint32_t  RESERVED11[6];
__IO uint32_t  IRQLATENCY;/*!< IRQ delay register, on LPC11UXX and LPC11EXX only */
__IO uint32_t  NMISRC;/*!< NMI source control register,some parts only */
__IO uint32_t  PINTSEL[8];/*!< GPIO pin interrupt select register 0-7, not on CHIP_LPC110X, CHIP_LPC11XXLV, CHIP_LPC11CXX */
__IO uint32_t  USBCLKCTRL;/*!< USB clock control register, LPC11UXX only */
__I  uint32_t  USBCLKST;/*!< USB clock status register, LPC11UXX only */
__I  uint32_t  RESERVED12[24];
__IO uint32_t  STARTAPRP0;/*!< Start loigc 0 interrupt wake up enable register 0, on CHIP_LPC110X, CHIP_LPC11XXLV, CHIP_LPC11CXX */
__IO uint32_t  STARTERP0;/*!< Start loigc signal enable register 0, not on LPC11AXX */
__IO uint32_t  STARTRSRP0CLR;/*!< Start loigc reset register 0, on CHIP_LPC110X, CHIP_LPC11XXLV, CHIP_LPC11CXX */
__IO uint32_t  STARTSRP0;/*!< Start loigc status register 0, on CHIP_LPC110X, CHIP_LPC11XXLV, CHIP_LPC11CXX */
__I  uint32_t  RESERVED13;
__IO uint32_t  STARTERP1;/*!< Start logic 1 interrupt wake up enable register 1, on LPC11UXX and LPC11EXX only */
__I  uint32_t  RESERVED14[6];
__IO uint32_t  PDSLEEPCFG;/*!< Power down states in deep sleep mode register, not on LPC11AXX */
__IO uint32_t  PDWAKECFG;/*!< Power down states in wake up from deep sleep register, not on LPC11AXX */
__IO uint32_t  PDRUNCFG;/*!< Power configuration register*/

} LPC_SYSCTL_T;

typedef struct {/*!< FMC Structure */
__I  uint32_t  RESERVED1[4];
__IO uint32_t  FLASHTIM;
__I  uint32_t  RESERVED2[3];
__IO uint32_t  FMSSTART;
__IO uint32_t  FMSSTOP;
__I  uint32_t  RESERVED3;
__I  uint32_t  FMSW[4];
__I  uint32_t  RESERVED4[25];
#if defined(CHIP_LPC1125)
__I  uint32_t  RESERVED5[977];
#else
__IO uint32_t  EEMSSTART;
__IO uint32_t  EEMSSTOP;
__I  uint32_t  EEMSSIG;
__I  uint32_t  RESERVED5[974];
#endif
__I  uint32_t  FMSTAT;
__I  uint32_t  RESERVED6;
__O  uint32_t  FMSTATCLR;
} LPC_FMC_T;

#define LPC_SYSCTL                ((LPC_SYSCTL_T           *) 0x40048000)
#define LPC_FMC                   ((LPC_FMC_T              *) LPC_FLASH_BASE)

typedef enum CHIP_SYSCTL_PLLCLKSRC {
SYSCTL_PLLCLKSRC_IRC = 0,/*!< Internal oscillator in */
SYSCTL_PLLCLKSRC_MAINOSC,/*!< Crystal (main) oscillator in */
#if defined(CHIP_LPC11AXX)
SYSCTL_PLLCLKSRC_EXT_CLKIN,/*!< External clock in (11Axx only) */
#else
SYSCTL_PLLCLKSRC_RESERVED1,/*!< Reserved */
#endif
SYSCTL_PLLCLKSRC_RESERVED2,/*!< Reserved */
} CHIP_SYSCTL_PLLCLKSRC_T;

typedef enum CHIP_SYSCTL_MAINCLKSRC {
SYSCTL_MAINCLKSRC_IRC = 0,/*!< Internal oscillator */
SYSCTL_MAINCLKSRC_PLLIN,/*!< System PLL input */
SYSCTL_MAINCLKSRC_LFOSC,/*!< LF oscillator rate (11Axx only) */
SYSCTL_MAINCLKSRC_WDTOSC = SYSCTL_MAINCLKSRC_LFOSC,/*!< Watchdog oscillator rate */
SYSCTL_MAINCLKSRC_PLLOUT,/*!< System PLL output */
} CHIP_SYSCTL_MAINCLKSRC_T;


void SystemSetupClocking(void)
{
volatile int i;

/* Powerup main oscillator */
uint32_t pdrun;

pdrun = LPC_SYSCTL->PDRUNCFG & 0x000000FF;
pdrun &= ~((1 << 5) & 0x000000FF);

LPC_SYSCTL->PDRUNCFG = (pdrun | 0x0000ED00);


/* Wait 200us for OSC to be stablized, no status
   indication, dummy wait. */
for (i = 0; i < 0x100; i++) {}


/* Set system PLL input to main oscillator */
LPC_SYSCTL->SYSPLLCLKSEL  = (uint32_t) SYSCTL_PLLCLKSRC_MAINOSC;
LPC_SYSCTL->SYSPLLCLKUEN  = 0;
LPC_SYSCTL->SYSPLLCLKUEN  = 1;


/* Power down PLL to change the PLL divider ratio */
uint32_t pdrun2;

pdrun2 = LPC_SYSCTL->PDRUNCFG & 0x000000FF;
pdrun2 |= ((1 << 7) & 0x000000FF);

LPC_SYSCTL->PDRUNCFG = (pdrun2 | 0x0000ED00);


/* Setup PLL for main oscillator rate (FCLKIN = 12MHz) * 4 = 48MHz
   MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2)
   FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz
   FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */
LPC_SYSCTL->SYSPLLCTRL = (3 & 0x1F) | ((1 & 0x3) << 5);


/* Powerup system PLL */
uint32_t pdrun3;

pdrun3 = LPC_SYSCTL->PDRUNCFG & 0x000000FF;
pdrun3 &= ~((1 << 7) & 0x000000FF);

LPC_SYSCTL->PDRUNCFG = (pdrun3 | 0x0000ED00);


/* Wait for PLL to lock */
while (!((LPC_SYSCTL->SYSPLLSTAT & 1) != 0)) {}


/* Set system clock divider to 1 */
LPC_SYSCTL->SYSAHBCLKDIV  = 1;


/* Setup FLASH access to 3 clocks */
uint32_t tmp = LPC_FMC->FLASHTIM & (~(0x3));


/* Don't alter upper bits */
LPC_FMC->FLASHTIM = tmp | 2;


/* Set main clock source to the system PLL. This will drive 48MHz
   for the main clock and 48MHz for the system clock */
LPC_SYSCTL->MAINCLKSEL  = (uint32_t) SYSCTL_MAINCLKSRC_PLLOUT;
LPC_SYSCTL->MAINCLKUEN  = 0;
LPC_SYSCTL->MAINCLKUEN  = 1;
}




int main(void) {
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6);

SystemSetupClocking();

//Toggle a GPIO (FBD48 pin 23, PIO0_7, controls the LED on the LPC Expresso PCB)
//CONNECT SYSTEM OSCILLATOR TO CLKOUT PIN: This allows measurement with o-scope.
LPC_IOCON->PIO0_1        &= 0xFFFFFFF8;       //clear FUNC bits (sec. 7.4.4)
LPC_IOCON->PIO0_1        |= 0x01;             //set FUNC bits to CLKOUT function (sec. 7.4.4)
LPC_GPIO0->DIR           |= 0x01;             //set CLKOUT pin to output (sec. 12.3.2)
LPC_SYSCON->CLKOUTCLKSEL = 0x3;               //sec. 3.5.21
LPC_SYSCON->CLKOUTUEN    = 0;                 //"CLKOUTUEN" has to be toggled for "CLKOTUCLKSEL" to accept the value written to it
LPC_SYSCON->CLKOUTUEN    = 1;                 //"CLKOUTUEN" has to be toggled for "CLKOTUCLKSEL" to accept the value written to it
LPC_SYSCON->CLKOUTDIV    = 1;                 //set divider to 1 (sec. 3.5.23)

     LPC_IOCON->PIO0_7           &= ~(0x10);    //NOT REQUIRED, turn off pull up (sec 7.4.19)
     LPC_GPIO0->DIR              |= (1<<7);     //set pin direction to output (sec 12.3.2)
     unsigned int i = 0;

     while(1){                      //infinite loop
          LPC_GPIO0->DATA           |= (1<<7);    //set pin high (sec 12.3.1)
          for(i=0; i<0xFFFFF; ++i);               //arbitrary delay
          LPC_GPIO0->DATA           &= ~(1<<7);   //set pin low (sec 12.3.1)
          for(i=0; i<0xFFFFF; ++i);               //arbitrary delay
     }
      return 0 ;
}



Most likely it can be a lot shorter, but it is still shorter than the complete libary. Unfortunately it didn't work (have no idea way, I worked very careful  ). But now I ended up locking the development board, a "02: Failed on connect: Em(020. MEMP-AP is not selected." popped up...

Ni: LPCXpresso Debug Driver v7.5 (Oct 21 2014 12:21:44 - crt_emu_lpc11_13_nxp.exe build 26)
Pc: (  0) Reading remote configuration
Pc: (  5) Remote configuration complete
Ed:02: Failed on connect: Em(02). MEM-AP is not selected.
Et: Emu(0): Conn&Reset. Was: None. DpID:  BB11477. Info: WIN64HS12
Error 0: (null)
Last sticky: 0. AIndex: 0
No MemAp selected
No Speed test
SWD Frequency: 250 KHz. RTCK: False. Vector catch: False.
Packet delay: 0  Poll delay: 0.
Pc: (100) Target Connection Failed
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Thu May 07 10:44:46 MST 2015

Quote: emielzij
Would it be a lot of work to track down all the functions in SystemSetupClocking to register level and then implement the code without using the board libary?



That depends how fast you are...
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by emielzij on Thu May 07 10:32:12 MST 2015
Yes, but I still need to include the board libary because of all the functions inside SystemSetupClocking. Would it be a lot of work to track down all the functions in SystemSetupClocking to register level and then implement the code without using the board libary?
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 05 15:40:25 MST 2015

Quote: emielzij
I need to change this in a lot of projects. Do you have any advice on how to fix this easy/fast?



It's a function  :O  Just add it wherever you want  :)



Quote: emielzij
...do you see why it doesn't work?



Because it's incomplete...
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by emielzij on Tue May 05 15:19:55 MST 2015
Ah I see. I tought I had to change something or add something to my main code, but the board libary itself is using the external crystal. It is now running properly :)

I need to change this in a lot of projects. Do you have any advice on how to fix this easy/fast? Because creating a new project (but now with the board libary) for every already existing project and then copying the files/code will not be the most efficient way I think?

A solution which looks nice to me would be a low level code which can be added to the main of the program which configures the external crystal. I don't use the board code for something else. Something like the code I found on the eewiki.net, but for some reason this code doesn't work, do you see why it doesn't work?
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 05 14:54:52 MST 2015

Quote: emielzij
But I don't get which part of SystemSetupClocking should be changed in order to use the external crystal...



:quest:

SystemSetupClocking is using the (external) crystal...


Quote: emielzij
Also somehow I prefer a low level implementation of this and ommit the board libary.



It's not necessary to use a board library, you can setup all important things yourself  :)


0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by emielzij on Tue May 05 14:11:45 MST 2015
I added board_lib to a new LPC_open project and found the code you where talking about.

But I don't get which part of SystemSetupClocking should be changed in order to use the external crystal...

Also somehow I prefer a low level implementation of this and ommit the board libary.

Thanks for you time.
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 05 11:00:38 MST 2015

Quote: emielzij
But I still don't see a straightforward way to use the external crystal. Can I get some help with which settings should be changed?



If you create a new LPCOpen project (with Board Library  ), your sysinit.c is using Board_SystemInit() 


/* Set up and initialize hardware prior to call to main */
void SystemInit(void)
{
#if defined(NO_BOARD_LIB)
/* Chip specific SystemInit */
Chip_SystemInit();
#else
/* Board specific SystemInit */
[color=#f00]Board_SystemInit();[/color]
#endif
}


And in board_sysinit.c you'll find:

/* Set up and initialize hardware prior to call to main */
void Board_SystemInit(void)
{
/* Setup system clocking and muxing */
[color=#f00]SystemSetupClocking();[/color]
SystemSetupMuxing();
}


and:


/* Setup system clocking */
STATIC void SystemSetupClocking(void)
{
volatile int i;

/* Powerup main oscillator */
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_SYSOSC_PD);

/* Wait 200us for OSC to be stablized, no status
   indication, dummy wait. */
for (i = 0; i < 0x100; i++) {}

/* Set system PLL input to main oscillator */
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_MAINOSC);

/* Power down PLL to change the PLL divider ratio */
Chip_SYSCTL_PowerDown(SYSCTL_POWERDOWN_SYSPLL_PD);

/* Setup PLL for main oscillator rate (FCLKIN = 12MHz) * 4 = 48MHz
   MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2)
   FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz
   FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */
Chip_Clock_SetupSystemPLL(3, 1);

/* Powerup system PLL */
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_SYSPLL_PD);

/* Wait for PLL to lock */
while (!Chip_Clock_IsSystemPLLLocked()) {}

/* Set system clock divider to 1 */
Chip_Clock_SetSysClockDiv(1);

/* Setup FLASH access to 3 clocks */
Chip_FMC_SetFLASHAccess(FLASHTIM_50MHZ_CPU);

/* Set main clock source to the system PLL. This will drive 48MHz
   for the main clock and 48MHz for the system clock */
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLOUT);
}


Now guess what's happening there 
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by emielzij on Tue May 05 10:52:04 MST 2015
void Chip_SystemInit(void)
{
/* IRC should be powered up */
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_IRC_PD);
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_IRCOUT_PD);

/* Set system PLL input to main oscillator */
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_IRC);

/* Power down PLL to change the PLL divider ratio */
Chip_SYSCTL_PowerDown(SYSCTL_POWERDOWN_SYSPLL_PD);

/* Setup PLL for main oscillator rate (FCLKIN = 12MHz) * 4 = 48MHz
   MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2)
   FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz
   FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) */
Chip_Clock_SetupSystemPLL(3, 1);

/* Powerup system PLL */
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_SYSPLL_PD);

/* Wait for PLL to lock */
while (!Chip_Clock_IsSystemPLLLocked()) {}

/* Set system clock divider to 1 */
Chip_Clock_SetSysClockDiv(1);

/* Setup FLASH access to 3 clocks */
Chip_FMC_SetFLASHAccess(FLASHTIM_50MHZ_CPU);

/* Set main clock source to the system PLL. This will drive 48MHz
   for the main clock and 48MHz for the system clock */
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLOUT);

/* Enable IOCON clock */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
}


There are indeed settings for the clock system

But I still don't see a straightforward way to use the external crystal. Can I get some help with which settings should be changed?
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 05 09:01:31 MST 2015

Quote: emielzij
I don't see any configuration options in sysint.c...



:quest:

And what's in your Chip_SystemInit()  :quest:  :O  :quest:
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by emielzij on Tue May 05 08:53:26 MST 2015
Attached the complete project.

I am using the LPCXpresso IDE.

I don't see any configuration options in sysint.c or should I copy the external osillator code to sysint.c?
0 Kudos

1,149 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue May 05 07:13:53 MST 2015
:quest:

Please post complete projects...

Which toolchain are you using? Why don't you switch in your SystemInit?
0 Kudos