//***************************************************************************** // //! \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); }
//***************************************************************************** // //! \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); }
//***************************************************************************** // //! \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); }
/* * 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; }
//***************************************************************************** // //! \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(); }
//***************************************************************************** // //! \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 }
//***************************************************************************** // //! \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 }
//***************************************************************************** // //! \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 }