Exemplo n.º 1
0
void main(void)
{
    //Set System clock to 72MHz
    xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    SysCtlDelay(10000);
    xSysCtlPeripheralEnable2(I2C1_BASE);

    xSysCtlPeripheralEnable2(xGPIO_PORTB_BASE);    

    //Map I2C1 Pin
    //SCK --> PB6
    //SDA --> PB7
    xSPinTypeI2C(I2C1SCK, PB6);
    xSPinTypeI2C(I2C1SDA, PB7);    

    //Initialize I2C Module 100K
    I2CInit(I2C1_BASE, 100000);
    I2CEnable(I2C1_BASE);
        
    //Enable ADXL345 Measure Function
    I2CMasterWriteS1(I2C1_BASE, I2C_SLAVE_ADDR, 0x2D, xfalse); 
    I2CMasterWriteS2(I2C1_BASE, 0x08, xtrue);
    
    SysCtlDelay(100000);
    
    //Read Accelerometer XYZ data in continue mode
    I2CMasterWriteS1(I2C1_BASE, I2C_SLAVE_ADDR, 0x32, xfalse);    
    I2CMasterReadBufS1(I2C1_BASE, I2C_SLAVE_ADDR, RecvBuf, 6, xtrue);

    while(1);
}
Exemplo n.º 2
0
//*****************************************************************************
//
//! \brief xsysctl 001 test of Peripheral Enable test .
//!
//! \return None.
//
//*****************************************************************************
static void xsysctl_xSysCtlPeripheralEnable2_test(void)
{
    unsigned long ulTemp,ulRegVal,i;


    for(i = 0; i < 16; i++)
    {
        xSysCtlPeripheralDisable2(ulPeriprerAddr[i]);
        ulRegVal = xHWREG(SYSCLK_APBCLK);
        TestAssert((ulxPeriphEnableMask[i] == (ulRegVal & ulxPeriphEnableMask[i])),
                                                          "xsysctl API error!");  
    }

	
    xSysCtlPeripheralEnable2(GPIO_PORTA_BASE);
    ulTemp = xHWREG(SYSCLK_APBCLK);
    TestAssert((ulTemp == (xHWREG(SYSCLK_APBCLK))), "xsysctl API error!");
	
    xSysCtlPeripheralEnable2(PWMA_BASE);
    ulRegVal = xHWREG(SYSCLK_APBCLK);
    TestAssert((SYSCLK_APBCLK_PWM01_EN == (ulRegVal & SYSCLK_APBCLK_PWM01_EN)),
                                                          "xsysctl API error!");
	
    xSysCtlPeripheralEnable2(PWMB_BASE);
    ulRegVal = xHWREG(SYSCLK_APBCLK);
    TestAssert((SYSCLK_APBCLK_PWM23_EN == (ulRegVal & SYSCLK_APBCLK_PWM23_EN)),
                                                          "xsysctl API error!");
}
Exemplo n.º 3
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xi2c001 test.
//!
//! \return None.
//
//*****************************************************************************
static void xI2C001Setup(void)
{      
    xSysCtlPeripheralEnable2(ulMaster);

    xSysCtlPeripheralEnable2(xGPIO_PORTD_BASE);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    
    xSPinTypeI2C(I2C0SCK, PD12);
    xSPinTypeI2C(I2C0SDA, PD13);
    
}
Exemplo n.º 4
0
Arquivo: SPI.cpp Projeto: Azz1/RPI_EPI
//Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
void SPIClass::begin(int spiClock){
    // Enable Peripheral SPIx
    xSysCtlPeripheralEnable2(spiPort);
    xSysCtlPeripheralEnable2(xGPIOSPinToPort(sD13));

    // Configure Some GPIO pins as SPIx Mode
    sPinTypeSPI(spiPort);
    ulDataWidth = xSPI_DATA_WIDTH8;
    ulDataFormat = SPI_MODE0;
    ulDataMode = MSBFIRST;
    xSPIConfigSet(spiPort, spiClock, xSPI_MOTO_FORMAT_MODE_0 | xSPI_DATA_WIDTH8 | xSPI_MSB_FIRST | xSPI_MODE_MASTER);
    xSPISSSet(spiPort, xSPI_SS_HARDWARE, xSPI_SS0);
    xSPIEnable(spiPort);
}
Exemplo n.º 5
0
Arquivo: PTC08.c Projeto: AlexGora/cox
//*****************************************************************************
//
//! \brief Initializes the PTC08 device.
//!
//! Initializes the PTC08 device,it will set the baud rate 115200,image size 
//! 320*240,ziprate 36 and non-save power.
//!
//! \return None.
//
//*****************************************************************************
xtBoolean 
PTC08Init(void)
{
    xSysCtlPeripheralEnable2(PTC08_UART);
    xSysCtlPeripheralEnable2(xGPIOSPinToPeripheralId(PTC08_PIN_UART_RX));
    xSysCtlPeripheralEnable2(xGPIOSPinToPeripheralId(PTC08_PIN_UART_TX));
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART1_MAIN, 1);

    xSPinTypeUART(PTC08_UART_RX, PTC08_PIN_UART_RX);
    xSPinTypeUART(PTC08_UART_TX, PTC08_PIN_UART_TX);

    xUARTConfigSet(PTC08_UART, 38400, (xUART_CONFIG_WLEN_8 |
    		                           xUART_CONFIG_STOP_1 |
                                       xUART_CONFIG_PAR_NONE));

    xUARTEnable(PTC08_UART, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX));

    //
    // Must wait for 2.5s before the camera can received Command
    //
    xSysCtlDelay(25000000); 
    
    if(!PTC08PhotoReset())
    {
        return xfalse;
    }
    if(!PTC08PhotoSizeSet(PTC08_SIZE_320_240))
    {
        return xfalse;
    }
    if(!PTC08ZipRateSet(0x36))
    {
        return xfalse;
    }
    xSysCtlDelay(10);
    
    if(!PTC08SavePowerSet(PTC08_SAVE_POWER_DIS))
    {
        return xfalse;
    } 
    if(!PTC08BaudRateSet(PTC08_BAUDRATE_115200))
    {
        return xfalse;
    } 
    xUARTConfigSet(PTC08_UART, 115200, (UART_CONFIG_WLEN_8 | 
                                        UART_CONFIG_STOP_ONE | 
                                        UART_CONFIG_PAR_NONE));
    return xtrue;
}
Exemplo n.º 6
0
/*
 * Initiate the Wire library and join the I2C bus as a master. This should normally be called only once.
 */
void WireClass::begin(void){
    // Enable the i2c&GPIO peripheral
    xSysCtlPeripheralEnable2(i2cPort);
    xSysCtlPeripheralEnable2(xGPIOSPinToPort(sSDA));

    // Congigure the i2c pin
    sPinTypeI2C(i2cPort);
    
    //Initialize I2C Module 100K
    xI2CMasterInit(i2cPort, 100000);
    xI2CMasterEnable(i2cPort);
    
    rxBufferIndex = 0; rxBufferLength = 0;
    txBufferIndex = 0; txBufferLength = 0;
}
Exemplo n.º 7
0
//*****************************************************************************
//
//! \brief Initialize  24LC64 and I2C
//!
//! \param None
//!
//! This function initialize the mcu I2C as master and specified I2C port.the 
//! master block will be set up to transfer data at 400 kbps.
//! 
//! \return None.
//
//*****************************************************************************
void _24LC64_Init(void)
{
    //
    // Enable GPIO Periph clock and Alternate Fuction I/O clock.
    //  
    xSysCtlPeripheralEnable(_24LC64_I2C_GPIO);
    //
    // Enable the I2C which is connected with _24LC64_
    //
    xSysCtlPeripheralEnable2(_24LC64_I2C_PORT);
    //
    // Set _24LC64_PIN_I2C_SCK as IICx.SCK
    //
    xSPinTypeI2C(_24LC64_I2C_SCK, _24LC64_PIN_I2C_SCK);
    //
    // Set _24LC64_PIN_I2C_SDA as I2Cx.SDA
    //
    xSPinTypeI2C(_24LC64_I2C_SDA, _24LC64_PIN_I2C_SDA);

    //
    // Initializes the I2C Master block.
    //
    xI2CMasterInit(_24LC64_I2C_PORT, I2C_Speed);

}
Exemplo n.º 8
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xacmp001 test.
//!
//! \return None.
//
//*****************************************************************************
static void xACMP001Setup(void)
{    
    xSysCtlPeripheralEnable2(xACMP0_BASE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_OPA1);
    xSysCtlPeripheralReset2(xACMP0_BASE);
    
    xSysCtlPeripheralEnable2(xGPIO_PORTB_BASE);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    
    xSPinTypeACMP(CMP0P, PB3);
    xSPinTypeACMP(CMP0N, PB2);
    xSPinTypeACMP(CMP0O, PB4);
    xSPinTypeACMP(CMP1P, PB6);
    xSPinTypeACMP(CMP1N, PB5);
    xSPinTypeACMP(CMP1O, PB7);
}
Exemplo n.º 9
0
//*****************************************************************************
//
//! \brief Initialize I2C
//!
//! \param None
//!
//! This function initialize the mcu I2C as master and specified I2C port.
//!
//! \note internal function, used in this file only.
//! \note The max data rate is 100KHz.
//! \return None.
//
//*****************************************************************************
static Result _I2CComPortInit(void)
{
    //I2C Max clock: 100K
    uint32_t I2CInitClkRate = 100000;

    xSysCtlPeripheralEnable(PCF8574_I2C_GPIO);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    //
    // Enable the I2C which is connected with PCF8574
    //
    xSysCtlPeripheralEnable2(PCF8574_PIN_I2C_PORT);

    //
    // Set PCF8574_PIN_I2C_SCK as I2C SCK Pin
    //
    xSPinTypeI2C(PCF8574_I2C_SCK, PCF8574_PIN_I2C_SCK);

    //
    // Set PCF8574_PIN_I2C_SDA as I2C SDA Pin
    //
    xSPinTypeI2C(PCF8574_I2C_SDA, PCF8574_PIN_I2C_SDA);

    //
    // I2C enable
    //
    xI2CMasterEnable(PCF8574_PIN_I2C_PORT);

    //
    // Initializes the I2C Master block.
    //
    xI2CMasterInit(PCF8574_PIN_I2C_PORT, I2CInitClkRate);

    return(SUCCESS);
}
Exemplo n.º 10
0
void SensorExample(void)
{
	int ADValue;
	char buf[4];
	//
    // Initionalize system clock.
    //
    xSysCtlClockSet(72000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);
    xSysCtlDelay(100000);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    xSysCtlPeripheralEnable2(sUART_BASE);
    xUARTConfigSet(sUART_BASE, 115200, (xUART_CONFIG_WLEN_8 |
									     xUART_CONFIG_STOP_1 |
									     xUART_CONFIG_PAR_NONE));
    xUARTEnable(sUART_BASE, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX));
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    sPinTypeUART(sUART_BASE);

	SensorShieldInit();

    while(1){
        ADValue = ADCValueGet(SENSOR_SHIELD_AI2);
        buf[0] = ADValue/1000 + 0x30;
        buf[1] = ADValue/100%10 + 0x30;
        buf[2] = ADValue/10%10 + 0x30;
        buf[3] = ADValue%10 + 0x30;
	    SensorShieldUARTBufferPut(sUART_BASE, buf, 4);
    }
}
Exemplo n.º 11
0
Arquivo: tc77.c Projeto: AlexGora/cox
//*****************************************************************************
//
//! \brief Initialize TC77 
//!
//! \param ulClock specifies the SPI Clock Rate
//!
//! This function is to initialize the MCU as master and specified SPI port.Set
//! TC77_PIN_SPI_CS as CS, TC77_PIN_SPI_CLK as CLK, TC77_PIN_SPI_MISO ->MISO and 
//! TC77_PIN_SPI_MOSI->MOSI,most of all it check the first conversion is finished 
//! or not in order to execute the following operation.
//! 
//! \return None.
//
//*****************************************************************************
void
TC77Init(unsigned long ulSpiClock)
{
    short sReadValue = 0;
    
    //
    // The max clock rate of TC77 is 7M Hz acoording to Datasheet, Otherwise
    // it will generate  bigger error
    //
    xASSERT((ulSpiClock > 0) && (ulSpiClock < 7000000));
    
    //
    // Enable the GPIOx port which is connected with tc77 
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_MISO));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_MOSI));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_CS));
    
    //
    // Enable the SPIx which is connected with tc77
    //
    xSysCtlPeripheralEnable2(TC77_PIN_SPI_PORT);
    
    //
    // Set TC77_PIN_SPI_CS as a chip select pin and set it as OUT_MODE
    //
    xGPIOSPinDirModeSet(TC77_PIN_SPI_CS, xGPIO_DIR_MODE_OUT);
    
    //
    // Set TC77_PIN_SPI_CLK as SPIx.CLK
    //
    xSPinTypeSPI(TC77_SPI_CLK, TC77_PIN_SPI_CLK);
    
    //
    // Set TC77_PIN_SPI_MISO as SPIx.MISO
    //
    xSPinTypeSPI(TC77_SPI_MISO, TC77_PIN_SPI_MISO);
    
    //
    // Configure MCU as a master device , 16 bits data width ,MSB first,Mode_0
    //
    xSPIConfigSet(TC77_PIN_SPI_PORT, ulSpiClock, xSPI_MOTO_FORMAT_MODE_0 |
                                                       xSPI_DATA_WIDTH16 |
                                                        xSPI_MODE_MASTER |
                                                           xSPI_MSB_FIRST);
    //
    // Disable TC77 when Power up
    //
    xGPIOSPinWrite(TC77_PIN_SPI_CS, 1);

    //
    // Wait for the first conversion completed
    //
    while(!(0x0004 & sReadValue))
    {
        sReadValue = TC77TemperRead();
    }
}
Exemplo n.º 12
0
Arquivo: adt75.c Projeto: AlexGora/cox
//*****************************************************************************
//
//! \brief Initializes the i2c master, select the power mode.
//!
//! \param rate The master baud rate  
//!
//! \ulMode - ADT75_POWER_SHOTDOWN Shut down mode
//!         - ADT75_POWER_NORMAL Power normal mode
//!
//! \return None
//
//*****************************************************************************
void ADT75Init(unsigned long ulRate, unsigned long ulPowerMode)
{
    unsigned long ulTemp;
    
    //
    // Config the I2C master
    //
    if(ADT75_MASTER_BASE == I2C0_BASE)
    {
        //
        // Congigure the i2c pin
        //
        xSPinTypeI2C(I2C0SCK, ADT75_PIN_I2CSCK);
        xSPinTypeI2C(I2C0SDA, ADT75_PIN_I2CSDA);
    }
    else if(ADT75_MASTER_BASE == I2C1_BASE)
    {
        //
        // Congigure the i2c pin
        //
        xSPinTypeI2C(I2C1SCK, ADT75_PIN_I2CSCK);
        xSPinTypeI2C(I2C1SDA, ADT75_PIN_I2CSDA);     
    }
    else
    {
        //
        // more i2c to be enable
        //
    }
    
    //
    // Config the I2C master
    //
    xSysCtlPeripheralEnable2(ADT75_MASTER_BASE);
    
    //
    // Init the device rate
    //
    xI2CMasterInit(ADT75_MASTER_BASE, ulRate);
   
    //
    // Config the shut down mode
    //
    ulTemp = ADT75RegRead(ADT75_REGISTER_CFG);
    if(ulPowerMode == ADT75_POWER_SHOTDOWN)
    {
        ulTemp |= ADT75_CFG_POWER_SHOTDOWN; 
    }
    else
    {
        ulTemp &= ~ADT75_CFG_POWER_SHOTDOWN;
    }
    
    ADT75RegWrite(ADT75_REGISTER_CFG, ulTemp);
  
}
Exemplo n.º 13
0
//*****************************************************************************
//
//! \brief Initialize AT45DB161 and SPI
//!
//! \param ulSpiClock specifies the SPI Clock Rate
//!
//! This function initialize the mcu SPI as master and specified SPI port.
//! After SPI and port was configured, the mcu send a AT45DB161_CMD_SRRD command
//! to get the page size of AT45DB161 to get prepareed for the followed read and
//! write operations.
//!
//! \return None.
//
//*****************************************************************************
void AT45DB161_Init(unsigned long ulSpiClock)
{
    unsigned char tmp;
    xASSERT((ulSpiClock > 0) && (ulSpiClock < AT45DB161_MAX_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_SCK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_CS_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_MISO));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_MOSI));
    xSysCtlPeripheralEnable2(AT45DB161_SPI_PORT);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    xGPIOSPinDirModeSet(AT45DB161_CS_PIN, xGPIO_DIR_MODE_OUT);
#if (AT45DB161_WRITE_PROTECT < 1)
    xGPIOSPinDirModeSet(FLASH_PIN_WRITE_PROTECT, xGPIO_DIR_MODE_OUT);
    xGPIOSPinWrite(FLASH_PIN_WRITE_PROTECT, 0);
#endif
    //
    // PD1 as SPI2.CLK
    //
    xSPinTypeSPI(SPI_CLK, AT45DB161_SCK);
    //
    // PD2 as SPI2.MISO
    // MISO20 => SPI0MISO
    //
    xSPinTypeSPI(SPI_MISO, AT45DB161_MISO);
    //
    // PD3 as SPI2.MOSI
    // MOSI20 => SPI0MISO
    //
    xSPinTypeSPI(SPI_MOSI, AT45DB161_MOSI);

    //xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    //
    //! Set SPI mode.
    //
    xSPIConfigSet(AT45DB161_SPI_PORT, ulSpiClock, SPI_MODE_MASTER |
                  SPI_MSB_FIRST |
                  SPI_2LINE_FULL |
                  SPI_DATA_WIDTH8 |
                  SPI_FORMAT_MODE_4);
    SPISSModeConfig(AT45DB161_SPI_PORT, SPI_CR1_SSM);
    SPISSIConfig(AT45DB161_SPI_PORT, SPI_CR1_SSI);
    SPIEnble(AT45DB161_SPI_PORT);
    AT45DB161_CS = 1;
    xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0xFF);
    xSysCtlDelay(100000);
    AT45DB161_CS = 0;
    //
    //! Read AT45DB161 state register to get the page size.
    //
    xSPISingleDataReadWrite(AT45DB161_SPI_PORT, AT45DB161_CMD_SRRD);
    tmp = xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0xFF);
    if(tmp & AT45DB161_PGSZ) AT45DB161_PageSize = 512;
    AT45DB161_CS = 1;
}
Exemplo n.º 14
0
//*****************************************************************************
//
//! \brief something should do before the test execute of xsysctl002 test.
//!
//! \return None.
//
//*****************************************************************************
static void xI2C001Setup(void)
{    
    xSysCtlPeripheralEnable2(ulSlave);
    xSysCtlPeripheralReset2(ulSlave);
    
    xSysCtlPeripheralEnable2(ulMaster);
    xSysCtlPeripheralReset2(ulMaster);
    
    xSysCtlPeripheralEnable2(GPIOB_BASE);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    
    xSPinTypeI2C(I2C1SCK, PB6);
    xSPinTypeI2C(I2C1SDA, PB7);
    //xSPinTypeI2C(I2C1SCK, PB8);
    //xSPinTypeI2C(I2C1SDA, PB9);
    
    xSPinTypeI2C(I2C2SCK, PB10);
    xSPinTypeI2C(I2C2SDA, PB11);
    
    I2CSlaveInit(ulSlave, I2C_ADDR_7BIT, 0x12, I2C_GENERAL_CALL_DIS);
    I2CEnable(ulSlave);
    I2CIntEnable(ulSlave, I2C_INT_BUF | I2C_INT_EVT | I2C_INT_ERR);
    xIntEnable(xSysCtlPeripheraIntNumGet(ulSlave));
    I2CIntCallbackInit(ulSlave, I2CSlaveCallback);
    
    I2CMasterInit(ulMaster, SysCtlAPB1ClockGet(), xfalse, xtrue);
    I2CEnable(ulMaster);
    I2CMasterWriteS1(ulMaster, 0x12, 'a', xfalse);
    I2CMasterWriteS2(ulMaster, 'b', xfalse);
    I2CMasterWriteS2(ulMaster, 'c', xfalse);
    I2CMasterWriteS2(ulMaster, 'd', xfalse);
    I2CMasterReadS1(ulMaster, 0x12, ucTemp, xfalse);
    I2CMasterReadS2(ulMaster, &ucTemp[1], xfalse);
    I2CMasterReadS2(ulMaster, &ucTemp[2], xfalse);
    I2CMasterReadS2(ulMaster, &ucTemp[3], xfalse);
    I2CMasterReadS2(ulMaster, &ucTemp[4], xtrue);
}
Exemplo n.º 15
0
//*****************************************************************************
//
//! \brief Initialize STMPE811 and I2C  
//!
//! \param None
//!
//! This function initialize the mcu I2C as master and specified I2C port.the 
//! master block will be set up to transfer data at 400 kbps.
//! 
//! \return None.
//
//*****************************************************************************
void STMPE811Init(void)
{
    //
    // Enable GPIO Periph clock and Alternate Fuction I/O clock.
    //  
    xSysCtlPeripheralEnable(STMPE811_I2C_GPIO);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    //
    // Enable the I2C which is connected with STMPE811
    //
    xSysCtlPeripheralEnable2(STMPE811_PIN_I2C_PORT);   
    //
    // Set STMPE811_PIN_I2C_SCK as IICx.SCK
    //
    xSPinTypeI2C(STMPE811_I2C_SCK, STMPE811_PIN_I2C_SCK);   
    //
    // Set STMPE811_PIN_I2C_SDA as I2Cx.SDA
    //
    xSPinTypeI2C(STMPE811_I2C_SDA, STMPE811_PIN_I2C_SDA);  
    //
    // I2C enable
    //
    xI2CMasterEnable(STMPE811_PIN_I2C_PORT);
    //
    // Initializes the I2C Master block.
    //
    xI2CMasterInit(STMPE811_PIN_I2C_PORT, I2C_Speed);
    //
    // Set INT pin.
    //
    xGPIODirModeSet(STMPE811_INT_PORT, STMPE811_INT_GPIO, xGPIO_DIR_MODE_IN);
    //
    // Set GPIO pin interrupt callback.
    //
    xGPIOPinIntCallbackInit(STMPE811_INT_PORT, STMPE811_INT_GPIO, STMPE811IntCallback);
    //  Enable GPIO pin interrupt.
    xGPIOPinIntEnable(STMPE811_INT_PORT, STMPE811_INT_GPIO, xGPIO_FALLING_EDGE);
    xIntEnable(INT_GPIO);
    // STNPE811 initializtion.
    STMPE811InitConfig();     
}
Exemplo n.º 16
0
//*****************************************************************************
//
//! \brief Init the ADC with the corresponding configuration in the
//! LPR5150AL_Configure gorup.
//!
//! \return None.
//
//*****************************************************************************
void
LPR5150ALInit()
{
	//
	// Select the ADC clock source
	//
    xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_HCLK, 3);

    //
    // Enable Peripheral ADC0
    //
    xSysCtlPeripheralEnable2(LPR5150AL_ADC_BASE);

    //
    // Configure Some GPIO pins as ADC Mode
    //
    XAXIS_PIN_IN_CFG();
    YAXIS_PIN_IN_CFG();

    //
    // Enable the ADC
    //
    xADCEnable(LPR5150AL_ADC_BASE);

    //
    // ADC Channel0 convert once, Software tirgger.
    //
    xADCConfigure(LPR5150AL_ADC_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR);

    //
    // Enable the channel2/3
    //
    xADCStepConfigure(LPR5150AL_ADC_BASE, 0, xADC_CTL_CH2);
    xADCStepConfigure(LPR5150AL_ADC_BASE, 1, xADC_CTL_CH3);

    //
    // ADC start Convert
    //
    xADCProcessorTrigger(LPR5150AL_ADC_BASE);
}
Exemplo n.º 17
0
//*****************************************************************************
//
//! \brief Dalay some time in ms.
//!
//! \param ulDelay is the delay number of ms.
//!
//! \return None.
//
//*****************************************************************************
void
DelayMS(unsigned long ulDelay)
{
    //
    // Set the timer clock
    //
    xSysCtlPeripheralClockSourceSet(LPR5150AL_TIMER_CLK, 1);

    xSysCtlPeripheralEnable2(LPR5150AL_TIMER_BASE);

	//
	// Clear the status first
	//
	xTimerStatueClear(LPR5150AL_TIMER_BASE, xTIMER_CHANNEL0, xTIMER_INT_MATCH);

    //
    // Config as periodic mode
    //
    xTimerInitConfig(LPR5150AL_TIMER_BASE, xTIMER_CHANNEL0, xTIMER_MODE_PERIODIC, 1000);
    xTimerIntEnable(LPR5150AL_TIMER_BASE, xTIMER_CHANNEL0, xTIMER_INT_MATCH);
    xTimerStart(LPR5150AL_TIMER_BASE, xTIMER_CHANNEL0);

    //
    // Delay ulDelay cycles, one cycle delay is 1ms.
    //
    while(ulDelay)
	{
	    while(!xTimerStatusGet(LPR5150AL_TIMER_BASE, xTIMER_CHANNEL0, xTIMER_INT_MATCH));
		xTimerStatueClear(LPR5150AL_TIMER_BASE, xTIMER_CHANNEL0, xTIMER_INT_MATCH);
		ulDelay--;
	}

    //
    // Stop the timer
    //
	xTimerStop(LPR5150AL_TIMER_BASE, xTIMER_CHANNEL0);
	xSysCtlPeripheralDisable2(LPR5150AL_TIMER_BASE);

}
Exemplo n.º 18
0
//*****************************************************************************
//
//! \brief Init the SPLC780D LCD Device.
//!
//! \param None.
//!
//! This function is used to Init the SPLC780 Device. It must be call before 
//! any other LCD function use.
//!
//! It Open the pins's GPIO peripheral port, and config the pins type to GPIO 
//! output. Then config the LCD into the default state, clear the LCD and 
//! Open the display. Default A Blink cursor is set on. The LCD cursor move 
//! direction is config as increment default.
//!
//! The SPLC780 Initial state can be determined by the \ref SPLC780_Config.
//! - Pins that used is determined by \ref SPLC780D_Config_Pins.
//! - The inteface data length is determined by \ref SPLC780D_INTERFACE_DATA_LEN.
//! - The LCD display line is determined by \ref SPLC780D_DISPLAY_LINE.
//! - The LCD character font is determined by \ref SPLC780D_CHARACTER_FONT.
//! .
//! 
//! \return None.
//
//*****************************************************************************
void 
SPLC780Init(void)
{ 
    //
    // Enable and Configure I2C that used
    //
    xSysCtlPeripheralEnable2(ulMaster);

    xSysCtlPeripheralEnable2(GPIOB_BASE);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    
    xSPinTypeI2C(I2C1SCK, PB6);
    xSPinTypeI2C(I2C1SDA, PB7);

    xI2CMasterInit(ulMaster, 400000);
    //
    // I2C enable
    //
    xI2CMasterEnable(ulMaster); 

    SPLC780Write4Bit(0x30);
    xSysCtlDelay(720000);    // Wait time > 4.1 ms
    SPLC780Write4Bit(0x30);
    xSysCtlDelay(200);       // Wait time > 100 us
    SPLC780Write4Bit(0x30);
    xSysCtlDelay(200);
		
		while(SPLC780Busy());    // BF can be checked after the following instructions
    SPLC780Write4Bit(0x20);
		
    //
    // Set Entry Mode: Interface Data Length, Character Font, Display Line
    //
    while(SPLC780Busy()); 
#if (defined(SPLC780_DISPLAY_LINE) && (SPLC780_DISPLAY_LINE == 2))
    SPLC780WriteCmd(SPLC780_CMD_FUNCTION_SET(SPLC780_INTERFACE_DATA_LEN | 
                                             SPLC780_FUNCTION_SET_N_2 |
                                             SPLC780_CHARACTER_FONT)); // 0x28
#endif
    
#if (defined(SPLC780_DISPLAY_LINE) && (SPLC780_DISPLAY_LINE == 1))    
    SPLC780WriteCmd(SPLC780_CMD_FUNCTION_SET(SPLC780_INTERFACE_DATA_LEN | 
                                             SPLC780_FUNCTION_SET_N_1 |
                                             SPLC780_CHARACTER_FONT)); // 0x20
#endif    
    
    //
    // Display on & Cursor Blink
    //
    while(SPLC780Busy());
    SPLC780WriteCmd(SPLC780_CMD_DISPLAY_CTRL(SPLC780_DISPLAY_CTRL_D |
                                             0 |
                                             SPLC780_DISPLAY_CTRL_B)); //0x0d

    //
    // Clear LCD
    //    
    while(SPLC780Busy());
    SPLC780WriteCmd(SPLC780_CMD_CLS); //0x01

    //
    // Cursor Move Mode: Increment
    //
    while(SPLC780Busy());
    SPLC780WriteCmd(SPLC780_CMD_ENTRY_MODE_SET(SPLC780_ENTRY_MODE_SET_ID_INC | 0)); //0x06  
}
Exemplo n.º 19
0
Arquivo: CH376.c Projeto: AlexGora/cox
//*****************************************************************************
//
//! \brief MCU communication port initialize
//!
//! \param None
//!
//! \return None.
//
//*****************************************************************************
void	CH376PortInit( void )
{
#ifdef CH376_INT_WIRE
    xSysCtlPeripheralEnable2(CH376_INT_PORT);
    xGPIOSPinDirModeSet(CH376_INT_PIN, xGPIO_DIR_MODE_IN); //pass
    xGPIOSPinWrite(CH376_INT_PIN, 1);
#endif
#ifdef CH376_USE_HARDWARE_SPI
    xSysCtlPeripheralEnable2(CH376_SPI_CS_PORT);
    xGPIOSPinDirModeSet(CH376_SPI_CS_PIN, xGPIO_DIR_MODE_OUT);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_SCK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_MOSI));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_MISO));
    xSysCtlPeripheralEnable2(CH376_SPI_PORT);

    xSPinTypeSPI(CH376SPI_CLK, CH376_SCK);
    xSPinTypeSPI(CH376SPI_MISO, CH376_MISO);
    xSPinTypeSPI(CH376SPI_MOSI, CH376_MOSI);

    xSPIConfigSet(CH376_SPI_PORT, CH376_CLK_FREQ, SPI_MODE_MASTER |
    		            xSPI_MOTO_FORMAT_MODE_3 |
    		            xSPI_MODE_MASTER |
    		            xSPI_MSB_FIRST |
    		            xSPI_DATA_WIDTH8);
//    SPISSModeConfig(CH376_SPI_PORT, SPI_CR1_SSM);
//    SPISSIConfig(CH376_SPI_PORT, SPI_CR1_SSI);
    xSPISSSet( CH376_SPI_PORT, xSPI_SS_SOFTWARE, xSPI_SS0 );
    SPIEnble(CH376_SPI_PORT);
    CH376_SPI_CS_SET;
#endif  //End of CH376_USE_HARDWARE_SPI define

#ifdef CH376_USE_SOFTWARE_SPI
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_SCK_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_MISO_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_MOSI_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_SPI_CS_PIN));

    xGPIOSPinDirModeSet(CH376_SPI_CS_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_SCK_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_MOSI_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_MISO_PIN, xGPIO_DIR_MODE_IN);
    CH376_SPI_CS_SET;
#endif  //End of CH376_USE_SOFTWARE_SPI define

#ifdef CH376_USE_PARALLEL
    xSysCtlPeripheralEnable2(CH376_WR_PORT);
    xSysCtlPeripheralEnable2(CH376_RD_PORT);
    xSysCtlPeripheralEnable2(CH376_A0_PORT);
    xSysCtlPeripheralEnable2(CH376_PCS_PORT);
    xSysCtlPeripheralEnable2(CH376_DATA_PORT);
    xGPIOSPinDirModeSet(CH376_WR_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_RD_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_A0_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_PCS_PIN, xGPIO_DIR_MODE_OUT);
    xGPIODirModeSet( CH376_DATA_PORT, 0xFF, xGPIO_DIR_MODE_IN );
    CH376_PCS_SET;
    CH376_WR_SET;
    CH376_RD_SET;
    CH376_A0_CLR;
#endif  //End of CH376_USE_PARALLEL define

}
Exemplo n.º 20
0
//*****************************************************************************
//
//! \brief Init the HD44780 LCD Device.
//!
//! \param None.
//!
//! This function is used to Init the HD44780 Device. It must be call before 
//! any other LCD function use.
//!
//! It Open the pins's GPIO peripheral port, and config the pins type to GPIO 
//! output. Then config the LCD into the default state, clear the LCD and 
//! Open the display. Default A Blink cursor is set on. The LCD cursor move 
//! direction is config as increment default.
//!
//! The HD44780 Initial state can be determined by the \ref HD44780_Config.
//! - Pins that used is determined by \ref HD44780_Config_Pins.
//! - The inteface data length is determined by \ref HD44780_INTERFACE_DATA_LEN.
//! - The LCD display line is determined by \ref HD44780_DISPLAY_LINE.
//! - The LCD character font is determined by \ref HD44780_CHARACTER_FONT.
//! .
//! 
//! \return None.
//
//*****************************************************************************
void 
HD44780Init(void)
{
	ucDisplayFunction = (HD44780_INTERFACE_DATA_LEN |
                         HD44780_FUNCTION_SET_N_2 |
                         HD44780_CHARACTER_FONT);
	ucRsPin = 1;
	ucRwPin = 255;
	ucEnablePin = 2;
	ucDataPin[0] = 6;
	ucDataPin[1] = 5;
	ucDataPin[2] = 4;
	ucDataPin[3] = 3;
	_SPIbuff = 0;

    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(HD44780_PIN_CS));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(HD44780_PIN_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(HD44780_PIN_MOSI));
     

#if HD44780_SPI_MODE == SPIMODE_HARDWARE
    //
    // Enable Peripheral SPI1
    //
    xSysCtlPeripheralEnable2(HD44780_SPI);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    //
    // Configure Some GPIO pins as SPI Mode    SPI MISO is no use in LCD4884
    //
    xSPinTypeSPI(HD44780_CLK,HD44780_PIN_CLK);
    xSPinTypeSPI(HD44780_MOSI,HD44780_PIN_MOSI);
    xGPIOSPinTypeGPIOOutput(HD44780_PIN_CS);

    //
    // Configure SPI  SPI1,ulRate
    //
    xSPIConfigSet((HD44780_SPI), HD44780_SPI_BAUDRATE,
    	SPI_FORMAT_MODE_3 | SPI_DATA_WIDTH8 | SPI_MSB_FIRST | SPI_MODE_MASTER);

    //
    //! \note Enanble SPI SS,test on M0516LBN.other mcu there may need modify.
    //
    xSPISSSet((HD44780_SPI), xSPI_SS_SOFTWARE, xSPI_SS0);
    xSPIEnable(HD44780_SPI);
#else
    //
    // Set Pins Type to GPIO Output
    //

    xGPIOSPinTypeGPIOOutput(HD44780_PIN_CS);
    xGPIOSPinTypeGPIOOutput(HD44780_PIN_CLK);
    xGPIOSPinTypeGPIOOutput(HD44780_PIN_MOSI);
#endif

    //
    // Output default value : E disable
    //

    //
    // Set Entry Mode: Interface Data Length, Character Font, Display Line
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_FUNCTION_SET(HD44780_INTERFACE_DATA_LEN |
                                             HD44780_FUNCTION_SET_N_2 |
                                             HD44780_CHARACTER_FONT));

    //
    // Display on & Cursor Blink
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_DISPLAY_CTRL(HD44780_DISPLAY_CTRL_D |
                                             0 |
                                             HD44780_DISPLAY_CTRL_B));

    //
    // Clear LCD
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_CLS);

    //
    // Cursor Move Mode: Increment
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_ENTRY_MODE_SET(HD44780_ENTRY_MODE_SET_ID_INC |
                                               0));
    
}
Exemplo n.º 21
0
//*****************************************************************************
//
//! \brief Initialize the sensor shield board.
//!
//! \param None.
//!
//! Initialize the sensor shield board.
//!
//! \return None
//
//*****************************************************************************
void
SensorShieldInit(void)
{
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O0));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O1));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O2));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O3));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O4));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O5));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I0));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I1));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I2));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I3));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I4));
	xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I5));
#if(SENSOR_SHIELD_OUT_USED > 0)

    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O0);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O1);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O2);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O3);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O4);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O5);
    //xSysCtlPeripheralEnable2();
#endif

#if((SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG))

    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(sD45));

    //
    // Set ADCCLK prescaler, ADCCLK=PCLK2(max 72MHz)/Div(Div:2,4,6,8)
    // You should set ADCCLK < 14MHz to ensure the accuracy of ADC
    //
    xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_MAIN, 8);
    //
    // Enable Peripheral ADC clock
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_ADC1);


    //
    // Enable the ADC conversion
    //
    xADCEnable(sADC_BASE);

    //
    // The two sentences below configure ADC to scan mode, continuous convert, software trigger.
    //
    xADCConfigure(sADC_BASE, xADC_MODE_SCAN_SINGLE_CYCLE, ADC_TRIGGER_PROCESSOR);
    xADCConfigure(sADC_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR);

    //
    // Configure channel step by step.(Max 4 steps, the 2nd parameter start from 0, max is 3)
    // Must not jump over a step, or the ADC result may be in wrong position.
    //
    xADCStepConfigure(sADC_BASE, 0, sADC_CH0);
    xADCStepConfigure(sADC_BASE, 1, sADC_CH1);
    xADCStepConfigure(sADC_BASE, 2, sADC_CH2);
    xADCStepConfigure(sADC_BASE, 3, sADC_CH3);

#endif

#if(SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG)
    sA0PinTypeADC();
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I0);
#endif

#if(SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG)
    sA1PinTypeADC();
#elif (SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I1);
#endif

#if(SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG)
    sA2PinTypeADC();
#elif (SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I2);
#endif

#if(SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG)
    sA3PinTypeADC();
#elif (SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I3);
#endif

#if(SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG)||  \
       (SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I4);
#endif

#if(SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG)||  \
	   (SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I5);
#endif

#if(SENSOR_SHIELD_I2C_USED > 0)
    //
    // Enable the GPIOx port which is connected with I2C
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SDA));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SCK));

    //
    // Enable the I2Cx which is connected with device
    //
    xSysCtlPeripheralEnable2(sI2C_BASE);

    //
    // Set BH1750_PIN_I2C_CLK as CLK
    //
    sPinTypeI2C(sI2C_BASE);

    //
    // Configure MCU as a master device and Set Clcok Rates
    //
    xI2CMasterInit(sI2C_BASE, 100000);
    xI2CMasterEnable(sI2C_BASE);
#endif

#if(SENSOR_SHIELD_UART_USED > 0)
    xSysCtlPeripheralEnable2(sUART_BASE);
//    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART1_MAIN, 1);
    sPinTypeUART(sUART_BASE);
    xUARTConfigSet(sUART_BASE, 115200, (xUART_CONFIG_WLEN_8 |
                                        xUART_CONFIG_STOP_1 |
                                        xUART_CONFIG_PAR_NONE));
#endif
}
Exemplo n.º 22
0
//*****************************************************************************
//
//! \brief Init the sensor shield board.
//!
//! \param None.
//!
//! Init the sensor shield board.
//!
//! \return None
//
//*****************************************************************************
void
SensorShieldInit(void)
{
#if(SENSOR_SHIELD_OUT_USED > 0)
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O0);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O1);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O2);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O3);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O4);
    xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O5);

#endif

#if((SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG) ||                    \
    (SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG))

    xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_HCLK, 3);
    //
    // Enable Peripheral ADC0
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_ADC0);

    //
    // Configure Some GPIO pins as ADC Mode
    //

    //
    // Enable the adc
    //
    xADCEnable(xADC0_BASE);

    //
    // ADC Channel0 convert once, Software tirgger.
    //
    xADCConfigure(xADC0_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR);

    //
    // Enable the channel0
    //

    //
    // Set Compare Condition(Moisture Sensor Limited Value)
    //
    xADCCompConditionConfig(ADC_BASE, 0, xADC_COMP_INT_LOW);
    ADCCompDataSet(ADC_BASE, 0, 1600, 1);
    xADCCompEnable(ADC_BASE, 0);
    //
    // Enable the ADC end of conversion interrupt
    //
    xADCIntEnable(xADC0_BASE, xADC_INT_COMP);

    //
    // install the call back interrupt
    //
    xADCIntCallbackInit(xADC0_BASE, ADCCallback);

    //
    // Enable the NVIC ADC interrupt
    //
    xIntEnable(xINT_ADC0);

    xADCProcessorTrigger(xADC0_BASE);

#endif

#if(SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG)
    sA0PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH0);

#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A0);
#endif

#if(SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG)
    sA1PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH1);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A1);
#endif

#if(SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG)
    sA2PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH2);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A2);
#endif

#if(SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG)
    sA3PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH3);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A3);
#endif

#if(SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG)
    sA4PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH4);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A4);
#endif

#if(SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG)
    sA5PinTypeADC();
    xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH5);
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A5);
#endif

#if(SENSOR_SHIELD_I2C_USED > 0)
    //
    // Enable the GPIOx port which is connected with I2C
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SDA));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SCK));

    //
    // Enable the I2Cx which is connected with device
    //
    xSysCtlPeripheralEnable2(sI2C_BASE);

    //
    // Set BH1750_PIN_I2C_CLK as CLK
    //
    sPinTypeI2C(sI2C_BASE);

    //
    // Configure MCU as a master device and Set Clcok Rates
    //
    xI2CMasterInit(sI2C_BASE, 100000);
    xI2CMasterEnable(sI2C_BASE);
#endif

#if(SENSOR_SHIELD_UART_USED > 0)
    xSysCtlPeripheralEnable2(sUART_BASE);
    xSysCtlPeripheralClockSourceSet(xSYSCTL_UART1_MAIN, 1);
    sPinTypeUART(sUART_BASE);
    xUARTConfigSet(sUART_BASE, 115200, (xUART_CONFIG_WLEN_8 |
                                        xUART_CONFIG_STOP_1 |
                                        xUART_CONFIG_PAR_NONE));
#endif
}
Exemplo n.º 23
0
//*****************************************************************************
//
//! \brief Init the UC1701 LCD.
//!
//! \param ulSpiClock SPI clock to select.
//!
//! This function initialize the mcu SPI as master and specified SPI port.
//!
//! \return None.
//
//*****************************************************************************
void UC1701Init(unsigned long ulSpiClock)
{
    //
    // Enable the GPIOx port which is connected with UC1701
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_SPI_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_SPI_CS));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_SPI_MOSI));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_CD));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_RESET));
    
    //
    // Enable the SPIx which is connected with UC1701
    //
    xSysCtlPeripheralEnable2(LCD_PIN_SPI_PORT);
    xSysCtlPeripheralReset2(LCD_PIN_SPI_PORT);
    //
    // Set the chip select pin as OUT_MODE
    //
    xGPIOSPinDirModeSet(LCD_PIN_SPI_CS, xGPIO_DIR_MODE_OUT);
    //
    // Set the chip reset pin as OUT_MODE
    //
    xGPIOSPinDirModeSet(LCD_PIN_CD, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(LCD_PIN_RESET, xGPIO_DIR_MODE_OUT);
    
    xSPinTypeSPI(SPI_CLK, LCD_PIN_SPI_CLK);
    xSPinTypeSPI(SPI_MOSI, LCD_PIN_SPI_MOSI);
    
    //
    // Configure MCU as a master device , 8 bits data width ,MSB first,Mode_0
    //
    xSPIConfigSet(LCD_PIN_SPI_PORT, ulSpiClock, xSPI_MOTO_FORMAT_MODE_1 |
                                                xSPI_MODE_MASTER | 
                                                xSPI_MSB_FIRST |
                                                xSPI_DATA_WIDTH8);
    //
    // Disable UC1701 when Power up
    //
    xGPIOSPinWrite(LCD_PIN_SPI_CS, 1);

    //
    // Reset the chip
    //
    xGPIOSPinWrite(LCD_PIN_RESET, 0);
    delay_ms(2);
    xGPIOSPinWrite(LCD_PIN_RESET, 1);
    delay_ms(6);

    //
    // Initial Configuration
    //
    UC1701CmdWrite(0xe2);//System Reset
	UC1701CmdWrite(0x2c);//Power Rise Step1
	delay_ms(8);
	UC1701CmdWrite(0x2e);//Power Rise Step2
	delay_ms(8);
	UC1701CmdWrite(0x2f);//Power Rise Step3
	delay_ms(8);
	UC1701CmdWrite(0x23);
	UC1701DoubleCmdWrite(0x81, 0x1f);//Set LCD resistor ratio

	UC1701CmdWrite(0xa2);//Bias 1/9
	UC1701CmdWrite(0xc0);//Set COM Direction
	UC1701CmdWrite(0xa0);//Set SEG Direction
	UC1701CmdWrite(0x40);//Set Scroll Line: the first line
	UC1701CmdWrite(0xaf);//Display Enable

}