Andrew Boyson / motorhome

Dependencies:   net lpc1768 crypto clock web fram log

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers periphs.c Source File

periphs.c

00001 #define PCONP       (*((volatile unsigned *) 0x400FC0C4))
00002 #define PCLKSEL0    (*((volatile unsigned *) 0x400FC1A8))
00003 #define PCLKSEL1    (*((volatile unsigned *) 0x400FC1AC))
00004 #define PINSEL0     (*((volatile unsigned *) 0x4002C000))
00005 #define PINSEL1     (*((volatile unsigned *) 0x4002C004))
00006 #define PINSEL2     (*((volatile unsigned *) 0x4002C008))
00007 #define PINSEL3     (*((volatile unsigned *) 0x4002C00C))
00008 #define PINSEL4     (*((volatile unsigned *) 0x4002C010))
00009 #define PINMODE0    (*((volatile unsigned *) 0x4002C040))
00010 #define PINMODE4    (*((volatile unsigned *) 0x4002C050))
00011 #define PINMODE_OD0 (*((volatile unsigned *) 0x4002C068))
00012 #define PINMODE_OD1 (*((volatile unsigned *) 0x4002C06C))
00013 #define PINMODE_OD2 (*((volatile unsigned *) 0x4002C070))
00014 
00015 void PeriphsInit (void)
00016 {
00017     //Peripheral power - Table 46
00018     PCONP  = 0;
00019     PCONP |= 1 <<  1; //TIMER0
00020     PCONP |= 1 <<  2; //TIMER1
00021     PCONP |= 1 <<  3; //UART0
00022     PCONP |= 1 <<  6; //PWM1
00023     PCONP |= 1 <<  9; //RTC
00024     PCONP |= 1 << 10; //SSP1
00025     PCONP |= 1 << 14; //PCCAN2
00026     PCONP |= 1 << 15; //GPIO
00027     PCONP |= 1 << 16; //RIT
00028     PCONP |= 1 << 19; //I2C1
00029     PCONP |= 1 << 30; //ENET                 
00030 
00031     //Peripheral clock must be selected before PLL0 enabling and connecting; default is 00 divide by 4; need 01 to have divide by 1
00032     PCLKSEL0  = 0;
00033     PCLKSEL0 |= 1 <<  2;  //TIM0
00034     PCLKSEL0 |= 1 <<  4;  //TIM1
00035     PCLKSEL0 |= 1 <<  6;  //UART0
00036     PCLKSEL0 |= 1 << 12;  //PWM1
00037     PCLKSEL0 |= 1 << 20;  //SSP1
00038     
00039     PCLKSEL1  = 0;
00040     PCLKSEL1 |= 1 << 20; //I2C1
00041 
00042     //Pin functions table 80.
00043     PINSEL0  = 0;
00044     PINSEL0 |= 3U <<  0; //P0.00 11 SDA1   I2C1
00045     PINSEL0 |= 3U <<  2; //P0.01 11 SCL1   I2C1
00046     PINSEL0 |= 1U <<  4; //P0.02 01 TXD0  UART0
00047     PINSEL0 |= 1U <<  6; //P0.03 01 RXD0  UART0
00048     PINSEL0 |= 2U <<  8; //P0.04 11 RD2  PCCAN2
00049     PINSEL0 |= 2U << 10; //P0.05 11 TD2  PCCAN2
00050     PINSEL0 |= 2U << 14; //P0.07 10 SCK1   SSP1
00051     PINSEL0 |= 2U << 16; //P0.08 10 MISO1  SSP1
00052     PINSEL0 |= 2U << 18; //P0.09 10 MOSI1  SSP1
00053     
00054     PINSEL1  = 0;
00055 
00056     PINSEL2  = 0;
00057     PINSEL2 |= 1U <<  0; //P1.00 01 ENET_TXD0
00058     PINSEL2 |= 1U <<  2; //P1.01 01 ENET_TXD1
00059     PINSEL2 |= 1U <<  8; //P1.04 01 ENET_TX_EN
00060     PINSEL2 |= 1U << 16; //P1.08 01 ENET_CRS
00061     PINSEL2 |= 1U << 18; //P1.09 01 ENET_RXD0
00062     PINSEL2 |= 1U << 20; //P1.10 01 ENET_RXD1
00063     PINSEL2 |= 1U << 28; //P1.14 01 ENET_RX_ER
00064     PINSEL2 |= 1U << 30; //P1.15 01 ENET_REF_CLK
00065     
00066     PINSEL3  = 0;
00067     PINSEL3 |= 1U <<  0; //P1.16 01 ENET_MDC
00068     PINSEL3 |= 1U <<  2; //P1.17 01 ENET_MDIO
00069     
00070     PINSEL4  = 0;
00071     PINSEL4 |= 1U << 0;  //P2.00 01 PWM1.1
00072     
00073     PINMODE0  = 0;
00074     PINMODE0 |= 2U << 0; //P0.00 10 SDA1    I2C1 Neither pull up nor pull down
00075     PINMODE0 |= 2U << 2; //P0.01 10 SCL1    I2C1 Neither pull up nor pull down
00076     
00077     PINMODE_OD0  = 0;
00078     PINMODE_OD0 |= 1 << 0; //P0.00 10 SDA1    I2C1 Open drain mode
00079     PINMODE_OD0 |= 1 << 1; //P0.01 10 SCL1    I2C1 Open drain mode
00080 }