diff --git a/configs/xmc4500-relax/README.txt b/configs/xmc4500-relax/README.txt index 14eae34dc8..73b46be94b 100644 --- a/configs/xmc4500-relax/README.txt +++ b/configs/xmc4500-relax/README.txt @@ -162,3 +162,24 @@ Configurations Application Configuration: CONFIG_NSH_BUILTIN_APPS=y : Enable starting apps from NSH command line + +SPI +=== + + Using MAX6675 Thermocouple + -------------------------- + + There is a board support to use a MAX6675 connected to SPI2. In other to use + it you need to enable these options: + + CONFIG_XMC4_USIC=y + CONFIG_XMC4_USCI_UART=y + CONFIG_XMC4_USCI_SPI=y + CONFIG_XMC4_SPI2=y + CONFIG_XMC4_USIC1=y + CONFIG_XMC4_USIC1_CHAN0_ISSPI=y + CONFIG_XMC4_USIC1_CHAN1_ISUART=y + CONFIG_UART3_SERIAL_CONSOLE=y + CONFIG_SENSORS_MAX6675=y + + These are the used SPI pins: SCLK = P0.11, MISO = P0.4 and CS = P0.2 diff --git a/configs/xmc4500-relax/src/Makefile b/configs/xmc4500-relax/src/Makefile index 9181caf155..fe3fcaead3 100644 --- a/configs/xmc4500-relax/src/Makefile +++ b/configs/xmc4500-relax/src/Makefile @@ -52,6 +52,10 @@ ifeq ($(CONFIG_XMC4_USCI_SPI),y) CSRCS += xmc4_spi.c endif +ifeq ($(CONFIG_SENSORS_MAX6675),y) +CSRCS += xmc4_max6675.c +endif + ifeq ($(CONFIG_LIB_BOARDCTL),y) CSRCS += xmc4_appinit.c endif diff --git a/configs/xmc4500-relax/src/xmc4500-relax.h b/configs/xmc4500-relax/src/xmc4500-relax.h index 156d6f8c17..a5ab9f2888 100644 --- a/configs/xmc4500-relax/src/xmc4500-relax.h +++ b/configs/xmc4500-relax/src/xmc4500-relax.h @@ -76,6 +76,12 @@ #define GPIO_BUTTON2 (GPIO_INPUT | GPIO_PINCTRL_SOFTWARE | \ GPIO_PORT1 | GPIO_PIN15) +/* SPIs Chip select */ + +#define GPIO_CS_MAX6675 (GPIO_OUTPUT | GPIO_OUTPUT_PUSHPULL | \ + GPIO_PADA1P_STRONGSOFT | GPIO_PINCTRL_SOFTWARE | \ + GPIO_OUTPUT_SET | GPIO_PORT0 | GPIO_PIN2) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/configs/xmc4500-relax/src/xmc4_bringup.c b/configs/xmc4500-relax/src/xmc4_bringup.c index 151099f9ed..6955908682 100644 --- a/configs/xmc4500-relax/src/xmc4_bringup.c +++ b/configs/xmc4500-relax/src/xmc4_bringup.c @@ -40,6 +40,7 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -63,5 +64,15 @@ int xmc4_bringup(void) { - return OK; + int ret = OK; + +#ifdef CONFIG_SENSORS_MAX6675 + ret = xmc4_max6675initialize("/dev/temp0"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_max6675initialize failed: %d\n", ret); + } +#endif + + return ret; } diff --git a/configs/xmc4500-relax/src/xmc4_spi.c b/configs/xmc4500-relax/src/xmc4_spi.c index 37a72b0b11..1beb039238 100644 --- a/configs/xmc4500-relax/src/xmc4_spi.c +++ b/configs/xmc4500-relax/src/xmc4_spi.c @@ -75,7 +75,8 @@ void weak_function xmc4_spidev_initialize(void) /* Configure SPI2 chip selects */ -#ifdef CONFIG_XMC4_SPI2 +#ifdef CONFIG_XMC4_SPI2 && defined(CONFIG_SENSORS_MAX6675) + (void)xmc4_gpio_config(GPIO_CS_MAX6675); #endif /* Configure SPI3 chip selects */ @@ -161,6 +162,14 @@ void xmc4_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, { spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); + +#if defined(CONFIG_SENSORS_MAX6675) + if (devid == SPIDEV_TEMPERATURE(0)) + { + xmc4_gpio_write(GPIO_CS_MAX6675, !selected); + } +#endif + } #endif diff --git a/drivers/sensors/max6675.c b/drivers/sensors/max6675.c index b0f63d80c4..9d6c944536 100644 --- a/drivers/sensors/max6675.c +++ b/drivers/sensors/max6675.c @@ -127,7 +127,7 @@ static void max6675_lock(FAR struct spi_dev_s *spi) SPI_SETMODE(spi, SPIDEV_MODE0); SPI_SETBITS(spi, 8); (void)SPI_HWFEATURES(spi, 0); - SPI_SETFREQUENCY(spi, 400000); + SPI_SETFREQUENCY(spi, 4000000); } /****************************************************************************