#include "config.h" #include "printf.h" #define SPIPORT LPC_SPI0 #define SPI_FRAMELEN 15 static volatile uint32_t rxedData=0; void spiInit(void) { LPC_SYSCON->SYSAHBCLKCTRL |= (1<<11); // Enable SPI0 LPC_SYSCON->PRESETCTRL &= ~(1<<0); LPC_SYSCON->PRESETCTRL |= (1<<0);// Reset SPI0 LPC_SWM->PINASSIGN3=(LPC_SWM->PINASSIGN3&0x00FFFFFF)|(8<<24); // CLK on P0_8 LPC_SWM->PINASSIGN4=(LPC_SWM->PINASSIGN4&0xFF000000); LPC_SWM->PINASSIGN4|=(9<<16); LPC_SWM->PINASSIGN4|=(15<<8); // CS on P0_9, MISO on P0_15 LPC_SWM->PINASSIGN4|=(1<<0);// MOSI on P0_1 SPIPORT->DIV=1000; // Don't need anything too fast - there's not much else going on! SPIPORT->DLY=0; SPIPORT->CFG=0; SPIPORT->CFG=(1<<0)|(1<<2)|(1<<7); // Enabled, master mode, } // ============================================================================================ void spiGet_sample(void) { static uint32_t i=0; while (1) { // This will trigger a reception - we don't care about the sent data SPIPORT->TXDATCTL=i++|(SPI_FRAMELEN<<24)|(1<<20)|(1<<21); while (!(SPIPORT->STAT&1)); rxedData=SPIPORT->RXDAT; printf("%X\n",rxedData); } } |
#include "config.h" #include "flags.h" #include "uart.h" #include "printf.h" #ifdef SENSOR_THERMOCOUPLE #define SPIPORT LPC_SPI0 #define SPI_CLK 8 #define SPI_MISO 15 #define SPI_SEL 9 #define SPI_FRAMELEN 15 static volatile uint32_t rxedData=0; // ============================================================================================ void SPI0_IRQHandler(void) { rxedData=SPIPORT->RXDAT; uartPuti(rxedData,UART_BASE_HEX); flag_post(FLAG_GOTTEMP); } // ============================================================================================ // ============================================================================================ // ============================================================================================ // Externally available routines // ============================================================================================ // ============================================================================================ // ============================================================================================ void spiInit(void) { LPC_SYSCON->SYSAHBCLKCTRL |= (1<<11); // Enable SPI0 LPC_SYSCON->PRESETCTRL &= ~(1<<0); LPC_SYSCON->PRESETCTRL |= (1<<0);// Reset SPI0 LPC_SWM->PINASSIGN3=(LPC_SWM->PINASSIGN3&0x00FFFFFF)|(SPI_CLK<<24); LPC_SWM->PINASSIGN4=(LPC_SWM->PINASSIGN4&0xFF0000FF)|(SPI_SEL<<16)|(SPI_MISO<<8); SPIPORT->DIV=1000; // Don't need anything too fast - there's not much else going on! SPIPORT->DLY=0; SPIPORT->INTENSET=(1<<0); // Interrupt on RX data available NVIC_DisableIRQ(SPI0_IRQn); NVIC_ClearPendingIRQ(SPI0_IRQn); NVIC_EnableIRQ(SPI0_IRQn); SPIPORT->CFG=(1<<0)|(1<<2); // Enabled, master mode } // ============================================================================================ void spiGet_sample(void) { // This will trigger a reception - we don't care about the sent data SPIPORT->TXDATCTL=(SPI_FRAMELEN<<24)|(1<<20)|(1<<21); } // ============================================================================================ uint32_t spiResult(void) { return rxedData; } // ============================================================================================ #endif |