diff options
-rw-r--r-- | boards/EA_LPCXPRESSO_BB_1114/board.h | 1 | ||||
-rw-r--r-- | demos/ARMCM0-LPC1114-GCC/main.c | 19 | ||||
-rw-r--r-- | os/hal/platforms/LPC11xx/spi_lld.c | 8 |
3 files changed, 22 insertions, 6 deletions
diff --git a/boards/EA_LPCXPRESSO_BB_1114/board.h b/boards/EA_LPCXPRESSO_BB_1114/board.h index 59ec8a267..07966c527 100644 --- a/boards/EA_LPCXPRESSO_BB_1114/board.h +++ b/boards/EA_LPCXPRESSO_BB_1114/board.h @@ -78,6 +78,7 @@ #define GPIO1_SW4 4
#define GPIO1_LED3R 9
#define GPIO1_LED3G 10
+#define GPIO1_SPI0SEL 11
#ifdef __cplusplus
extern "C" {
diff --git a/demos/ARMCM0-LPC1114-GCC/main.c b/demos/ARMCM0-LPC1114-GCC/main.c index 45496acfc..5f47acf1c 100644 --- a/demos/ARMCM0-LPC1114-GCC/main.c +++ b/demos/ARMCM0-LPC1114-GCC/main.c @@ -21,14 +21,28 @@ #include "hal.h"
#include "test.h"
+
+/* Maximum speed SPI configuration (1MHz, CPHA=0, CPOL=0).*/
+static SPIConfig spicfg = {
+ NULL,
+ GPIO1,
+ GPIO1_SPI0SEL,
+ CR0_DSS8BIT | CR0_FRFSPI | CR0_CLOCKRATE(0),
+ 0,
+ 48
+};
+
/*
* Red LED blinker thread, times are in milliseconds.
*/
static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) {
+ uint8_t digit = 0;
(void)arg;
while (TRUE) {
+ spiStartSend(&SPID1, 1, &digit);
+ digit++;
palClearPad(GPIO0, GPIO0_LED2);
chThdSleepMilliseconds(500);
palSetPad(GPIO0, GPIO0_LED2);
@@ -78,9 +92,10 @@ int main(int argc, char **argv) { (void)argv;
/*
- * Activates the serial driver 1 using the driver default configuration.
+ * Activates the SD1 and SPI1 drivers.
*/
- sdStart(&SD1, NULL);
+ sdStart(&SD1, NULL); /* Default: 38400,8,N,1. */
+ spiStart(&SPID1, &spicfg);
/*
* Creates the blinker threads.
diff --git a/os/hal/platforms/LPC11xx/spi_lld.c b/os/hal/platforms/LPC11xx/spi_lld.c index 50cd0c1ef..50f9903ae 100644 --- a/os/hal/platforms/LPC11xx/spi_lld.c +++ b/os/hal/platforms/LPC11xx/spi_lld.c @@ -199,16 +199,16 @@ void spi_lld_start(SPIDriver *spip) { /* Clock activation.*/
#if LPC11xx_SPI_USE_SSP0
if (&SPID1 == spip) {
- LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 11);
LPC_SYSCON->SSP0CLKDIV = LPC11xx_SPI_SSP0CLKDIV;
+ LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 11);
NVICEnableVector(SSP0_IRQn,
CORTEX_PRIORITY_MASK(LPC11xx_SPI_SSP0_IRQ_PRIORITY));
}
#endif
#if LPC11xx_SPI_USE_SSP1
if (&SPID2 == spip) {
- LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 18);
LPC_SYSCON->SSP1CLKDIV = LPC11xx_SPI_SSP1CLKDIV;
+ LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 18);
NVICEnableVector(SSP1_IRQn,
CORTEX_PRIORITY_MASK(LPC11xx_SPI_SSP1_IRQ_PRIORITY));
}
@@ -237,16 +237,16 @@ void spi_lld_stop(SPIDriver *spip) { if (spip->spd_state != SPI_STOP) {
#if LPC11xx_SPI_USE_SSP0
if (&SPID1 == spip) {
- LPC_SYSCON->SSP0CLKDIV = 0;
LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 11);
+ LPC_SYSCON->SSP0CLKDIV = 0;
NVICDisableVector(SSP0_IRQn);
return;
}
#endif
#if LPC11xx_SPI_USE_SSP1
if (&SPID2 == spip) {
- LPC_SYSCON->SSP1CLKDIV = 0;
LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 18);
+ LPC_SYSCON->SSP1CLKDIV = 0;
NVICDisableVector(SSP1_IRQn);
return;
}
|