/** * Function documented in platform/uart.h */ otError otPlatUartEnable(void) { PRCMPowerDomainOn(PRCM_DOMAIN_SERIAL); while (PRCMPowerDomainStatus(PRCM_DOMAIN_SERIAL) != PRCM_DOMAIN_POWER_ON); PRCMPeripheralRunEnable(PRCM_PERIPH_UART0); PRCMPeripheralSleepEnable(PRCM_PERIPH_UART0); PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_UART0); PRCMLoadSet(); while (!PRCMLoadGet()); IOCPinTypeUart(UART0_BASE, IOID_2, IOID_3, IOID_UNUSED, IOID_UNUSED); UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); UARTIntRegister(UART0_BASE, UART0_intHandler); UARTEnable(UART0_BASE); return OT_ERROR_NONE; }
void uartb_init(unsigned long speed){ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1); GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); SysCtlPeripheralDisable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(UART_BUFFERIZED_PERIF); // Initialize the UART. Set the baud rate, number of data bits, turn off // parity, number of stop bits, and stick mode. UARTConfigSetExpClk(UART_BUFFERIZED_BASE, SysCtlClockGet(), speed, UART_BUFFERIZED_FLAGS); // Enable the UART. UARTEnable(UART_BUFFERIZED_BASE); // Use hardware FIFO to reduce the amount of interruptions UARTFIFOEnable(UART_BUFFERIZED_BASE); // Set fifo limit for interruption triggering at 7/8 th of the fifo size UARTFIFOLevelSet(UART_BUFFERIZED_BASE,UART_FIFO_TX7_8,UART_FIFO_RX7_8); // Flush characters. Spin here until bus is empty // while(UARTCharGetNonBlocking(UART_BUFFERIZED_BASE)>=0); // Register UART interrupt UARTIntRegister(UART_BUFFERIZED_BASE,uartb_intHandler); // Enable UART interruptions IntEnable(INT_UART1); UARTIntDisable(UART_BUFFERIZED_BASE,UART_INT_TX); UARTIntEnable(UART_BUFFERIZED_BASE,UART_INT_RT|UART_INT_RX); // IntMasterEnable(); }
void bluetooth_init(uint32_t baudrate) { uint32_t ui32_SystemClock; ui32_SystemClock = u32_UsrSystemClockGet(); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTConfigSetExpClk(UART0_BASE, ui32_SystemClock, baudrate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // UARTFIFOEnable(UART0_BASE); // UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX7_8, UART_FIFO_RX1_8); UARTIntRegister(UART0_BASE, &Bluetooth_RxTxHandler); IntEnable(INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT | UART_INT_TX); UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_EOT); HC05_ClearEvtQueue(); }
void Init_UART() { // Enable the peripherals used by this example. SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable processor interrupts. IntMasterEnable(); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Configure the UART for 115,200, 8-N-1 operation. UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // Enable the UART interrupt. IntEnable(INT_UART0); UARTIntRegister(UART0_BASE, UARTIntHandler0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); }
void enableUART(uint8_t UART, unsigned long baudRate) { // We must unlock PD7 to use UART2 if (UART == 2) { // GPIO Port D Lock Register is at 0x40007520 HWREG(0x40007520) = GPIO_LOCK_KEY; // GPIO Port D Control Register is at 0x40007524 HWREG(0x40007524) = 0x80; } // Enable the UART peripheral in SysCtl ROM_SysCtlPeripheralEnable(SysCtlGPIOs[UARTPins[UART][0] / 8]); ROM_SysCtlPeripheralSleepEnable(SysCtlGPIOs[UARTPins[UART][0] / 8]); ROM_SysCtlPeripheralEnable(SysCtlUARTs[UART]); ROM_SysCtlPeripheralSleepEnable(SysCtlUARTs[UART]); // Configure the associated GPIO pins for UART ROM_GPIOPinConfigure(UARTPins[UART][2]); ROM_GPIOPinConfigure(UARTPins[UART][3]); ROM_GPIOPinTypeUART(GPIO[UARTPins[UART][0] / 8], bit8[UARTPins[UART][0] % 8] | bit8[UARTPins[UART][1] % 8]); // Configure the UART ROM_UARTConfigSetExpClk(UARTBASE[UART], ROM_SysCtlClockGet(), baudRate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_UARTFIFOEnable(UARTBASE[UART]); // Configure the UART receive (rx) interrupt ROM_UARTIntEnable(UARTBASE[UART], UART_INT_RX); UARTFIFOLevelSet(UARTBASE[UART], UART_FIFO_TX4_8, UART_FIFO_RX4_8); UARTIntRegister(UARTBASE[UART], rxInterrupts[UART]); ROM_IntPrioritySet(UART_INTs[UART], 0x00); // Enable the UART ROM_UARTEnable(UARTBASE[UART]); }
void uartBt_init(unsigned long baudrate) { ROM_SysCtlPeripheralEnable(UARTBT_PORTENABLE); ROM_SysCtlPeripheralEnable(UARTBT_PERIPHENABLE); if(UARTBT_PORT == GPIO_PORTD_BASE) { // Enable port PD7 for UART2-TX by opening the lock and selecting the bits we want to modify in the GPIO commit register. HWREG(UARTBT_PORT + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(UARTBT_PORT + GPIO_O_CR) = 0x80; } ROM_GPIOPinConfigure(UARTBT_PINMAP_TX); ROM_GPIOPinConfigure(UARTBT_PINMAP_RX); ROM_GPIOPinTypeUART(UARTBT_PORT, UARTBT_PIN_RX | UARTBT_PIN_TX); // Configure the UART for the specified baud rate, 8-N-1 operation. ROM_UARTConfigSetExpClk(UARTBT_BASE, ROM_SysCtlClockGet(), baudrate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_UARTFIFODisable(UARTBT_BASE); // FIFO disabled so that short commands come through immediately // ROM_UARTFIFOEnable(UARTBT_BASE); // ROM_UARTFIFOLevelSet(UARTBT_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); UARTIntRegister(UARTBT_BASE, ISR_uartBt); ROM_IntEnable(UARTBT_INTERRUPT); ROM_UARTIntEnable(UARTBT_BASE, UART_INT_RX); }
/********************************************************************************************** * Main *********************************************************************************************/ void main(void) { //After tomorrow's test flight. FOR THE LOVE OF GOD MOVE THESE INITALIZATIONS TO FUNCTIONS /********************************************************************************************** * Local Variables *********************************************************************************************/ unsigned long ultrasonic = 0; // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. FPULazyStackingEnable(); //Set the clock speed to 80MHz aka max speed SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /*unsigned long test[2]; test[0] = 180; test[1] = 10; short bob[1]; bob[0] = ((char)test[0]<<8)|(char)test[1]; float jimmy = (short)(((char)test[0]<<8)|(char)test[1]); jimmy /= 26;*/ /********************************************************************************************** * Peripheral Initialization Awake *********************************************************************************************/ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Turn on GPIO communication on F pins for switches SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //Turn on GPIO for ADC SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Turn on GPIO for the PWM comms SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //Turn on GPIO for LED test SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Turn on GPIO for UART SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); //Turn on Timer for PWM SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); //Turn on Timer for PWM SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); //Turn on Timer for PWM SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3); //Turn on Timer for PWM SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1); //Turn on I2C communication I2C slot 0 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); //Turn on the UART com SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG); //Turn on the watchdog timer. This is a risky idea but I think it's for the best. /********************************************************************************************** * Peripheral Initialization Sleep *********************************************************************************************/ /*SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF); //This sets what peripherals are still enabled in sleep mode while UART would be nice, it would require the clock operate at full speed which is :P SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER0); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER1); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER2); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER3); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_SSI0); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_I2C1); SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_ADC); SysCtlPeripheralClockGating(true); //I'm not sure about this one maybe remove it */ /********************************************************************************************** * PWM Initialization *********************************************************************************************/ SysCtlDelay((SysCtlClockGet() / (1000 * 3))*100); //This shouldn't be needed will test to remove //PWM pin Setup //PWM 0 on GPIO PB6, PWM 1 on pin 4... etc GPIOPinConfigure(GPIO_PB6_T0CCP0); //Pitch - yaw + GPIOPinConfigure(GPIO_PB4_T1CCP0); //Pitch + yaw + GPIOPinConfigure(GPIO_PB0_T2CCP0); //Roll - yaw - GPIOPinConfigure(GPIO_PB2_T3CCP0); //Roll + yaw - GPIOPinTypeTimer(GPIO_PORTB_BASE, (GPIO_PIN_6|GPIO_PIN_4|GPIO_PIN_0|GPIO_PIN_2)); //Prescale the timers so they are slow enough to work with the ESC TimerPrescaleSet(TIMER0_BASE,TIMER_A,2); TimerPrescaleSet(TIMER1_BASE,TIMER_A,2); TimerPrescaleSet(TIMER2_BASE,TIMER_A,2); TimerPrescaleSet(TIMER3_BASE,TIMER_A,2); //Basic LED Out Test Not sure why this is here look into This just turns on an LED that I don't have plugged in. should remove later GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3); GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0xFF); //GPIOPinTypeGPIOOutputOD(GPIO_PORTB_BASE,GPIO_PIN_0); //Timers Setup for PWM and the load for the countdown TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1); TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod -1); TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); TimerLoadSet(TIMER2_BASE, TIMER_A, (ulPeriod -1)); TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM); TimerLoadSet(TIMER3_BASE, TIMER_A, ulPeriod -1); //TimerPrescaleSet(TIMER2_BASE, TIMER_A, extender1); //TimerLoadSet(TIMER2_BASE, TIMER_A, period1); //Set the match which is when the thing will pull high TimerMatchSet(TIMER0_BASE, TIMER_A, 254); //Duty cycle = (1-%desired)*1000 note this means this number is percent low not percent high TimerMatchSet(TIMER1_BASE, TIMER_A, 254); TimerMatchSet(TIMER2_BASE, TIMER_A, 254); TimerMatchSet(TIMER3_BASE, TIMER_A, 254); //TimerPrescaleMatchSet(TIMER2_BASE, TIMER_A, extender2); //TimerMatchSet(TIMER2_BASE, TIMER_A, period2); //Enable the timers TimerEnable(TIMER0_BASE, TIMER_A); TimerEnable(TIMER1_BASE, TIMER_A); TimerEnable(TIMER2_BASE, TIMER_A); TimerEnable(TIMER3_BASE, TIMER_A); /********************************************************************************************** * onboard Chip interrupt Initialization *********************************************************************************************/ //These two buttons are used to reset the bluetooth module in case of disconnection GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); //RGB LED's GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x00); HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; //Sw1 (PF4) is unaviable unless you make it only a GPIOF input via these commands HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x1; GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4); //Onboard buttons (PF0=Sw2,PF4=Sw1 GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //This will make the buttons falling edge (a press pulls them low) //void (*functionPtr)(void) = &onBoardInteruptHandle; GPIOPortIntRegister(GPIO_PORTF_BASE, onBoardInteruptHandle); //set function to handle interupt GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4,GPIO_FALLING_EDGE); //Set the interrupt as falling edge GPIOPinIntEnable(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4); //Enable the interrupt //IntMasterEnable(); IntEnable(INT_GPIOF); /********************************************************************************************** * UART Initialization *********************************************************************************************/ //Unlock PD7 HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80; GPIOPinConfigure(GPIO_PD7_U2TX); //Set PD7 as TX GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_7); GPIOPinConfigure(GPIO_PD6_U2RX); //Set PD6 as RX GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6); UARTConfigSetExpClk(UART2_BASE,SysCtlClockGet(),115200,UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE); //I believe the Xbee defaults to no parity I do know it's 9600 baud though, changed to 115200 for bluetooth reasons UARTFIFOLevelSet(UART2_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8); //Set's how big the fifo needs to be in order to call the interrupt handler, 2byte UARTIntRegister(UART2_BASE,Uart2IntHandler); //Regiester the interrupt handler UARTIntClear(UART2_BASE, UART_INT_TX | UART_INT_RX); //Clear the interrupt UARTIntEnable(UART2_BASE, UART_INT_TX | UART_INT_RX); //Enable the interrupt to trigger on both TX and RX event's. Could possibly remove TX UARTEnable(UART2_BASE); //Enable UART IntEnable(INT_UART2); //Second way to enable handler not sure if needed using anyway /********************************************************************************************** * I2C Initialization *********************************************************************************************/ //Serious credit to the man who made the Arduino version of this. he gave me addresses and equations. Sadly Arduino obfuscates what really is happening //Link posted on blog page //gyro address = 0x68 not 0x69 GPIOPinConfigure(GPIO_PA7_I2C1SDA); GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7); //Set GPA7 as SDA GPIOPinConfigure(GPIO_PA6_I2C1SCL); GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6); //Set GPA6 as SCL I2CMasterInitExpClk(I2C1_MASTER_BASE,SysCtlClockGet(),false); //I think it operates at 100kbps I2CMasterEnable(I2C1_MASTER_BASE); //Initalize the accelerometer Address = 0x53 GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x02); UARTSend(0xAB); I2CTransmit(0x53,0x2D,0x00); I2CTransmit(0x53,0x2D,0x10); I2CTransmit(0x53,0x2D,0x08); //Initalize the gyroscope Address = 0x68 I2CTransmit(0x68,0x3E,0x00); I2CTransmit(0x68,0x15,0x07); I2CTransmit(0x68,0x16,0x1E); I2CTransmit(0x68,0x17,0x00); UARTSend(0xAC); /********************************************************************************************** * SysTick Initialization *********************************************************************************************/ SysTickIntRegister(SysTickIntHandler); SysTickIntEnable(); SysTickPeriodSet((SysCtlClockGet() / (1000 * 3))*timeBetweenCalculations); //This sets the period for the delay. the last num is the num of milliseconds SysTickEnable(); /********************************************************************************************** * Watchdog Initialization *********************************************************************************************/ WatchdogReloadSet(WATCHDOG_BASE, 0xFEEFEEFF); //Set the timer for a reset WatchdogIntRegister(WATCHDOG_BASE,WatchdogIntHandler); //Enable interrupt WatchdogIntClear(WATCHDOG_BASE); WatchdogIntEnable(WATCHDOG_BASE); WatchdogEnable(WATCHDOG_BASE); //Enable the actual timer IntEnable(INT_WATCHDOG); /********************************************************************************************** * Preflight motor inialization maybe not necessary not going to test *********************************************************************************************/ PWMSet(TIMER0_BASE,998); PWMSet(TIMER1_BASE,998); PWMSet(TIMER2_BASE,998); PWMSet(TIMER3_BASE,998); recievedCommands[0]=253; SysCtlDelay((SysCtlClockGet() / (1000 * 3))*100); //Very important to ensure motor see's a start high (998 makes 0 sense but it works so shhhh don't tell anyone) GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06); while(1){ WatchdogReloadSet(WATCHDOG_BASE, 0xFEEFEEFF); //Feed the dog a new time //UARTSend(recievedCommands[0]); //SysCtlDelay(50000); //Set 4 PWM Outputs //Get Acc data I2CRead(0x53,0x32,6,quadAcc); //Address blah blah 2 for each axis rawAccToG(quadAcc,RwAcc); /*GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x04); //Blue //Get Gyro data /************************************** Gyro ITG-3200 I2C registers: temp MSB = 1B, temp LSB = 1C x axis MSB = 1D, x axis LSB = 1E y axis MSB = 1F, y axis LSB = 20 z axis MSB = 21, z axis LSB = 22 *************************************/ I2CRead(0x68,0x1B,8,quadGyro); //Address blah blah 2 for each axis + 2 for temperature. why. because why not rawGyroToDegsec(quadGyro,Gyro_ds); //GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x02); //Red //Get the actual angles in XYZ. Store them in RwEst //getInclination(RwAcc, RwEst, RwGyro, Gyro_ds, Awz); //After this function is called RwEst will hold the roll pitch and yaw //RwEst will be returned in PITCH, ROLL, YAW 0, 1, 2 remember this order very important. Little obvious but yaw is worthless /*if(RwEst[1]>0.5){ GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06); //Red Blue, Correct data read in }else{ GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x0A); //Red Green, The correct data is not there }*/ /*GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06); //Red Blue, Correct data read in float test=RwAcc[0]*100; //These two commands work char temp = (char)test; //UARTSend((char)(RwAcc[0])*100); //This one does not UARTSend(temp); //UARTSend((char)(RwAcc[1])*100); UARTSend(0xAA); SysCtlDelay((SysCtlClockGet() / (1000 * 3))*1); */ } }
//***************************************************************************** // //! Config Uart: some characteristic: //! PortName //! BaudRate //! DataBits //! Parity //! StopBits //! (*ISR)(): name of UART interrupt function //! //! //! \param pointer of Uart characteristic structure. //! //! \return ERROR_NONE: 0 // //***************************************************************************** unsigned char ConfigUART(UARTType *UART) { unsigned long ulSet = 0; //Configure GPIO for UART Mode switch ((*UART).PortName) { case UART0_BASE: SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); break; case UART1_BASE: break; case UART2_BASE: SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); GPIOPinConfigure(GPIO_PD6_U2RX); GPIOPinConfigure(GPIO_PD7_U2TX); break; case UART3_BASE: SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7); GPIOPinConfigure(GPIO_PC6_U3RX); GPIOPinConfigure(GPIO_PC7_U3TX); break; case UART4_BASE: SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4); GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); GPIOPinConfigure(GPIO_PC4_U4RX); GPIOPinConfigure(GPIO_PC5_U4TX); break; case UART5_BASE: SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5); GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5); GPIOPinConfigure(GPIO_PE4_U5RX); GPIOPinConfigure(GPIO_PE5_U5TX); break; case UART6_BASE: SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6); GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); GPIOPinConfigure(GPIO_PD4_U6RX); GPIOPinConfigure(GPIO_PD5_U6TX); break; case UART7_BASE: SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinConfigure(GPIO_PE0_U7RX); GPIOPinConfigure(GPIO_PE1_U7TX); break; default: return(INVALID_UART_NAME); } switch ((*UART).DataBits) { case 5: ulSet |= UART_CONFIG_WLEN_5; break; case 6: ulSet |= UART_CONFIG_WLEN_6; break; case 7: ulSet |= UART_CONFIG_WLEN_7; break; case 8: ulSet |= UART_CONFIG_WLEN_8; break; default: return(INVALID_DATA_BITS); } switch ((*UART).Parity) { case None: ulSet |= UART_CONFIG_PAR_NONE; break; case Odd: ulSet |= UART_CONFIG_PAR_ODD; break; case Even: ulSet |= UART_CONFIG_PAR_EVEN; break; case One: ulSet |= UART_CONFIG_PAR_ONE; break; case Zero: ulSet |= UART_CONFIG_PAR_ZERO; break; default: return(INVALID_PARITY_BIT); } switch ((*UART).StopBits) { case 1: ulSet |= UART_CONFIG_STOP_ONE; break; case 2: ulSet |= UART_CONFIG_STOP_TWO; break; default: return(INVALID_STOP_BIT); } //Configure UART UARTConfigSetExpClk((*UART).PortName, SysCtlClockGet(), (*UART).BaudRate, ulSet); UARTIntRegister((*UART).PortName, (*UART).ISR); UARTIntEnable((*UART).PortName, UART_INT_RX | UART_INT_RT); UARTEnable((*UART).PortName); IntMasterEnable(); return(ERROR_NONE); }
/**************************************************************************//** * @brief Main function of example. ******************************************************************************/ void main(void) { uint8_t ui8KeyBm = 0; uint_fast16_t ui16Cnt = 0; uint8_t ui8Byte = APP_TX_BYTE; // // Initialize clocks and board I/O // bspInit(BSP_SYS_CLK_SPD); // // Set LED1 to indicate life // bspLedSet(BSP_LED_1); // // Initialize key driver // bspKeyInit(BSP_KEY_MODE_ISR); bspKeyIntEnable(BSP_KEY_SELECT|BSP_KEY_UP); // // Initialize UART to USB MCU // bspUartBufInit(pui8TxBuf, sizeof(pui8TxBuf), pui8RxBuf, sizeof(pui8RxBuf)); // // Application must register the UART interrupt handler // UARTIntRegister(BSP_UART_BASE, &appUartIsr); // // Open UART connection // if(bspUartOpen(eBaudRate115200) != BSP_UART_SUCCESS) { // // Failed to initialize UART handler // bspAssert(); } // // Initialize SPI interface to LCD, configure LCD, and display information. // bspSpiInit(BSP_SPI_CLK_SPD); lcdInit(); lcdBufferPrintStringAligned(0, "UART example", eLcdAlignCenter, eLcdPage0); lcdBufferInvertPage(0, 0,127, eLcdPage0); lcdBufferPrintString(0, "Baud rate :", 6, eLcdPage2); lcdBufferPrintIntAligned(0, bspUartBaudRateGet(), eLcdAlignRight, eLcdPage2); lcdBufferPrintString(0, "Format :", 6, eLcdPage3); lcdBufferPrintStringAligned(0, "8-N-1", eLcdAlignRight, eLcdPage3); lcdBufferPrintString(0, "Flow control:", 6, eLcdPage4); lcdBufferPrintStringAligned(0, "No", eLcdAlignRight, eLcdPage4); lcdBufferPrintStringAligned(0, "Transmit: UP key", eLcdAlignRight, eLcdPage6); lcdBufferPrintStringAligned(0, "SELECT to toggle mode", eLcdAlignCenter, eLcdPage7); lcdBufferInvertPage(0, 0,127, eLcdPage7); lcdSendBuffer(0); // // Enable global interrupts // IntMasterEnable(); while(1) { ui8KeyBm = bspKeyPushed(BSP_KEY_ALL); if(BSP_KEY_SELECT & ui8KeyBm) { // // Change mode // bRepeaterMode ^= 1; bspLedToggle(BSP_LED_3); // // Update LCD for the new mode // lcdBufferClearPart(0, 0,127, eLcdPage6, eLcdPage6); if(bRepeaterMode) { lcdBufferPrintStringAligned(0, "Repeater mode", eLcdAlignCenter, eLcdPage6); } else { lcdBufferPrintStringAligned(0, "Transmit: UP key", eLcdAlignCenter, eLcdPage6); } lcdSendBufferPart(0, 0,127, eLcdPage6, eLcdPage6); } // // Read data from UART RX buffer to application buffer // ui16Cnt = bspUartDataGet(pui8AppBuf, bspUartRxCharsAvail()); if(bRepeaterMode) { // // Repeater mode // if(ui16Cnt) { // // Send data from application buffer to UART TX buffer // bspUartDataPut(pui8AppBuf, ui16Cnt); } } else { // // Transmit mode // if(BSP_KEY_UP & ui8KeyBm) { // // Transmit a single character // bspUartDataPut(&ui8Byte, 1); } } } }