Hi
I had no problem with the SSI2 port on my Tiva Launchpad, but now I need to switch to SSI3 and it does not work anymore.
I probed the SPI clock signal and there is no clock signal at all.
Cheers Michael
My Code;
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== EK_TM4C1294XL.c ========
* This file is responsible for setting up the board specific items for the
* EK_TM4C1294XL board.
*/
#include <stdint.h>
#include <stdbool.h>
#include <inc/hw_memmap.h>
#include <inc/hw_types.h>
#include <inc/hw_ints.h>
#include <inc/hw_gpio.h>
#include <driverlib/gpio.h>
#include <driverlib/flash.h>
#include <driverlib/sysctl.h>
#include <driverlib/i2c.h>
#include <driverlib/ssi.h>
#include <driverlib/uart.h>
#include <driverlib/udma.h>
#include <driverlib/pin_map.h>
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include "EK_TM4C1294XL.h"
#ifndef TI_DRIVERS_UART_DMA
#define TI_DRIVERS_UART_DMA 0
#endif
#ifndef TI_EXAMPLES_PPP
#define TI_EXAMPLES_PPP 0
#else
/* prototype for NIMU init function */
extern int USBSerialPPP_NIMUInit();
#endif
/*
* =============================== DMA ===============================
*/
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_ALIGN(dmaControlTable, 1024)
#elif defined(__IAR_SYSTEMS_ICC__)
#pragma data_alignment=1024
#elif defined(__GNUC__)
__attribute__ ((aligned (1024)))
#endif
static tDMAControlTable dmaControlTable[32];
static bool dmaInitialized = false;
/* Hwi_Struct used in the initDMA Hwi_construct call */
static Hwi_Struct dmaHwiStruct;
/* Hwi_Struct used in the usbBusFault Hwi_construct call */
static Hwi_Struct usbBusFaultHwiStruct;
/*
* ======== dmaErrorHwi ========
*/
static Void dmaErrorHwi(UArg arg)
{
System_printf("DMA error code: %d\n", uDMAErrorStatusGet());
uDMAErrorStatusClear();
System_abort("DMA error!!");
}
/*
* ======== EK_TM4C1294XL_usbBusFaultHwi ========
*/
static Void EK_TM4C1294XL_usbBusFaultHwi(UArg arg)
{
/*
* This function should be modified to appropriately manage handle
* a USB bus fault.
*/
System_printf("USB bus fault detected.");
Hwi_clearInterrupt(INT_GPIOQ4);
System_abort("USB error!!");
}
/*
* ======== EK_TM4C1294XL_initDMA ========
*/
void EK_TM4C1294XL_initDMA(void)
{
Error_Block eb;
Hwi_Params hwiParams;
if (!dmaInitialized) {
Error_init(&eb);
Hwi_Params_init(&hwiParams);
Hwi_construct(&(dmaHwiStruct), INT_UDMAERR, dmaErrorHwi,
&hwiParams, &eb);
if (Error_check(&eb)) {
System_abort("Couldn't construct DMA error hwi");
}
SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
uDMAEnable();
uDMAControlBaseSet(dmaControlTable);
dmaInitialized = true;
}
}
/*
* =============================== General ===============================
*/
/*
* ======== EK_TM4C1294XL_initGeneral ========
*/
void EK_TM4C1294XL_initGeneral(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOR);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOS);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOT);
}
/*
* =============================== EMAC ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(EMAC_config, ".const:EMAC_config")
#pragma DATA_SECTION(emacHWAttrs, ".const:emacHWAttrs")
#pragma DATA_SECTION(NIMUDeviceTable, ".data:NIMUDeviceTable")
#endif
#include <ti/drivers/EMAC.h>
#include <ti/drivers/emac/EMACSnow.h>
/*
* Required by the Networking Stack (NDK). This array must be NULL terminated.
* This can be removed if NDK is not used.
* Double curly braces are needed to avoid GCC bug #944572
* https://bugs.launchpad.net/gcc-linaro/+bug/944572
*/
#if TI_EXAMPLES_PPP
/* Use PPP driver for PPP example only */
NIMU_DEVICE_TABLE_ENTRY NIMUDeviceTable[2] = {{USBSerialPPP_NIMUInit}, {NULL}};
#else
/* Default: use Ethernet driver */
NIMU_DEVICE_TABLE_ENTRY NIMUDeviceTable[2] = {{EMACSnow_NIMUInit}, {NULL}};
#endif
/* EMAC objects */
EMACSnow_Object emacObjects[EK_TM4C1294XL_EMACCOUNT];
/*
* EMAC configuration structure
* Set user/company specific MAC octates. The following sets the address
* to ff-ff-ff-ff-ff-ff. Users need to change this to make the label on
* their boards.
*/
unsigned char macAddress[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
const EMACSnow_HWAttrs emacHWAttrs[EK_TM4C1294XL_EMACCOUNT] = {
{EMAC0_BASE, INT_EMAC0, ~0 /* Interrupt priority */, macAddress}
};
const EMAC_Config EMAC_config[] = {
{
&EMACSnow_fxnTable,
&emacObjects[0],
&emacHWAttrs[0]
},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C1294XL_initEMAC ========
*/
void EK_TM4C1294XL_initEMAC(void)
{
uint32_t ulUser0, ulUser1;
/* Get the MAC address */
FlashUserGet(&ulUser0, &ulUser1);
if ((ulUser0 != 0xffffffff) && (ulUser1 != 0xffffffff)) {
System_printf("Using MAC address in flash\n");
/*
* Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
* address needed to program the hardware registers, then program the MAC
* address into the Ethernet Controller registers.
*/
macAddress[0] = ((ulUser0 >> 0) & 0xff);
macAddress[1] = ((ulUser0 >> 8) & 0xff);
macAddress[2] = ((ulUser0 >> 16) & 0xff);
macAddress[3] = ((ulUser1 >> 0) & 0xff);
macAddress[4] = ((ulUser1 >> 8) & 0xff);
macAddress[5] = ((ulUser1 >> 16) & 0xff);
}
else if (macAddress[0] == 0xff && macAddress[1] == 0xff &&
macAddress[2] == 0xff && macAddress[3] == 0xff &&
macAddress[4] == 0xff && macAddress[5] == 0xff) {
System_abort("Change the macAddress variable to match your boards MAC sticker");
}
GPIOPinConfigure(GPIO_PF0_EN0LED0); /* EK_TM4C1294XL_USR_D3 */
GPIOPinConfigure(GPIO_PF4_EN0LED1); /* EK_TM4C1294XL_USR_D4 */
GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4);
/* Once EMAC_init is called, EMAC_config cannot be changed */
EMAC_init();
}
/*
* =============================== GPIO ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(GPIOTiva_config, ".const:GPIOTiva_config")
#endif
#include <ti/drivers/GPIO.h>
#include <ti/drivers/gpio/GPIOTiva.h>
/*
* Array of Pin configurations
* NOTE: The order of the pin configurations must coincide with what was
* defined in EK_TM4C1294XL.h
* NOTE: Pins not used for interrupts should be placed at the end of the
* array. Callback entries can be omitted from callbacks array to
* reduce memory usage.
*/
GPIO_PinConfig gpioPinConfigs[] = {
/* Input pins */
/* EK_TM4C1294XL_USR_SW1 */
GPIOTiva_PJ_0 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
/* EK_TM4C1294XL_USR_SW2 */
GPIOTiva_PJ_1 | GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_RISING,
/* Output pins */
/* EK_TM4C1294XL_USR_D1 */
GPIOTiva_PN_1 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C1294XL_USR_D2 */
GPIOTiva_PN_0 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* Pins for SPI/OLED on Booster Pack 2 */
/* EK_TM4C1294XL_USR_M7 */
GPIOTiva_PM_7 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C1294XL_USR_P4 */
GPIOTiva_PP_4 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C1294XL_USR_P5 */
GPIOTiva_PP_5 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C1294XL_USR_D2 */
GPIOTiva_PD_2 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* Pins for SPI/OLED on Booster Pack 1 */
/* EK_TM4C1294XL_USR_M3 */
GPIOTiva_PM_3 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C1294XL_USR_C7 */
GPIOTiva_PC_7 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C1294XL_USR_H2 */
GPIOTiva_PH_2 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
/* EK_TM4C1294XL_USR_E4 */
GPIOTiva_PE_4 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_LOW,
};
/*
* Array of callback function pointers
* NOTE: The order of the pin configurations must coincide with what was
* defined in EK_TM4C1294XL.h
* NOTE: Pins not used for interrupts can be omitted from callbacks array to
* reduce memory usage (if placed at end of gpioPinConfigs array).
*/
GPIO_CallbackFxn gpioCallbackFunctions[] = {
NULL, /* EK_TM4C1294XL_USR_SW1 */
NULL /* EK_TM4C1294XL_USR_SW2 */
};
/* The device-specific GPIO_config structure */
const GPIOTiva_Config GPIOTiva_config = {
.pinConfigs = (GPIO_PinConfig *) gpioPinConfigs,
.callbacks = (GPIO_CallbackFxn *) gpioCallbackFunctions,
.numberOfPinConfigs = sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
.numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn),
.intPriority = (~0)
};
/*
* ======== EK_TM4C1294XL_initGPIO ========
*/
void EK_TM4C1294XL_initGPIO(void)
{
/* Initialize peripheral and pins */
GPIO_init();
}
/*
* =============================== I2C ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(I2C_config, ".const:I2C_config")
#pragma DATA_SECTION(i2cTivaHWAttrs, ".const:i2cTivaHWAttrs")
#endif
#include <ti/drivers/I2C.h>
#include <ti/drivers/i2c/I2CTiva.h>
/* I2C objects */
I2CTiva_Object i2cTivaObjects[EK_TM4C1294XL_I2CCOUNT];
/* I2C configuration structure, describing which pins are to be used */
const I2CTiva_HWAttrs i2cTivaHWAttrs[EK_TM4C1294XL_I2CCOUNT] = {
{I2C7_BASE, INT_I2C7, ~0 /* Interrupt priority */},
{I2C8_BASE, INT_I2C8, ~0 /* Interrupt priority */}
};
const I2C_Config I2C_config[] = {
{&I2CTiva_fxnTable, &i2cTivaObjects[0], &i2cTivaHWAttrs[0]},
{&I2CTiva_fxnTable, &i2cTivaObjects[1], &i2cTivaHWAttrs[1]},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C1294XL_initI2C ========
*/
void EK_TM4C1294XL_initI2C(void)
{
/* I2C7 Init */
/*
* NOTE: TI-RTOS examples configure pins PD0 & PD1 for SSI2 or I2C7. Thus,
* a conflict occurs when the I2C & SPI drivers are used simultaneously in
* an application. Modify the pin mux settings in this file and resolve the
* conflict before running your the application.
*/
/* Enable the peripheral */
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C7);
/* Configure the appropriate pins to be I2C instead of GPIO. */
GPIOPinConfigure(GPIO_PD0_I2C7SCL);
GPIOPinConfigure(GPIO_PD1_I2C7SDA);
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
/* I2C8 Init */
/* Enable the peripheral */
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C8);
/* Configure the appropriate pins to be I2C instead of GPIO. */
GPIOPinConfigure(GPIO_PA2_I2C8SCL);
GPIOPinConfigure(GPIO_PA3_I2C8SDA);
GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_3);
I2C_init();
}
/*
* =============================== PWM ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(PWM_config, ".const:PWM_config")
#pragma DATA_SECTION(pwmTivaHWAttrs, ".const:pwmTivaHWAttrs")
#endif
#include <ti/drivers/PWM.h>
#include <ti/drivers/pwm/PWMTiva.h>
#include <driverlib/pwm.h>
PWMTiva_Object pwmTivaObjects[EK_TM4C1294XL_PWMCOUNT];
/* PWM configuration structure */
const PWMTiva_HWAttrs pwmTivaHWAttrs[EK_TM4C1294XL_PWMCOUNT] = {
{
PWM0_BASE,
PWM_OUT_0,
PWM_GEN_MODE_DOWN | PWM_GEN_MODE_DBG_RUN
}
};
const PWM_Config PWM_config[] = {
{&PWMTiva_fxnTable, &pwmTivaObjects[0], &pwmTivaHWAttrs[0]},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C1294XL_initPWM ========
*/
void EK_TM4C1294XL_initPWM(void)
{
/* Enable PWM peripherals */
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
/*
* Enable PWM output on GPIO pins. PWM output is connected to an Ethernet
* LED on the development board (D4). The PWM configuration
* below will disable Ethernet functionality.
*/
GPIOPinConfigure(GPIO_PF0_M0PWM0);
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
PWM_init();
}
/*
* =============================== SDSPI ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(SDSPI_config, ".const:SDSPI_config")
#pragma DATA_SECTION(sdspiTivaHWattrs, ".const:sdspiTivaHWattrs")
#endif
#include <ti/drivers/SDSPI.h>
#include <ti/drivers/sdspi/SDSPITiva.h>
/* SDSPI objects */
SDSPITiva_Object sdspiTivaObjects[EK_TM4C1294XL_SDSPICOUNT];
/* SDSPI configuration structure, describing which pins are to be used */
const SDSPITiva_HWAttrs sdspiTivaHWattrs[EK_TM4C1294XL_SDSPICOUNT] = {
{
SSI3_BASE, /* SPI base address */
GPIO_PORTQ_BASE, /* SPI SCK PORT */
GPIO_PIN_0, /* SCK PIN */
GPIO_PORTQ_BASE, /* SPI MISO PORT*/
GPIO_PIN_3, /* MISO PIN */
GPIO_PORTQ_BASE, /* SPI MOSI PORT */
GPIO_PIN_2, /* MOSI PIN */
GPIO_PORTP_BASE, /* GPIO CS PORT */
GPIO_PIN_4, /* CS PIN */
}
};
const SDSPI_Config SDSPI_config[] = {
{&SDSPITiva_fxnTable, &sdspiTivaObjects[0], &sdspiTivaHWattrs[0]},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C1294XL_initSDSPI ========
*/
void EK_TM4C1294XL_initSDSPI(void)
{
/* SDSPI0 configuration */
/* Enable the peripherals used by the SD Card */
/* SDSPI1 configuration */
/* Enable the peripherals used by the SD Card */
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);
/* Configure pad settings */
GPIOPadConfigSet(GPIO_PORTQ_BASE,
GPIO_PIN_0 | GPIO_PIN_2,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTQ_BASE,
GPIO_PIN_3,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet(GPIO_PORTP_BASE,
GPIO_PIN_4,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
GPIOPinConfigure(GPIO_PQ0_SSI3CLK);
GPIOPinConfigure(GPIO_PQ3_SSI3XDAT1);
GPIOPinConfigure(GPIO_PQ2_SSI3XDAT0);
/*
* These GPIOs are connected to PA2 and PA3 and need to be brought into a
* GPIO input state so they don't interfere with SPI communications.
*/
GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_2);
GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_3);
SDSPI_init();
}
/*
* =============================== SPI ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(SPI_config, ".const:SPI_config")
#pragma DATA_SECTION(spiTivaDMAHWAttrs, ".const:spiTivaDMAHWAttrs")
#endif
#include <ti/drivers/SPI.h>
#include <ti/drivers/spi/SPITivaDMA.h>
/* SPI objects */
SPITivaDMA_Object spiTivaDMAObjects[EK_TM4C1294XL_SPICOUNT];
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_ALIGN(spiTivaDMAscratchBuf, 32)
#elif defined(__IAR_SYSTEMS_ICC__)
#pragma data_alignment=32
#elif defined(__GNUC__)
__attribute__ ((aligned (32)))
#endif
uint32_t spiTivaDMAscratchBuf[EK_TM4C1294XL_SPICOUNT];
/* SPI configuration structure */
const SPITivaDMA_HWAttrs spiTivaDMAHWAttrs[EK_TM4C1294XL_SPICOUNT] = {
{
SSI3_BASE,
INT_SSI3,
~0, // Interrupt priority
&spiTivaDMAscratchBuf[0],
0,
UDMA_SEC_CHANNEL_TMR2A_14,
UDMA_SEC_CHANNEL_TMR2B_15,
uDMAChannelAssign,
UDMA_CH14_SSI3RX,
UDMA_CH15_SSI3TX
}
};
const SPI_Config SPI_config[] = {
{&SPITivaDMA_fxnTable, &spiTivaDMAObjects[0], &spiTivaDMAHWAttrs[0]},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C1294XL_initSPI ========
*/
void EK_TM4C1294XL_initSPI(void)
{
/* SSI2 */
/*
* NOTE: TI-RTOS examples configure pins PD0 & PD1 for SSI2 or I2C7. Thus,
* a conflict occurs when the I2C & SPI drivers are used simultaneously in
* an application. Modify the pin mux settings in this file and resolve the
* conflict before running your the application.
*/
uint32_t g_ui32SysClock = 120 * 1e6;
/* SSI3 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);
GPIOPadConfigSet(GPIO_PORTQ_BASE,
GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
GPIOPadConfigSet(GPIO_PORTQ_BASE,
GPIO_PIN_3,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet(GPIO_PORTP_BASE,
GPIO_PIN_4,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
GPIOPinConfigure(GPIO_PQ0_SSI3CLK);
GPIOPinConfigure(GPIO_PQ1_SSI3FSS);
GPIOPinConfigure(GPIO_PQ2_SSI3XDAT0);
GPIOPinConfigure(GPIO_PQ3_SSI3XDAT1);
GPIOPinTypeSSI(GPIO_PORTQ_BASE, GPIO_PIN_0 | GPIO_PIN_1 |
GPIO_PIN_2 | GPIO_PIN_3);
SSIConfigSetExpClk(SSI3_BASE, g_ui32SysClock, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 10000000, 8);
EK_TM4C1294XL_initDMA();
SPI_init();
}
/*
* =============================== UART ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(UART_config, ".const:UART_config")
#pragma DATA_SECTION(uartTivaHWAttrs, ".const:uartTivaHWAttrs")
#endif
#include <ti/drivers/UART.h>
#if TI_DRIVERS_UART_DMA
#include <ti/drivers/uart/UARTTivaDMA.h>
/* UART objects using DMA */
UARTTivaDMA_Object uartTivaObjects[EK_TM4C1294XL_UARTCOUNT];
/* UART DMA configuration structure */
const UARTTivaDMA_HWAttrs uartTivaHWAttrs[EK_TM4C1294XL_UARTCOUNT] = {
{/* EK_TM4C1294XL_UART0 */
UART0_BASE,
INT_UART0,
~0, /* Interrupt priority */
UDMA_CH8_UART0RX,
UDMA_CH9_UART0TX,
}
};
const UART_Config UART_config[] = {
{
&UARTTivaDMA_fxnTable,
&uartTivaObjects[0],
&uartTivaHWAttrs[0]
},
{NULL, NULL, NULL}
};
#else
#include <ti/drivers/uart/UARTTiva.h>
/* UART objects */
UARTTiva_Object uartTivaObjects[EK_TM4C1294XL_UARTCOUNT];
unsigned char uartTivaRingBuffer[32];
/* UART configuration structure */
const UARTTiva_HWAttrs uartTivaHWAttrs[EK_TM4C1294XL_UARTCOUNT] = {
{/* EK_TM4C1294XL_UART0 */
.baseAddr = UART0_BASE,
.intNum = INT_UART0,
.intPriority = ~0,
.flowControl = UART_FLOWCONTROL_NONE,
.ringBufPtr = uartTivaRingBuffer,
.ringBufSize = sizeof(uartTivaRingBuffer)
}
};
const UART_Config UART_config[] = {
{
&UARTTiva_fxnTable,
&uartTivaObjects[0],
&uartTivaHWAttrs[0]
},
{NULL, NULL, NULL}
};
#endif /* TI_DRIVERS_UART_DMA */
/*
* ======== EK_TM4C1294XL_initUART ========
*/
void EK_TM4C1294XL_initUART(void)
{
/* Enable and configure the peripherals used by the uart. */
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
/* Initialize the UART driver */
#if TI_DRIVERS_UART_DMA
EK_TM4C1294XL_initDMA();
#endif
UART_init();
}
/*
* =============================== USB ===============================
*/
/*
* ======== EK_TM4C1294XL_initUSB ========
* This function just turns on the USB
*/
void EK_TM4C1294XL_initUSB(EK_TM4C1294XL_USBMode usbMode)
{
Error_Block eb;
Hwi_Params hwiParams;
/* Enable the USB peripheral and PLL */
SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
SysCtlUSBPLLEnable();
/* Setup pins for USB operation */
GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
/* Additional configurations for Host mode */
if (usbMode == EK_TM4C1294XL_USBHOST) {
/* Configure the pins needed */
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xff;
GPIOPinConfigure(GPIO_PD6_USB0EPEN);
GPIOPinTypeUSBDigital(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);
/*
* USB bus fault is routed to pin PQ4. We create a Hwi to allow us
* to detect power faults and recover gracefully or terminate the
* program. PQ4 is active low; set the pin as input with a weak
* pull-up.
*/
GPIOPadConfigSet(GPIO_PORTQ_BASE, GPIO_PIN_4,
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
GPIOIntTypeSet(GPIO_PORTQ_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE);
GPIOIntClear(GPIO_PORTQ_BASE, GPIO_PIN_4);
/* Create a Hwi for PQ4 pin. */
Error_init(&eb);
Hwi_Params_init(&hwiParams);
Hwi_construct(&(usbBusFaultHwiStruct), INT_GPIOQ4,
EK_TM4C1294XL_usbBusFaultHwi, &hwiParams, &eb);
if (Error_check(&eb)) {
System_abort("Couldn't construct USB bus fault hwi");
}
}
}
/*
* =============================== USBMSCHFatFs ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(USBMSCHFatFs_config, ".const:USBMSCHFatFs_config")
#pragma DATA_SECTION(usbmschfatfstivaHWAttrs, ".const:usbmschfatfstivaHWAttrs")
#endif
#include <ti/drivers/USBMSCHFatFs.h>
#include <ti/drivers/usbmschfatfs/USBMSCHFatFsTiva.h>
/* USBMSCHFatFs objects */
USBMSCHFatFsTiva_Object usbmschfatfstivaObjects[EK_TM4C1294XL_USBMSCHFatFsCOUNT];
/* USBMSCHFatFs configuration structure, describing which pins are to be used */
const USBMSCHFatFsTiva_HWAttrs usbmschfatfstivaHWAttrs[EK_TM4C1294XL_USBMSCHFatFsCOUNT] = {
{INT_USB0, ~0 /* Interrupt priority */}
};
const USBMSCHFatFs_Config USBMSCHFatFs_config[] = {
{
&USBMSCHFatFsTiva_fxnTable,
&usbmschfatfstivaObjects[0],
&usbmschfatfstivaHWAttrs[0]
},
{NULL, NULL, NULL}
};
/*
* ======== EK_TM4C1294XL_initUSBMSCHFatFs ========
*/
void EK_TM4C1294XL_initUSBMSCHFatFs(void)
{
/* Initialize the DMA control table */
EK_TM4C1294XL_initDMA();
/* Call the USB initialization function for the USB Reference modules */
EK_TM4C1294XL_initUSB(EK_TM4C1294XL_USBHOST);
USBMSCHFatFs_init();
}
/*
* =============================== Watchdog ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(Watchdog_config, ".const:Watchdog_config")
#pragma DATA_SECTION(watchdogTivaHWAttrs, ".const:watchdogTivaHWAttrs")
#endif
#include <ti/drivers/Watchdog.h>
#include <ti/drivers/watchdog/WatchdogTiva.h>
/* Watchdog objects */
WatchdogTiva_Object watchdogTivaObjects[EK_TM4C1294XL_WATCHDOGCOUNT];
/* Watchdog configuration structure */
const WatchdogTiva_HWAttrs watchdogTivaHWAttrs[EK_TM4C1294XL_WATCHDOGCOUNT] = {
/* EK_TM4C1294XL_WATCHDOG0 with 1 sec period at default CPU clock freq */
{
WATCHDOG0_BASE,
INT_WATCHDOG,
~0, /* Interrupt priority */
80000000
},
};
const Watchdog_Config Watchdog_config[] = {
{&WatchdogTiva_fxnTable, &watchdogTivaObjects[0], &watchdogTivaHWAttrs[0]},
{NULL, NULL, NULL},
};
/*
* ======== EK_TM4C1294XL_initWatchdog ========
*
* NOTE: To use the other watchdog timer with base address WATCHDOG1_BASE,
* an additional function call may need be made to enable PIOSC. Enabling
* WDOG1 does not do this. Enabling another peripheral that uses PIOSC
* such as ADC0 or SSI0, however, will do so. Example:
*
* SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
* SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG1);
*
* See the following forum post for more information:
* http://e2e.ti.com/support/microcontrollers/stellaris_arm_cortex-m3_microcontroller/f/471/p/176487/654390.aspx#654390
*/
void EK_TM4C1294XL_initWatchdog(void)
{
/* Enable peripherals used by Watchdog */
SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
/* Initialize the Watchdog driver */
Watchdog_init();
}
/*
* =============================== WiFi ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(WiFi_config, ".const:WiFi_config")
#pragma DATA_SECTION(wiFiCC3100HWAttrs, ".const:wiFiCC3100HWAttrs")
#endif
#include <ti/drivers/WiFi.h>
#include <ti/drivers/wifi/WiFiCC3100.h>
/* WiFi objects */
WiFiCC3100_Object wiFiCC3100Objects[EK_TM4C1294XL_WIFICOUNT];
/* WiFi configuration structure */
const WiFiCC3100_HWAttrs wiFiCC3100HWAttrs[EK_TM4C1294XL_WIFICOUNT] = {
{
GPIO_PORTM_BASE, /* IRQ port */
GPIO_PIN_3, /* IRQ pin */
INT_GPIOM, /* IRQ port interrupt vector */
GPIO_PORTH_BASE, /* CS port */
GPIO_PIN_2, /* CS pin */
GPIO_PORTC_BASE, /* WLAN EN port */
GPIO_PIN_6 /* WLAN EN pin */
}
};
const WiFi_Config WiFi_config[] = {
{
&WiFiCC3100_fxnTable,
&wiFiCC3100Objects[0],
&wiFiCC3100HWAttrs[0]
},
{NULL,NULL, NULL},
};
/*
* ======== EK_TM4C1294XL_initWiFi ========
*/
void EK_TM4C1294XL_initWiFi(void)
{
/* Configure EN & CS pins to disable CC3100 */
GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_2);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_6);
GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_2, GPIO_PIN_2);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0);
/* Configure SSI2 for CC3100 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
GPIOPinConfigure(GPIO_PD3_SSI2CLK);
GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);
GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);
GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3);
/* Configure IRQ pin */
GPIOPinTypeGPIOInput(GPIO_PORTM_BASE, GPIO_PIN_3);
GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPD);
GPIOIntTypeSet(GPIO_PORTM_BASE, GPIO_PIN_3, GPIO_RISING_EDGE);
SPI_init();
EK_TM4C1294XL_initDMA();
WiFi_init();
}
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== gpiointerrupt.c ========
*/
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
/* Example/Board Header files */
#include "Board.h"
#include "oled.h"
#include "thumbstick.h"
#include <string.h>
void oled_window_init(void);
/* variable to be read by GUI Composer */
int count = 0;
int btn_count = 0;
int led_count = 0;
/*
* ======== gpioButtonFxn0 ========
* Callback function for the GPIO interrupt on Board_BUTTON0.
*/
void gpioButtonFxn0(void)
{
/* Clear the GPIO interrupt and toggle an LED */
// GPIO_toggle(Board_LED0);
volatile int cnt;
btn_count++;
//Task_sleep(1);
// GPIO_disableInt(Board_BUTTON0);
for(cnt=0;cnt<100;cnt++);
// GPIO_enableInt(Board_BUTTON0);
}
/*
* ======== pwmLEDFxn ========
* Task periodically increments the PWM duty for the on board LED.
*/
Void Button0Fxn(UArg arg0, UArg arg1)
{
/* Loop forever incrementing the PWM duty */
// initOLED();
// oled_window_init();
initSPI();
while (1){
Thumbstick_read();
Task_sleep(200);
}
/* while (1) {
Semaphore_pend(semaphore0,BIOS_WAIT_FOREVER);
while (btn_count!=led_count)
{
led_count=btn_count;
Task_sleep(1000);
}
Semaphore_post(semaphore0);
}*/
}
/*
* ======== pwmLEDFxn ========
* Task periodically bliks for the on board LED.
*/
Void LED1Fxn(UArg arg0, UArg arg1)
{
int x;
/* Loop forever blinking Led1 */
while (1) {
Semaphore_pend(semaphore1,BIOS_WAIT_FOREVER);
if(btn_count==led_count)
Semaphore_pend(semaphore0,BIOS_WAIT_FOREVER);
while(btn_count==led_count)
{
for(x=0;x<led_count;x++)
{
GPIO_write(Board_LED0, Board_LED_ON);
Task_sleep(200);
GPIO_write(Board_LED0, Board_LED_OFF);
Task_sleep(200);
}
Task_sleep(1000);
}
if(btn_count>led_count)
{
btn_count -= led_count;
Semaphore_post(semaphore0);
}
Semaphore_post(semaphore1);
}
}
/*
* ======== main ========
*/
int main(void)
{
/* Call board init functions */
Board_initGeneral();
Board_initGPIO();
// Board_initUART();
Board_initSPI();
/* Turn on user LED */
GPIO_write(Board_LED0, Board_LED_OFF);
System_printf("Starting the GPIO Interrupt example\nSystem provider is set"
" to SysMin. Halt the target to view any SysMin contents in"
" ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
/* install Button callback */
GPIO_setCallback(Board_BUTTON0, gpioButtonFxn0);
/* Enable interrupts */
GPIO_enableInt(Board_BUTTON0);
/* Start BIOS */
BIOS_start();
return (0);
}
void oled_window_init(void)
{
char data[15];
oled_background(0, 0);
oled_rectangle(0, 20, 96, 1, 0xFFFF);
strcpy(data, "String");
oled_text(data, 6, 0xFFFF, 0, 10, 10);
oled_rectangle(96-1*7, 10, 7, 8, rgb2oled(0xFF, 0, 0));
oled_rectangle(96-2*7, 10, 7, 8, rgb2oled(0, 0xFF, 0));
oled_rectangle(96-3*7, 10, 7, 8, rgb2oled(0, 0, 0xFF));
oled_frame(0, 40, 96, 50, 1, rgb2oled(0, 0, 0xFF));
strcpy(data, "line");
oled_text(data, 4, 0xFFFF, 0, 15, 60);
}
/*
* spi_wrapper.c
*
* Created on: 06.05.2015
* Author: Christoph R.
*/
#include <stdint.h>
#include <stdbool.h>
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
/* TI-RTOS Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/SPI.h>
/* Example/Board Header files */
#include "Board.h"
#include "spi_wrapper.h"
#define SPI_FREQ 1e6
#define SPI_DATA 8
SPI_Handle masterSpiOled;
SPI_Handle masterSpiThumbStk;
SPI_Transaction masterTransaction;
bool transferOK;
unsigned char masterRxBuffer[SPI_MSG_LENGTH];
unsigned char masterTxBuffer[SPI_MSG_LENGTH] = "\0";
unsigned char masterRxBufferTS[3];
unsigned char masterTxBufferTS[3] = "\0";
void initSPI()
{
/* Initialize SPI handle as default master */
// masterSpiOled = SPI_open(Board_SPI1, NULL);
masterSpiThumbStk = SPI_open(Board_SPI1, NULL);
/*if (masterSpi == NULL) {
System_abort("Error initializing SPI\n");
}
else {
System_printf("SPI initialized\n");
}*/
}
void SPI_PutSingle(uint8_t data)
{
clearCS();
masterTxBuffer[0] = data;
/* Initialize master SPI transaction structure */
masterTransaction.count = SPI_MSG_LENGTH;
masterTransaction.txBuf = (Ptr)masterTxBuffer;
masterTransaction.rxBuf = (Ptr)masterRxBuffer;
/* Initiate SPI transfer */
transferOK = SPI_transfer(masterSpiOled, &masterTransaction);
setCS();
}
int SPI_GetDouble(uint8_t channel)
{
int adcval=0;
uint32_t g_ui32SysClock = 120 * 1e6;
// setCS();
// SysCtlDelay(g_ui32SysClock / 3 / 10 ); // 100 ms
clearCSB_TS();
SysCtlDelay(g_ui32SysClock / 3 / 10 ); // 100 ms
/* Initialize master SPI transaction structure */
masterTransaction.count = 3;
masterTransaction.txBuf = (Ptr)masterTxBufferTS;
masterTransaction.rxBuf = (Ptr)masterRxBufferTS;
/* Initiate SPI transfer */
masterTxBufferTS[0] = 0x06;
masterTxBufferTS[1] = channel << 6;
masterTxBufferTS[2] = 0xFF;
transferOK = SPI_transfer(masterSpiThumbStk, &masterTransaction);
adcval= masterRxBufferTS[1]<< 8| (masterRxBufferTS[2]);
setCSB_TS();
return adcval;
}
/*
* thumstick.c
*
* Created on: 02.01.2016
* Author: Rubi
*/
#include "thumbstick.h"
#include "spi_wrapper.h"
int Thumbstick_read(void)
{
int adcval;
adcval=SPI_GetDouble(0);
adcval=SPI_GetDouble(1);
return adcval;
}