From 16f10822864c01278a4f8d450136f8d88f29f87e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 15 Jun 2013 16:38:10 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5856 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM8S/SPI/demo/main.c | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 testhal/STM8S/SPI/demo/main.c (limited to 'testhal/STM8S/SPI/demo/main.c') diff --git a/testhal/STM8S/SPI/demo/main.c b/testhal/STM8S/SPI/demo/main.c new file mode 100644 index 000000000..b1e8b6ed1 --- /dev/null +++ b/testhal/STM8S/SPI/demo/main.c @@ -0,0 +1,87 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include "ch.h" +#include "hal.h" + +/* + * SPI configuration (8MHz, CPHA=0, CPOL=0, MSb first). + */ +static ROMCONST SPIConfig spicfg = { + NULL, + GPIOD, + PD_LD10, + 0 +}; + +/* + * Transmit data. + */ +static ROMCONST uint8_t digits[32] = { + 0x24, 0xAF, 0xE0, 0xA2, 0x2B, 0x32, 0x30, 0xA7, + 0x20, 0x22, 0x21, 0x38, 0x74, 0xA8, 0x70, 0x71, + 0x04, 0x8F, 0xC0, 0x82, 0x0B, 0x12, 0x10, 0x87, + 0x00, 0x02, 0x01, 0x18, 0x54, 0x88, 0x50, 0x51 +}; + +/* + * Receive buffer. + */ +static uint8_t buffer[32]; + +/* + * Application entry point. + */ +void main(void) { + + /* + * System initializations. + * - HAL initialization, this also initializes the configured device drivers + * and performs the board-specific initializations. + * - Kernel initialization, the main() function becomes a thread and the + * RTOS is active. + */ + halInit(); + chSysInit(); + + /* + * OS initialization. + */ + chSysInit(); + + /* + * Activates the SPI driver 1 using the driver default configuration. + */ + spiStart(&SPID1, &spicfg); + + /* + * Normal main() thread activity. + */ + while (TRUE) { + volatile uint8_t b; + + chThdSleepMilliseconds(1000); + /* Exchanging data, if the pins MISO and MOSI are connected then the + transmitted data is received back into the buffer. On the + STM8S-Discovery board the pins are CN2-9 and CN2-10.*/ + spiSelect(&SPID1); + spiExchange(&SPID1, sizeof(digits), digits, buffer); + /* Polled transfers test.*/ + b = spiPolledExchange(&SPID1, 0x55); + b = spiPolledExchange(&SPID1, 0xAA); + spiUnselect(&SPID1); + } +} -- cgit v1.2.3