LPC1769.. gpio stops working after configuring external clock.

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

LPC1769.. gpio stops working after configuring external clock.

386 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by baot on Sun Mar 08 06:49:21 MST 2015
If i dont call setclk from main, iam able to toggle GPIO 2:1.
But if i chose to run setclk we cant toggle GPIO 2:1, but we can still step though the code with instruction stepping.
Any ides of what iam doing wrong in setclk?

edit: i have tested not to activate pwm1 peripheral clock

regards baot

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#define XTAL (12000000UL) /* Oscillator frequency */
#define OSC_CLK ( XTAL) /* Main oscillator frequency */

#include <cr_section_macros.h>

// TODO: insert other include files here

// TODO: insert other definitions and declarations here

int SystemFrequency;
void setclk(void){
LPC_SC->SCS = 0x20;
while ((LPC_SC->SCS & (1<<6))==0);
//Clkdiv, divide by 4
LPC_SC->CCLKCFG = 0x00000003;

// Timer0,Uart0,PWM1,I2C0,SPI,ADC
LPC_SC->PCLKSEL0 = 0x1015044; //0b01000000010101000001000100 PCLKSEL1
//External Clock
LPC_SC->CLKSRCSEL = 0x00000001;

LPC_SC->PLL0CFG = 0x00020033; /* MSEL0 = 51 , NSEL0 = 2 */
//Updating PLL Config
LPC_SC->PLL0CON = 0x01;
//Feed Sequence
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
//Waiting for PLL update
while (!(LPC_SC->PLL0STAT & (1<<26)));
//Connect PLL
LPC_SC->PLL0CON = 0x03;
//Feed Sequence
LPC_SC->PLL0FEED = 0xAA;
LPC_SC->PLL0FEED = 0x55;
//Dont Used
LPC_SC->USBCLKCFG = 0x00000000;
//Power Control dont used
LPC_SC->PCONP = 0x00000000;

//LPC_SC->CLKOUTCFG = 0x000000C0;

LPC_SC->FLASHCFG = (0b100)<<12;

SystemFrequency = (OSC_CLK *
(((2 * ((LPC_SC->PLL0STAT & 0x7FFF) + 1))) /
(((LPC_SC->PLL0STAT >> 16) & 0xFF) + 1)) /
((LPC_SC->CCLKCFG & 0xFF)+ 1));




}
int main(void) {

    // Force the counter to be placed into memory
    volatile static int i = 0 ;
    setclk();
    // Enter an infinite loop, just incrementing a counter
    LPC_GPIO2->FIODIR = 1;
    LPC_GPIO2->FIOMASK = 0;
    while(1) {
    //LPC_GPIO0->DATA ^= (1<<7);
    LPC_GPIO2->FIOSET = 1;
        LPC_GPIO2->FIOCLR = 1;
    i++ ;

    }
    return 0 ;
}
Labels (1)
0 Kudos
2 Replies

338 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by baot on Mon Mar 09 05:33:01 MST 2015
Our problem was that i turned of the power for the peripherals. with
LPC_SC->PCONP = 0x00000000;
removed that row and everything is fine !
0 Kudos

338 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Mar 08 07:35:52 MST 2015

Quote: baot
Any ides of what iam doing wrong ?



Which toolchain are you using?

Is there a SystemInit(), Chip_SystemInit() or Board_SystemInit() executed before ?

If so, change you clock setup there  :)
0 Kudos