//***************************************************************************** // //! \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; }
void UART_example(void) { unsigned int i = 0; // // Configure System clock // xSysCtlClockSet(84000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ); SysCtlDelay(10000); // // Enable GPIO/UART Clock // xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOG); // // Remap UART pin to GPIO Port UART0_RX --> PG1 UART0_TX --> PG2 xSPinTypeUART(UART0RX, PG1); xSPinTypeUART(UART0TX, PG2); // // Configure UART Baud 115200 8-N-1 // xUARTConfigSet(xUART0_BASE, 115200, xUART_CONFIG_WLEN_8 | xUART_CONFIG_PAR_NONE | xUART_CONFIG_STOP_1); // // Enable UART Receive/Transmit // xUARTEnable(xUART0_BASE, xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX); // // print out welcome information // i = 0; while(Buf[i] != '\0') { xUARTCharPut(xUART0_BASE, Buf[i++]); } // // Echo user's input information // while((Rec = UxARTCharGet(xUART0_BASE)) != '\n') { xUARTCharPut(xUART0_BASE, Rec); } // // print out run over information // i = 0; while(Buf[i] != '\0') { xUARTCharPut(xUART0_BASE, End[i++]); } while(1); }
//***************************************************************************** // //! \brief print some data to terminal. //! //! \param None //! //! \return None. // //***************************************************************************** void UartPrintf(void) { unsigned long i; // //Set System Clock // xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); xSysCtlDelay(10000); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOD); xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO); xSPinTypeUART(UART1TX,PA9); xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1); xUARTConfigSet(USART1_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); xUARTEnable(USART1_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX)); for(i = 0; i < sizeof("STM32F1xx.UART Example of CoX \r\n"); i++) { xUARTCharPut(USART1_BASE, ucData[i]); } }
//***************************************************************************** // //! \brief Init uart to print. //! //! \param None //! //! \details uart config as (115200, 8 data bit, 1 stop bit , no partiy) //! //! \return None. // //***************************************************************************** static void UartInit(void) { xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO); xSPinTypeUART(UART0RX, PC10); xSPinTypeUART(UART0TX, PC8); xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0); // // Set UART0 clock source. // SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART_S_HCLK); // // Configure 8 bit word length, 1 stop bit, // and none parity bit, receive FIFO 1 byte. // xUARTConfigSet(UART0_BASE, 115200, (xUART_CONFIG_WLEN_8 | xUART_CONFIG_STOP_1 | xUART_CONFIG_PAR_NONE)); xUARTEnable(UART0_BASE, (UART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX)); }
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); } }
void DeltaAngleGet() { tLPR5150ALData g_XYAxisCurrentVoltage; tLPR5150ALData g_XYAxisNullVoltage; tLPR5150ALData g_XYAxisAngle; tLPR5150ALData g_XYAxisRate; xSysCtlClockSet(12000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ); xSysCtlDelay(1000); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(sD13)); xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_MAIN, 1); sPinTypeUART(sUART_DBG_BASE); xUARTConfigSet(sUART_DBG_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); xUARTEnable(sUART_DBG_BASE, (UART_BLOCK_UART | UART_BLOCK_RX)); //automatically added by CoIDE //ADConvert(); xSysCtlClockSet(12000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ); LPR5150ALInit(); while(1) { g_XYAxisAngle = LPR5150ALXYAxisAngleGet(); printf("The roll angle is: %f ", g_XYAxisAngle.fXAxisData); printf("The pitch angle is: %f \r\n", g_XYAxisAngle.fYAxisData); //DelayMS(500); } }
//***************************************************************************** // //! Something should do after the test execute of xuart001 test. //! //! \return None. // //***************************************************************************** static void xuart003TearDown(void) { xUARTConfigSet(USART2_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); xUARTEnable(USART2_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX)); }
//***************************************************************************** // //! \brief initialize USART for debugging use //! //! \param None //! //! \details Initialize USART1 for debugging use. Debugging will use printf function, //! so we use USART1 as the debugging tool. Don't forget to add and transplant printf.c. //! If you don't need debugging or you have your own debugging function, remove this //! function. //! //! \return None // //***************************************************************************** void mInitSTDIO( void ) { xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA); xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1); xUARTConfigSet(xUART1_BASE, 115200, (xUART_CONFIG_WLEN_8 | xUART_CONFIG_STOP_1 | xUART_CONFIG_PAR_NONE)); xUARTEnable(xUART1_BASE, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX)); xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO); xSPinTypeUART(UART1TX, PA9); }
//***************************************************************************** // //! \brief Init uart to print. //! //! \param None //! //! \details uart config as (115200, 8 data bit, 1 stop bit , no partiy) //! //! \return None. // //***************************************************************************** static void UartInit(void) { xSPinTypeUART(UART0RX,PB0); xSPinTypeUART(UART0TX,PB1); xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0); xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_MAIN, 1); xUARTConfigSet(UART0_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); }
void TestIOInit(void) { xSysCtlClockSet(50000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ); SysCtlDelay(10000); xSPinTypeUART(UART0RX,PB0); xSPinTypeUART(UART0TX,PB1); xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0); xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_MAIN, 1); xUARTConfigSet(UART0_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); xUARTEnable(UART0_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX)); }
////////////////////////////////////////////////////////////////////////////// // Platform (STM32F103X) initialization for peripherals as GPIO, SPI, UARTs // ////////////////////////////////////////////////////////////////////////////// void platform_init(void) { xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); xSysCtlDelay((xSysCtlClockGet()/1000)*50); // wait 50ms /**************************/ /* GPIO_A For SPI CS PIN */// It must be first to enable GPIO peripheral than other peripheral. (Otherwise, UART do not run in STM32F103X) /**************************/ xSysCtlPeripheralEnable( xSYSCTL_PERIPH_GPIOA ); xGPIODirModeSet(xGPIO_PORTA_BASE, xGPIO_PIN_4, xGPIO_DIR_MODE_OUT); /************/ /* For UART */ /************/ xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1); xSPinTypeUART(UART1TX,PA9); xSPinTypeUART(UART1RX,PA10); xUARTConfigSet(xUART1_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); xUARTEnable(xUART1_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX)); /***********/ /* For SPI */ /***********/ xSysCtlPeripheralReset(WIZCHIP_SPI_PERIPH); xSysCtlPeripheralEnable(WIZCHIP_SPI_PERIPH); xSPinTypeSPI(WIZCHIP_SPI_CLK, WIZCHIP_SPI_CLK_PIN); // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_5, GPIO_TYPE_AFOUT_STD, GPIO_OUT_SPEED_50M); xSPinTypeSPI(WIZCHIP_SPI_MOSI,WIZCHIP_SPI_MOSI_PIN); // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_7, GPIO_TYPE_AFOUT_STD, GPIO_OUT_SPEED_50M); xSPinTypeSPI(WIZCHIP_SPI_MISO,WIZCHIP_SPI_MISO_PIN); // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_6, GPIO_TYPE_IN_FLOATING, GPIO_IN_SPEED_FIXED); xSPIConfigSet(WIZCHIP_SPI_BASE, xSysCtlClockGet()/2, xSPI_MOTO_FORMAT_MODE_0 | xSPI_MODE_MASTER | xSPI_MSB_FIRST | xSPI_DATA_WIDTH8); xSPISSSet(WIZCHIP_SPI_BASE, SPI_SS_SOFTWARE, xSPI_SS_NONE); xSPIEnable(WIZCHIP_SPI_BASE); printf("HCLK = %dMHz\r\n", (unsigned int)(xSysCtlClockGet()/1000000)); }
void uartprinntf() { xSysCtlClockSet(84000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_12MHZ); xSysCtlDelay(10000); xSPinTypeUART(UART0RX,PG1); xSPinTypeUART(UART0TX,PG2); xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0); // // Config 8 bit word length, 1 stop bit, // and none parity bit, receive FIFO 1 byte. // xUARTConfigSet(xUART0_BASE, 115200, (xUART_CONFIG_WLEN_8 | \ xUART_CONFIG_STOP_1 | \ xUART_CONFIG_PAR_NONE)); xUARTEnable(xUART0_BASE, (xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX)); UARTBufferWrite(UART0_BASE, "NUC1xx.UART.BAUDRATE EXAMPLE \r\n", sizeof("NUC1xx.UART.BAUDRATE EXAMPLE \r\n")); }
//***************************************************************************** // //! \brief print some data to terminal. //! //! \param None //! //! \return None. // //***************************************************************************** void UartPrintf(void) { unsigned long i; // //Set System Clock // xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); xSysCtlDelay(10000); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO); xSPinTypeUART(UART0RX, PA8); xSPinTypeUART(UART0TX, PA9); xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART0); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART0); // // Set UART0 clock source. // xSysCtlPeripheralClockSourceSet(xSYSCTL_UART0_HCLK, 1); // // Configure 8 bit word length, 1 stop bit, // and none parity bit, receive FIFO 1 byte. // xUARTConfigSet(UART0_BASE, 115200, (xUART_CONFIG_WLEN_8 | xUART_CONFIG_STOP_1 | xUART_CONFIG_PAR_NONE)); xUARTEnable(UART0_BASE, (UART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX)); for(i = 0; i < sizeof("HT32F125x.UART Example of CoX \r\n"); i++) { xUARTCharPut(UART0_BASE, ucData[i]); } }
void TestIOInit(void) { xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); SysCtlDelay(10000); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA); //xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO); //xSPinTypeUART(UART1RX,PA10); xSPinTypeUART(UART1TX,PA9); xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1); //SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART_S_EXT12M); xUARTConfigSet(USART1_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); xUARTEnable(USART1_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX)); }
void RTCTickInt() { xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); xSysCtlPeripheralEnable(SYSCTL_PERIPH_PWR); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA); SysCtlBackupAccessEnable(); SysCtlLSEConfig(SYSCTL_LSE_OSC_EN); SysCtlPeripheralClockSourceSet(SYSCTL_RTC_LSE); xSysCtlPeripheralEnable(SYSCTL_PERIPH_RTC); SysCtlDelay(10000); xSPinTypeUART(UART1RX,PA10); xSPinTypeUART(UART1TX,PA9); xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1); xUARTConfigSet(xUART1_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); xUARTEnable(xUART1_BASE, UART_BLOCK_UART | UART_BLOCK_RX | UART_BLOCK_TX); UARTBufferWrite(xUART1_BASE, "usart init is ok!", sizeof("usart init is ok!")-1); RTCTimeInit(0X7FFF); tTime1.ulSecond = 20; tTime1.ulMinute = 10; tTime1.ulHour = 11; tTime1.ulMDay = 13; tTime1.ulMonth = 6; tTime1.ulYear = 2012; tTime1.ulWDay = 3; // // Writes current time to corresponding register. // RTCTimeWrite(&tTime1, ulTimeAlarm[0]); SysCtlDelay(10000); RTCIntCallbackInit(xRTCCallback); // // Enables tick interrupt. // RTCIntEnable(RTC_INT_TIME_TICK); xIntEnable(INT_RTC); xIntMasterEnable(); while(ulj < 2); xIntMasterDisable(); RTCTimeRead(&tTime1, ulTimeAlarm[0]); }
void Blinky(void) { volatile int i = 0; // // Initionalize system clock. // xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); // // Configure LED and USB Disc Port // xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOB); xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO); xGPIOPinConfigure(PB4(APP), PB4); // // Configure UART Pin // PA9-->TX PA10-->RX // xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA); xSPinTypeUART(UART1TX, PA9); xSPinTypeUART(UART1RX, PA10); //xSPinTypeUART(UART2TX, PA2); //xSPinTypeUART(UART2RX, PA3); // // Configure UART1 115200 8-N-1 // xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1); xUARTConfigSet(USART1_BASE, 115200, xUART_CONFIG_WLEN_8 | xUART_CONFIG_STOP_1 | xUART_CONFIG_PAR_NONE); xUARTEnable(USART1_BASE, xUART_BLOCK_UART | xUART_BLOCK_TX | xUART_BLOCK_RX); PrintStr("Embedded Pi Board Test Begin\r\n"); PrintStr("1:LED Test, Now LED will Light\r\n"); // // Configure LED Port // xGPIODirModeSet( xGPIO_PORTB_BASE, xGPIO_PIN_13, xGPIO_DIR_MODE_OUT ); xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_13 , 1 ); xSysCtlDelay(MAX_TICK*10); PrintStr("2: USB Disc Test, Now you computer will find a new device\r\n"); PrintStr("And LED is Blinking\r\n"); xGPIODirModeSet( xGPIO_PORTB_BASE, xGPIO_PIN_4, xGPIO_DIR_MODE_OUT ); xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_4 , 0 ); // // Shane LED to indicate that USB Disc is PROCESSING // for(i = 0; i < 10; i++) { // // Turn on LED // xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_13 , 1 ); xSysCtlDelay(MAX_TICK); // // Turn off LED // xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_13 , 0 ); xSysCtlDelay(MAX_TICK); } PrintStr("Now, USB Disc test is over and led will be turned off\r\n"); // // Turn off LED, USB Disc is over // xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_4 , 1 ); xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_13 , 0 ); //Configure PB4 to Jtag Mode AFIO_DEBUG_REG &= 0x00FFFFFF; // // Test Low Speed External crystal // PrintStr("3: Low Speed External crystal test begin\r\n"); PrintStr("If you can't see OK later, then test is failure\r\n"); xSysCtlPeripheralEnable(SYSCTL_PERIPH_PWR | SYSCTL_PERIPH_BKP); SysCtlBackupAccessEnable(); SysCtlLSEConfig(SYSCTL_LSE_OSC_EN); PrintStr("OK\r\n"); PrintStr("Running"); while(1) { xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_13 , 1 ); PrintStr("."); xSysCtlDelay(10*MAX_TICK); xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_13 , 0 ); PrintStr("."); xSysCtlDelay(10*MAX_TICK); xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_13 , 1 ); PrintStr("."); xSysCtlDelay(10*MAX_TICK); xGPIOPinWrite( xGPIO_PORTB_BASE, xGPIO_PIN_13 , 0 ); PrintStr("."); xSysCtlDelay(10*MAX_TICK); PrintStr("\b\b\b\b \b\b\b\b"); } }
//***************************************************************************** // //! \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 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 }