#include /* for EnableInterrupts macro */ #include "derivative.h" /* include peripheral declarations */ void cpmu_init(void); void delay(long int time); int gSPI; void write_spi(int data); void read_spi(void); void spi0init(void); int tx = 'a'; void cpmu_init(void) { // Wait for stable supply after power up while (GDUF_GLVLSF) GDUF_GLVLSF = 1; CPMUREFDIV_REFDIV = 7; // 8MHz => 2MHz CPMUREFDIV_REFFRQ = 0; // 0 for 1MHz - 2MHz CPMUSYNR_SYNDIV = 49; // 100 MHz VCO output CPMUSYNR_VCOFRQ = 1; CPMUPOSTDIV_POSTDIV = 0; // 100MHz CPMUCLKS_PLLSEL = 1; //PLL Select Bit CPMUOSC_OSCE = 1; CPMUVREGCTL_INTXON = 0; // Internal VDDX regulator off CPMUVREGCTL_EXTXON = 1; // External VDDX regulator on CPMUHTCTL_VSEL = 0; //Voltage Access Select Bit CPMUHTCTL_HTE = 1; //High Temperature Sensor/Bandgap Voltage Enable Bit // Wait for oscillator to start up (UPOSC=1) and PLL to lock (LOCK=1). while (CPMUIFLG_UPOSC == 0) {}; while (CPMUIFLG_LOCK == 0) {}; CPMURFLG = 0x60; //Clear PORF and LVRF } void delay(long int time) { while(time>0){--time;} } void read_spi(void){ while(!SPI0SR_SPIF){}; gSPI= SPI0DR; /* if(gSPI == 0x01){ LED_GREEN = 1; LED_RED = 0; } else if(gSPI == 0x02){ LED_GREEN = 0; LED_RED = 1; }*/ } void write_spi(int data){ while(!SPI0SR_SPTEF){}; SPI0DR = data; } void spi0init(void){ MODRR0_SPI0RR = 1; SPI0CR1 = 0x5E; SPI0CR2 = 0x50; SPI0BR = 0x77; } void main(void) { // EnableInterrupts; cpmu_init(); spi0init(); for(;;) { __RESET_WATCHDOG(); /* feeds the dog */ write_spi(tx); delay(3000); } /* loop forever */ /* please make sure that you never leave main */ }