/****************************************************************************** * UART-0 Configuration VCP (Virtual Com Port) * ---------------------------------------------------------------------------- * UART 0 -> Port A -> Pins PA0(Tx) & PA1(Rx) * 9600-8N1 * ******************************************************************************/ void PSO_UART0Config() { SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); /* Enable UART Module 0 */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); /* Enable GPIO Port A for UART-0 use */ GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); /* UART-0 interrupt configuration */ UARTDisable(UART0_BASE); UARTFIFOEnable(UART0_BASE); IntEnable(INT_UART0); UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX7_8); UARTIntEnable(UART0_BASE, UART_INT_RX); // | UART_INT_RT UARTEnable(UART0_BASE); UARTFIFOEnable(UART0_BASE); }
void UART_Disable(tUART* uart) { // Disable UART UARTDisable(uart -> base); // Set GPIO Pin Mux GPIOPinTypeGPIOInput(pins[uart -> tx_pin].port.base, pins[uart -> tx_pin].offset); GPIOPinTypeGPIOInput(pins[uart -> rx_pin].port.base, pins[uart -> rx_pin].offset); }
void UART2_57600(void) { // Disable UART Receive/Transmit UARTDisable(UART2_BASE, UART_TX | UART_RX); // Configure UART Baud 57600 UARTConfigSet(UART2_BASE, 57600, UART_CONFIG_SAMPLE_RATE_DEFAULT | UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_1); // Enable UART Receive and Transmit UARTEnable(UART2_BASE, UART_TX | UART_RX); }
/************************************************************************************************* * @fn HalUARTCloseIsr() * * @brief Close the UART * * @param port - UART port (not used.) * * @return none *************************************************************************************************/ void HalUARTCloseIsr(uint8 port) { (void)port; UARTDisable(HAL_UART_PORT); if (uartRecord.configured) { (void)osal_mem_free(uartRecord.rx.pBuffer); (void)osal_mem_free(uartRecord.tx.pBuffer); recRst(); } }
void UARTConfigSet(unsigned long ulBase, unsigned long ulBaud, unsigned long ulConfig) { unsigned long ulUARTClk, ulInt, ulFrac; // // Check the arguments. // ASSERT((ulBase == UART0_BASE) || (ulBase == UART1_BASE)); // // Stop the UART. // UARTDisable(ulBase); // // Determine the UART clock rate. // ulUARTClk = SysCtlClockGet(); // // Compute the fractional baud rate divider. // ulInt = ulUARTClk / (16 * ulBaud); ulFrac = ulUARTClk % (16 * ulBaud); ulFrac = ((((2 * ulFrac * 4) / ulBaud) + 1) / 2); // // Set the baud rate. // HWREG(ulBase + UART_O_IBRD) = ulInt; HWREG(ulBase + UART_O_FBRD) = ulFrac; // // Set parity, data length, and number of stop bits. // HWREG(ulBase + UART_O_LCR_H) = ulConfig; // // Clear the flags register. // HWREG(ulBase + UART_O_FR) = 0; // // Start the UART. // UARTEnable(ulBase); }
/*---------------------------------------------------------------------------*/ static void reset(void) { /* * Make sure the UART is disabled before trying to configure it. This also * flushes the FIFOs. */ UARTDisable(UART0_BASE); /* Clear error status */ UARTRxErrorClear(UART0_BASE); /* UART Enable */ UARTEnable(UART0_BASE); }
/************************************************************************************************* * @fn sbUartInit() * * @brief Initialize the UART. * * @param none * * @return none */ void sbUartInit(void) { // // Set IO clock to the same as system clock // SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ); // // Enable UART peripheral module // SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART0); // // Disable UART function // UARTDisable(UART0_BASE); // // Disable all UART module interrupts // UARTIntDisable(UART0_BASE, 0x1FFF); // // Set IO clock as UART clock source // UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // // Map UART signals to the correct GPIO pins and configure them as // hardware controlled. // IOCPinConfigPeriphOutput(GPIO_A_BASE, GPIO_PIN_1, IOC_MUX_OUT_SEL_UART0_TXD); GPIOPinTypeUARTOutput(GPIO_A_BASE, GPIO_PIN_1); IOCPinConfigPeriphInput(GPIO_A_BASE, GPIO_PIN_0, IOC_UARTRXD_UART0); GPIOPinTypeUARTInput(GPIO_A_BASE, GPIO_PIN_0); // // Configure the UART for 115,200, 8-N-1 operation. // This function uses SysCtrlClockGet() to get the system clock // frequency. This could be also be a variable or hard coded value // instead of a function call. // UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTEnable(UART0_BASE); }
/** * @brief Función para inicializar uno de los puertos UART. * * @return - * * Inicializa el puerto 0 de la UART. */ int UART_open(int nPort) { initUartPins(nPort); UARTDisable(gs_ul_uarts_bases[nPort]); UARTConfigSetExpClk(gs_ul_uarts_bases[nPort], SysCtlClockGet(), BAUD_RATE, DATA_FRAME); UARTEnable(gs_ul_uarts_bases[nPort]); gs_cu_uarts[nPort].inHead = 0; gs_cu_uarts[nPort].inTail = 0; gs_cu_uarts[nPort].inHead = 0; gs_cu_uarts[nPort].inTail = 0; gs_cu_uarts[nPort].intWhileWriting = 0; gs_cu_uarts[nPort].writingToBuf=0; UARTFIFOLevelSet(gs_ul_uarts_bases[nPort], UART_FIFO_TX1_8, UART_FIFO_RX1_8); IntEnable(gs_ul_uarts_ints[nPort]); UARTIntEnable(gs_ul_uarts_bases[nPort], UART_INT_TX | UART_INT_RX | UART_INT_RT); return 0; }
void Init_UART0(int baud, int buffer_size) { xtEventCallback UART0_INT_HANDLE = USART0IntHandler; // Enable GPIO and UART Clock SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Remap UART pin to GPIO Port UART0_RX --> PA2 UART0_TX --> PA1 xSPinTypeUART(UART0RX, PA1); xSPinTypeUART(UART0TX, PA2); // Set UART clock SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART0_S_MCGPLLCLK_2); // Disable UART Receive/Transmit UARTDisable(UART0_BASE, UART_TX | UART_RX); // Configure UART Baud 115200 UARTConfigSet(UART0_BASE, baud, UART_CONFIG_SAMPLE_RATE_DEFAULT | UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_1); if (OSSemCreate(0, &SerialTX0) != ALLOC_EVENT_OK) { // Oh Oh // Não deveria entrar aqui !!! while(1){}; }; // Só cria fila se for passado um tamanho maior que 0 if (buffer_size){ if (OSQueueCreate(buffer_size, &Serial0) != ALLOC_EVENT_OK) { // Oh Oh // Não deveria entrar aqui !!! while(1){}; }; } UARTIntEnable(UART0_BASE, UART_INT_R); UARTIntCallbackInit(UART0_BASE, UART0_INT_HANDLE); // Enable UART Receive and Transmit UARTEnable(UART0_BASE, UART_TX | UART_RX); xIntEnable(28); }
void Uart::sleep(void) { // Wait until UART is not busy while(UARTBusy(uart_.base)) ; // Disable UART hardware UARTDisable(uart_.base); // Configure the pins as outputs GPIOPinTypeGPIOOutput(rx_.getPort(), rx_.getPin()); GPIOPinTypeGPIOOutput(tx_.getPort(), tx_.getPin()); // Pull the pins to ground GPIOPinWrite(rx_.getPort(), rx_.getPin(), 0); GPIOPinWrite(tx_.getPort(), tx_.getPin(), 0); }
//***************************************************************************** // //! Sets the configuration of a UART. //! //! \param ulBase is the base address of the UART port. //! \param ulUARTClk is the rate of the clock supplied to the UART module. //! \param ulBaud is the desired baud rate. //! \param ulConfig is the data format for the port (number of data bits, //! number of stop bits, and parity). //! //! This function will configure the UART for operation in the specified data //! format. The baud rate is provided in the \e ulBaud parameter and the data //! format in the \e ulConfig parameter. //! //! The \e ulConfig parameter is the logical OR of three values: the number of //! data bits, the number of stop bits, and the parity. \b UART_CONFIG_WLEN_8, //! \b UART_CONFIG_WLEN_7, \b UART_CONFIG_WLEN_6, and \b UART_CONFIG_WLEN_5 //! select from eight to five data bits per byte (respectively). //! \b UART_CONFIG_STOP_ONE and \b UART_CONFIG_STOP_TWO select one or two stop //! bits (respectively). \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN, //! \b UART_CONFIG_PAR_ODD, \b UART_CONFIG_PAR_ONE, and \b UART_CONFIG_PAR_ZERO //! select the parity mode (no parity bit, even parity bit, odd parity bit, //! parity bit always one, and parity bit always zero, respectively). //! //! The peripheral clock will be the same as the processor clock. This will be //! the value returned by SysCtlClockGet(), or it can be explicitly hard coded //! if it is constant and known (to save the code/execution overhead of a call //! to SysCtlClockGet()). //! //! This function replaces the original UARTConfigSet() API and performs the //! same actions. A macro is provided in <tt>uart.h</tt> to map the original //! API to this API. //! //! \return None. // //***************************************************************************** void UARTConfigSetExpClk(unsigned long ulBase, unsigned long ulUARTClk, unsigned long ulBaud, unsigned long ulConfig) { unsigned long ulDiv; // // Check the arguments. // ASSERT(UARTBaseValid(ulBase)); ASSERT(ulBaud != 0); ASSERT(ulUARTClk >= (ulBaud * UART_CLK_DIVIDER)); // // Stop the UART. // UARTDisable(ulBase); // // Compute the fractional baud rate divider. // ulDiv = (((ulUARTClk * 8) / ulBaud) + 1) / 2; // // Set the baud rate. // HWREG(ulBase + UART_O_IBRD) = ulDiv / 64; HWREG(ulBase + UART_O_FBRD) = ulDiv % 64; // // Set parity, data length, and number of stop bits. // HWREG(ulBase + UART_O_LCRH) = ulConfig; // // Clear the flags register. // HWREG(ulBase + UART_O_FR) = 0; // // Start the UART. // UARTEnable(ulBase); }
void Init_UART2(void) { xtEventCallback UART2_INT_HANDLE = USART2IntHandler; // Enable GPIO and UART Clock SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // Remap UART pin to GPIO Port UART0_RX --> PA2 UART0_TX --> PA1 xSPinTypeUART(UART2RX, PE23); xSPinTypeUART(UART2TX, PE22); // Set UART clock SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART0_S_MCGPLLCLK_2); // Disable UART Receive/Transmit UARTDisable(UART2_BASE, UART_TX | UART_RX); // Configure UART Baud 115200 UARTConfigSet(UART2_BASE, 9600, UART_CONFIG_SAMPLE_RATE_DEFAULT | UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_1); if (OSSemCreate(0, &SerialTX2) != ALLOC_EVENT_OK) { // Oh Oh // Não deveria entrar aqui !!! while(1){}; }; if (OSQueueCreate(128, &Serial2) != ALLOC_EVENT_OK) { // Oh Oh // Não deveria entrar aqui !!! while(1){}; }; UARTIntEnable(UART2_BASE, UART_INT_R); UARTIntCallbackInit(UART2_BASE, UART2_INT_HANDLE); // Enable UART Receive and Transmit UARTEnable(UART2_BASE, UART_TX | UART_RX); xIntEnable(30); }
void uart_init() { // reset local variables memset(&uart_vars,0,sizeof(uart_vars_t)); // Disable UART function UARTDisable(UART0_BASE); // Disable all UART module interrupts UARTIntDisable(UART0_BASE, 0x1FFF); // Set IO clock as UART clock source UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // Map UART signals to the correct GPIO pins and configure them as // hardware controlled. GPIO-A pin 0 and 1 IOCPinConfigPeriphOutput(GPIO_A_BASE, PIN_UART_TXD, IOC_MUX_OUT_SEL_UART0_TXD); GPIOPinTypeUARTOutput(GPIO_A_BASE, PIN_UART_TXD); IOCPinConfigPeriphInput(GPIO_A_BASE, PIN_UART_RXD, IOC_UARTRXD_UART0); GPIOPinTypeUARTInput(GPIO_A_BASE, PIN_UART_RXD); // Configure the UART for 115,200, 8-N-1 operation. // This function uses SysCtrlClockGet() to get the system clock // frequency. This could be also be a variable or hard coded value // instead of a function call. UARTConfigSetExpClk(UART0_BASE, SysCtrlIOClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // Enable UART hardware UARTEnable(UART0_BASE); // Disable FIFO as we only one 1byte buffer UARTFIFODisable(UART0_BASE); // Raise interrupt at end of tx (not by fifo) UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_EOT); // Register isr in the nvic and enable isr at the nvic UARTIntRegister(UART0_BASE, uart_isr_private); // Enable the UART0 interrupt IntEnable(INT_UART0); }
/** * Function documented in platform/uart.h */ otError otPlatUartDisable(void) { UARTDisable(UART0_BASE); UARTIntUnregister(UART0_BASE); UARTIntDisable(UART0_BASE, UART_INT_RX | UART_INT_RT); IOCPortConfigureSet(IOID_2, IOC_PORT_GPIO, IOC_STD_INPUT); IOCPortConfigureSet(IOID_3, IOC_PORT_GPIO, IOC_STD_INPUT); PRCMPeripheralRunDisable(PRCM_PERIPH_UART0); PRCMPeripheralSleepDisable(PRCM_PERIPH_UART0); PRCMPeripheralDeepSleepDisable(PRCM_PERIPH_UART0); PRCMLoadSet(); /** * \warn this assumes that there are no other devices being used in the * serial power domain */ PRCMPowerDomainOff(PRCM_DOMAIN_SERIAL); return OT_ERROR_NONE; }
void Uart::enable(uint32_t baudrate) { // Get GpioConfig structures GpioConfig& rx = rx_.getGpioConfig(); GpioConfig& tx = tx_.getGpioConfig(); // Store baudrate in configuration if (baudrate != 0) { config_.baudrate = baudrate; } // Enable peripheral except in deep sleep modes (e.g. LPM1, LPM2, LPM3) SysCtrlPeripheralEnable(config_.peripheral); SysCtrlPeripheralSleepEnable(config_.peripheral); SysCtrlPeripheralDeepSleepDisable(config_.peripheral); // Disable peripheral previous to configuring it UARTDisable(config_.peripheral); // Set IO clock as UART clock source UARTClockSourceSet(config_.base, config_.clock); // Configure the UART RX and TX pins IOCPinConfigPeriphInput(rx.port, rx.pin, rx.ioc); IOCPinConfigPeriphOutput(tx.port, tx.pin, tx.ioc); // Configure the UART GPIOs GPIOPinTypeUARTInput(rx.port, rx.pin); GPIOPinTypeUARTOutput(tx.port, tx.pin); // Configure the UART UARTConfigSetExpClk(config_.base, SysCtrlIOClockGet(), config_.baudrate, config_.mode); // Disable FIFO as we only use a one-byte buffer UARTFIFODisable(config_.base); // Raise an interrupt at the end of transmission UARTTxIntModeSet(config_.base, UART_TXINT_MODE_EOT); // Enable UART hardware UARTEnable(config_.base); }
/*---------------------------------------------------------------------------*/ void uart_init(void) { /* Enable clock for GPIO port A */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); /* Enable clock for UART0 */ SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); /* Configure the IO mux to map UART0 signals to PA0/PA1 */ GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); /* Configure the pins as UART */ GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); /* * UART Interrupt Masks: * Acknowledge RX and RX Timeout * Acknowledge Framing, Overrun and Break Errors */ UARTIntEnable(UART0_BASE, (UART_INT_RX | UART_INT_RT | UART_INT_OE | UART_INT_BE | UART_INT_FE)); /* Set FIFO levels */ UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX1_8); /* Make sure the UART is disabled before trying to configure it */ UARTDisable(UART0_BASE); /* Baud Rate Generation */ UARTConfigSetExpClk(UART0_BASE, sys_clock, UART_CONF_BAUD_RATE, (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE | UART_CONFIG_WLEN_8)); /* Enable UART0 Interrupts */ IntEnable(INT_UART0); /* UART Enable */ UARTEnable(UART0_BASE); }
void Uart::sleep(void) { // Get GpioConfig structures GpioConfig& rx = rx_.getGpioConfig(); GpioConfig& tx = tx_.getGpioConfig(); // Wait until UART is not busy while(UARTBusy(config_.base)) ; // Disable UART hardware UARTDisable(config_.base); // Configure the pins as outputs GPIOPinTypeGPIOOutput(rx.port, rx.pin); GPIOPinTypeGPIOOutput(tx.port, tx.pin); // Pull the pins to ground GPIOPinWrite(rx.port, rx.pin, 0); GPIOPinWrite(tx.port, tx.pin, 0); }
void Uart::enable(uint32_t baudrate, uint32_t config, uint32_t mode) { // Store the UART baudrate, configuration and mode baudrate_ = baudrate; config_ = config; mode_ = mode; // Enable peripheral except in deep sleep modes (e.g. LPM1, LPM2, LPM3) SysCtrlPeripheralEnable(uart_.peripheral); SysCtrlPeripheralSleepEnable(uart_.peripheral); SysCtrlPeripheralDeepSleepDisable(uart_.peripheral); // Disable peripheral previous to configuring it UARTDisable(uart_.peripheral); // Set IO clock as UART clock source UARTClockSourceSet(uart_.base, uart_.clock); // Configure the UART RX and TX pins IOCPinConfigPeriphInput(rx_.getPort(), rx_.getPin(), rx_.getIoc()); IOCPinConfigPeriphOutput(tx_.getPort(), tx_.getPin(), tx_.getIoc()); // Configure the UART GPIOs GPIOPinTypeUARTInput(rx_.getPort(), rx_.getPin()); GPIOPinTypeUARTOutput(tx_.getPort(), tx_.getPin()); // Configure the UART UARTConfigSetExpClk(uart_.base, SysCtrlIOClockGet(), baudrate_, config_); // Disable FIFO as we only use a one-byte buffer UARTFIFODisable(uart_.base); // Raise an interrupt at the end of transmission UARTTxIntModeSet(uart_.base, mode_); // Enable UART hardware UARTEnable(uart_.base); }
void uartb_deinit(){ UARTDisable(UART_BUFFERIZED_BASE); }
/** * @brief Función para cerrar uno de los puertos UART. * * @return - * * Cierra el puerto 0 de la UART. */ void UART_close(int nPort) { UARTDisable(gs_ul_uarts_bases[nPort]); IntDisable(INT_UART0); }
//***************************************************************************** // //! Sets the configuration of a UART //! //! \param ui32Base is the base address of the UART port. //! \param ui32UARTClk is the rate of the clock supplied to the UART module. //! \param ui32Baud is the desired baud rate. //! \param ui32Config is the data format for the port (number of data bits, //! number of stop bits, and parity). //! //! This function configures the UART for operation in the specified data //! format. The baud rate is provided in the \e ui32Baud parameter and the data //! format in the \e ui32Config parameter. //! //! The \e ui32Config parameter is the logical OR of three values: the number of //! data bits, the number of stop bits, and the parity. \b UART_CONFIG_WLEN_8, //! \b UART_CONFIG_WLEN_7, \b UART_CONFIG_WLEN_6, and \b UART_CONFIG_WLEN_5 //! select from eight to five data bits per byte (respectively). //! \b UART_CONFIG_STOP_ONE and \b UART_CONFIG_STOP_TWO select one or two stop //! bits (respectively). \b UART_CONFIG_PAR_NONE, \b UART_CONFIG_PAR_EVEN, //! \b UART_CONFIG_PAR_ODD, \b UART_CONFIG_PAR_ONE, and \b UART_CONFIG_PAR_ZERO //! select the parity mode (no parity bit, even parity bit, odd parity bit, //! parity bit always one, and parity bit always zero, respectively). //! //! The peripheral clock is set in the System Control module. The frequency of //! the system clock is the value returned by SysCtrlClockGet() or //! SysCtrlIOClockGet() depending on the chosen clock source as set by //! UARTClockSourceSet(), or it can be explicitly hard coded if it is constant //! and known (to save the code/execution overhead of a call to //! SysCtrlClockGet() or SysCtrlIOClockGet()). //! //! The CC2538 part has the ability to specify the UART baud clock //! source (via UARTClockSourceSet()), the peripheral clock can be changed to //! PIOSC. In this case, the peripheral clock should be specified as //! 16,000,000 (the nominal rate of PIOSC). //! //! \sa See UARTClockSourceSet() //! //! \return None // //***************************************************************************** void UARTConfigSetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk, uint32_t ui32Baud, uint32_t ui32Config) { uint32_t ui32Div; // // Check the arguments. // ASSERT(UARTBaseValid(ui32Base)); ASSERT(ui32Baud != 0); // // Stop the UART. // UARTDisable(ui32Base); // // Is the required baud rate greater than the maximum rate supported // without the use of high speed mode? // if((ui32Baud * 16) > ui32UARTClk) { // // Enable high speed mode. // HWREG(ui32Base + UART_O_CTL) |= UART_CTL_HSE; // // Half the supplied baud rate to compensate for enabling high speed // mode. This allows the following code to be common to both cases. // ui32Baud /= 2; } else { // // Disable high speed mode. // HWREG(ui32Base + UART_O_CTL) &= ~(UART_CTL_HSE); } // // Compute the fractional baud rate divider. // ui32Div = (((ui32UARTClk * 8) / ui32Baud) + 1) / 2; // // Set the baud rate. // HWREG(ui32Base + UART_O_IBRD) = ui32Div / 64; HWREG(ui32Base + UART_O_FBRD) = ui32Div % 64; // // Set parity, data length, and number of stop bits. // HWREG(ui32Base + UART_O_LCRH) = ui32Config; // // Clear the flags register. // HWREG(ui32Base + UART_O_FR) = 0; }
//***************************************************************************** // // Configure the UART and perform reads and writes using polled I/O. // //***************************************************************************** int main(void) { char cThisChar; // // Set the clocking to run directly from the external crystal/oscillator. // (no ext 32k osc, no internal osc) // SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ); // // Set IO clock to the same as system clock // SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ); // // Enable UART peripheral module // SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_UART0); // // Disable UART function // UARTDisable(UART0_BASE); // // Disable all UART module interrupts // UARTIntDisable(UART0_BASE, 0x1FFF); // // Set IO clock as UART clock source // UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // // Map UART signals to the correct GPIO pins and configure them as // hardware controlled. // IOCPinConfigPeriphOutput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_TXD, IOC_MUX_OUT_SEL_UART0_TXD); GPIOPinTypeUARTOutput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_TXD); IOCPinConfigPeriphInput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_RXD, IOC_UARTRXD_UART0); GPIOPinTypeUARTInput(EXAMPLE_GPIO_BASE, EXAMPLE_PIN_UART_RXD); // // Configure the UART for 115,200, 8-N-1 operation. // This function uses SysCtrlClockGet() to get the system clock // frequency. This could be also be a variable or hard coded value // instead of a function call. // UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTEnable(UART0_BASE); // // Put a character to show start of example. This will display on the // terminal. // UARTCharPut(UART0_BASE, '!'); // // Enter a loop to read characters from the UART, and write them back // (echo). When a line end is received, the loop terminates. // do { // // Read a character using the blocking read function. This function // will not return until a character is available. // cThisChar = UARTCharGet(UART0_BASE); // // Write the same character using the blocking write function. This // function will not return until there was space in the FIFO and // the character is written. // UARTCharPut(UART0_BASE, cThisChar); // // Stay in the loop until either a CR or LF is received. // } while((cThisChar != '\n') && (cThisChar != '\r')); // // Put a character to show the end of the example. This will display on // the terminal. // UARTCharPut(UART0_BASE, '@'); // // Enter an infinite loop. // while(1) { } }
void UART_example(void) { unsigned int i = 0; // // Configure System clock // xSysCtlClockSet(48000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); SysCtlDelay(1000000); // Note: Defore call UART0 Function, you must call SysCtlPeripheralClockSourceSet Function. // SYSCTL_PERIPH_UART0_S_MCGFLLCLK, SYSCTL_PERIPH_UART0_S_MCGPLLCLK_2, // SYSCTL_PERIPH_UART0_S_OSCERCLK, SYSCTL_PERIPH_UART0_S_MCGIRCLK, // For UART1/2, just comment it SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART0_S_MCGPLLCLK_2); // // Enable GPIO/UART Clock // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Remap UART pin to GPIO Port UART1_RX --> PC3 UART1_TX --> PC4 xSPinTypeUART(UART0RX, PA1); xSPinTypeUART(UART0TX, PA2); // // Disable UART Receive/Transmit // UARTDisable(UART0_BASE, UART_TX | UART_RX); // // Configure UART Baud 115200 8-N-1 // UARTConfigSet(UART0_BASE, 115200, UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_1); // // Enable UART Receive/Transmit // UARTEnable(UART0_BASE, UART_TX | UART_RX); // // print out welcome information // i = 0; while(Begin[i] != '\0') { UARTCharPut(UART0_BASE, Begin[i++]); } // // Echo user's input information // while((Rec = UARTCharGet(UART0_BASE)) != '\n') { UARTCharPut(UART0_BASE, Rec); } // // print out run over information // i = 0; while(End[i] != '\0') { UARTCharPut(UART0_BASE, End[i++]); } while(1); }
void UART_example(void) { unsigned int i = 0; char Rec = 0; // // Configure System clock // xSysCtlClockSet(48000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); SysCtlDelay(1000000); // // Enable GPIO/UART Clock // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); // // Remap UART pin to GPIO Port UART1_RX --> PC3 UART1_TX --> PC4 xSPinTypeUART(UART1RX, PC3); xSPinTypeUART(UART1TX, PC4); // // Disable UART Receive/Transmit // UARTDisable(UART1_BASE, UART_TX | UART_RX); // // Configure UART Baud 9600 8-N-1 // UARTConfigSet(UART1_BASE, 9600, UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_1); // // Enable UART Receive/Transmit // UARTEnable(UART1_BASE, UART_TX | UART_RX); // // print out welcome information // i = 0; while(Begin[i] != '\0') { UARTCharPut(UART1_BASE, Begin[i++]); } // // Echo user's input information // while((Rec = UARTCharGet(UART1_BASE)) != '\n') { UARTCharPut(UART1_BASE, Rec); } // // print out run over information // i = 0; while(End[i] != '\0') { UARTCharPut(UART1_BASE, End[i++]); } while(1); }
//***************************************************************************** // //! Initialize the UART module and send characters to the terminal //! //! \param None //! //! This function initializes the UART including clock source, enables RX and TX. //! Prints the welcome message and echos characters. //! //! \return none // //***************************************************************************** void UART_example_freedomKL25(void) { unsigned int i = 0; unsigned char Rec; // // Configure System clock // xSysCtlClockSet(48000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); SysCtlDelay(1000000); // // Enable GPIO and UART Clock // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Remap UART pin to GPIO Port UART0_RX --> PA2 UART0_TX --> PA1 // xSPinTypeUART(UART0RX, PA1); xSPinTypeUART(UART0TX, PA2); // // Set UART clock // SysCtlPeripheralClockSourceSet(SYSCTL_PERIPH_UART0_S_MCGPLLCLK_2); // // Disable UART Receive/Transmit // UARTDisable(UART0_BASE, UART_TX | UART_RX); // // Configure UART Baud 115200 // UARTConfigSet(UART0_BASE, 115200, UART_CONFIG_SAMPLE_RATE_15 | UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_1); // // Enable UART Receive and Transmit // UARTEnable(UART0_BASE, UART_TX | UART_RX); // // Print out welcome information // i = 0; while(Begin[i] != '\0') { UARTCharPut(UART0_BASE, Begin[i++]); } // // Echo user's input information. End if 0xD (CR) // while((Rec = UARTCharGet(UART0_BASE)) != 0xD) { UARTCharPut(UART0_BASE, Rec); } // // print out last message // i = 0; while(End[i] != '\0') { UARTCharPut(UART0_BASE, End[i++]); } while(1); }