Skip to content

Commit

Permalink
~configs/xmc4500-relax: Add support to MAX6675 on XMC4500-Relax board…
Browse files Browse the repository at this point in the history
…. drivers/sensors/max6675.c: Increases SPI frequency from 400Khz to 4MHz.
  • Loading branch information
acassis authored and gregory-nutt committed Jun 16, 2018
1 parent 61a026d commit 5fb988b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
21 changes: 21 additions & 0 deletions configs/xmc4500-relax/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions configs/xmc4500-relax/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions configs/xmc4500-relax/src/xmc4500-relax.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down
13 changes: 12 additions & 1 deletion configs/xmc4500-relax/src/xmc4_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <nuttx/config.h>

#include <sys/types.h>
#include <debug.h>

/****************************************************************************
* Pre-processor Definitions
Expand All @@ -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;
}
11 changes: 10 additions & 1 deletion configs/xmc4500-relax/src/xmc4_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion drivers/sensors/max6675.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/****************************************************************************
Expand Down

0 comments on commit 5fb988b

Please sign in to comment.