/******************************** UART initialization function ***********************/
void Long_Uart0_Init(void)
{
	uint32_t ui32_SystemClock;
	RINGBUF_Init(&long_Uart0_TxRingBuf, long_Uart0_TxBuf, sizeof(long_Uart0_TxBuf));
	RINGBUF_Init(&long_Uart0_RxRingBuf, long_Uart0_RxBuf, sizeof(long_Uart0_RxBuf));
	ui32_SystemClock = u32_UsrSystemClockGet();
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	IntDisable(INT_UART0);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	UARTConfigSetExpClk(UART0_BASE, ui32_SystemClock, 19200,
						(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
						UART_CONFIG_PAR_NONE));
	UARTIntRegister(UART0_BASE, &UART0_RxTxHandler);
	UARTIntClear(UART0_BASE, UART_INT_RX | UART_INT_TX);
	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
	UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_EOT);
	IntEnable(INT_UART0);
}
Esempio n. 2
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 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();
}