//*****************************************************************************
//
// uart_polled.c - Example demonstrating UART polled I/O.
//
// Copyright (c) 2010-2015 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// This is part of revision 2.1.1.71 of the Tiva Firmware Development Package.
//
//*****************************************************************************
//!
//! This example shows how to set up the UART and use polled I/O methods
//! for transmitting and receiving UART data. The example receives characters
//! from UART0 and retransmits the same character using UART0. It can be
//! tested by using a serial terminal program on a host computer. This
//! example will echo every character that is type until the return/enter key
//! is pressed.
//!
//! This example uses the following peripherals and I/O signals. You must
//! review these and change as needed for your own board:
//! - UART0 peripheral
//! - GPIO Port A peripheral (for UART0 pins)
//! - UART0RX - PA0
//! - UART0TX - PA1
//
//*****************************************************************************
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
uint32_t ui32SysClock;
#endif
//uint32_t ADC_Data[2];
//uint32_t test_Data[2];
//uint32_t DAC_Data[2];
//float voltage0[2];
//float voltage1[2];
const uint32_t ADarry_ch0_Len=12;
const uint32_t ADarry_ch1_Len=12;
//
// Get the interrrupt status.
//
ui32Status = UARTIntStatus(UART0_BASE, true);
//
// Clear the asserted interrupts.
//
UARTIntClear(UART0_BASE, ui32Status);
//
// Loop while there are characters in the receive FIFO.
//
while(UARTCharsAvail(UART0_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
UARTCharPutNonBlocking(UART0_BASE,
UARTCharGetNonBlocking(UART0_BASE));
}
}
//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
//UARTCharPut(UART0_BASE, *pui8Buffer++);
}
}
usart_send_data_state[0]=0xEB;//frame head
usart_send_data_state[1]=0x01;//frame data type
usart_send_data_state[2]=0x00;//..device region
usart_send_data_state[3]=0x00;//..device code
usart_send_data_state[4]=0x01;//..data send reason
usart_send_data_state[5]=0x00;//..device state
usart_send_data_state[6]=0x00;//..DA0 height
usart_send_data_state[7]=0x00;//..DA0 low
usart_send_data_state[8]=0x00;//..DA1 height
usart_send_data_state[9]=0x00;//..DA1 low
usart_send_data_state[10]=0x00;//..AD0 height
usart_send_data_state[11]=0x00;//..DA0 low
usart_send_data_state[12]=0x00;//parite height
usart_send_data_state[13]=0x00;//parite low
usart_send_data_state[14]=0xAA;//frame end
/*
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
uint32_t ui32SysClock;
#endif
*/
//
// Set the clocking to run directly from the external crystal/oscillator.
// TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
// crystal on your board.
//
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C12ru9_RA1) || \
defined(TARGET_IS_TM4C129ru_RA2)
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_OSC), 25000000);
#else
//SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
// SYSCTL_XTAL_16MHZ);
/////////////////uart init/////////////////////////////
#if 1
//ru
// Enruable the peripherals used by this example.
// The UruART itself needs to be enabled, as well as the GPIO port
// containirung the pins that will be used.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Configure the GPIO pin muxing for the UART function.
//ru This is only necessary if your part supports GPIO pin function muxing.
// Struudy the data sheet to see which functions are allocated per pin.
// TODO:ru change this to select the port/pin you are using
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
//
// Since GPIO A0 and A1 are used for the UART function, they must be
//ru configured for use as a peripheral function (instead of GPIO).
// TOruDO: change this to match the port/pin you are using
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Configure the UART for 115,200, 8-N-1 operation.
//ru This function uses SysCtlClockGet() or ui32SysClock to get the system clock
// frruequency. This could be also be a variable or hard coded value
// insteruad of a function call.
//
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
#else
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
#endif