예제 #1
0
//*****************************************************************************
//
//! \brief Init GPIO of the sensor shield board.
//!
//! \param None.
//!
//! Init GPIO of the sensor shield board.
//!
//! \return None
//
//*****************************************************************************
void
SensorShieldIOInit(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);
	  xGPIOSPinWrite(SENSOR_SHIELD_O5, 1);

#endif

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

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

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

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

#if(SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG)
    sA4PinTypeADC();
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A4);
#endif

#if(SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG)
    sA5PinTypeADC();
#elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL)
    xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A5);
#endif

#if(SENSOR_SHIELD_I2C_USED > 0)
    sPinTypeI2C(sI2C_BASE);
#endif

#if(SENSOR_SHIELD_UART_USED > 0)
    sPinTypeUART(sUART_BASE);
#endif
}
예제 #2
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
}
예제 #3
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
}