These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uart_hw_flow_control.c Source File

uart_hw_flow_control.c

00001 /***
00002  * @file        uart_hw_flow_control.c
00003  * @purpose     This example describes how to using UART Hardware flow control mode
00004  * @version     2.0
00005  * @date        10. June. 2010
00006  * @author      NXP MCU SW Application Team
00007  *---------------------------------------------------------------------
00008  * Software that is described herein is for illustrative purposes only
00009  * which provides customers with programming information regarding the
00010  * products. This software is supplied "AS IS" without any warranties.
00011  * NXP Semiconductors assumes no responsibility or liability for the
00012  * use of the software, conveys no license or title under any patent,
00013  * copyright, or mask work right to the product. NXP Semiconductors
00014  * reserves the right to make changes in the software without
00015  * notification. NXP Semiconductors also make no representation or
00016  * warranty that such application will be suitable for the specified
00017  * use without further testing or modification.
00018  **********************************************************************/
00019 #include "lpc17xx_uart.h"
00020 #include "lpc17xx_libcfg.h"
00021 #include "lpc17xx_pinsel.h"
00022 
00023 /* Example group ----------------------------------------------------------- */
00024 /** @defgroup UART_HWFlowControl    HWFlowControl
00025  * @ingroup UART_Examples
00026  * @{
00027  */
00028 
00029 /************************** PRIVATE DEFINITIONS *************************/
00030 #define TEST_UART (LPC_UART_TypeDef *)LPC_UART1
00031 
00032 /************************** PRIVATE VARIABLES *************************/
00033 uint8_t menu1[] = "Hello NXP Semiconductors \n\r";
00034 uint8_t menu2[] = "UART hardware flow control mode demo \n\r\t MCU LPC17xx - ARM Cortex-M3 \n\r\t UART1 - 9600bps \n\r";
00035 uint8_t menu3[] = "UART demo terminated!";
00036 
00037 /************************** PRIVATE FUNCTIONS *************************/
00038 void print_menu(void);
00039 
00040 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
00041 /*********************************************************************//**
00042  * @brief       Print Welcome menu
00043  * @param[in]   none
00044  * @return      None
00045  **********************************************************************/
00046 void print_menu(void)
00047 {
00048     UART_Send(TEST_UART, menu1, sizeof(menu1), BLOCKING);
00049     UART_Send(TEST_UART, menu2, sizeof(menu2), BLOCKING);
00050 }
00051 
00052 /*-------------------------MAIN FUNCTION------------------------------*/
00053 /*********************************************************************//**
00054  * @brief       c_entry: Main UART program body
00055  * @param[in]   None
00056  * @return      int
00057  **********************************************************************/
00058 int c_entry(void)
00059 {
00060     // UART Configuration structure variable
00061     UART_CFG_Type UARTConfigStruct;
00062     // UART FIFO configuration Struct variable
00063     UART_FIFO_CFG_Type UARTFIFOConfigStruct;
00064     // Pin configuration for UART0
00065     PINSEL_CFG_Type PinCfg;
00066 
00067     uint32_t idx, len;
00068     __IO FlagStatus exitflag;
00069     uint8_t buffer[10];
00070 
00071     /*
00072      * Initialize UART1 pin connect
00073      */
00074     PinCfg.Funcnum = 2;
00075     PinCfg.OpenDrain = 0;
00076     PinCfg.Pinmode = 0;
00077     PinCfg.Pinnum = 0;
00078     PinCfg.Portnum = 2;
00079     PINSEL_ConfigPin(&PinCfg);//P2.0 TXD1
00080     PinCfg.Pinnum = 1;
00081     PINSEL_ConfigPin(&PinCfg);//P2.1 RXD1
00082     PinCfg.Pinnum = 2;
00083     PINSEL_ConfigPin(&PinCfg);//P2.2 CTS1
00084     PinCfg.Pinnum = 7;
00085     PINSEL_ConfigPin(&PinCfg);//P2.7 RTS1
00086 
00087     /* Initialize UART Configuration parameter structure to default state:
00088      * Baudrate = 9600bps
00089      * 8 data bit
00090      * 1 Stop bit
00091      * None parity
00092      */
00093     UART_ConfigStructInit(&UARTConfigStruct);
00094 
00095     // Initialize UART0 peripheral with given to corresponding parameter
00096     UART_Init(TEST_UART, &UARTConfigStruct);
00097 
00098     /* Initialize FIFOConfigStruct to default state:
00099      *              - FIFO_DMAMode = DISABLE
00100      *              - FIFO_Level = UART_FIFO_TRGLEV0
00101      *              - FIFO_ResetRxBuf = ENABLE
00102      *              - FIFO_ResetTxBuf = ENABLE
00103      *              - FIFO_State = ENABLE
00104      */
00105     UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);
00106 
00107     // Initialize FIFO for UART0 peripheral
00108     UART_FIFOConfig(TEST_UART, &UARTFIFOConfigStruct);
00109 
00110     // Configure UART1 hardware flow control RTS/CTS
00111     UART_FullModemForcePinState((LPC_UART1_TypeDef *)LPC_UART1,UART1_MODEM_PIN_RTS,ACTIVE);
00112 
00113     // Enable UART Transmit
00114     UART_TxCmd(TEST_UART, ENABLE);
00115 
00116     // print welcome screen
00117     print_menu();
00118 
00119     // Reset exit flag
00120     exitflag = RESET;
00121 
00122     /* Read some data from the buffer */
00123     while (exitflag == RESET)
00124     {
00125        len = 0;
00126         while (len == 0)
00127         {
00128             len = UART_Receive(TEST_UART, buffer, sizeof(buffer), NONE_BLOCKING);
00129         }
00130 
00131         /* Got some data */
00132         idx = 0;
00133         while (idx < len)
00134         {
00135             if (buffer[idx] == 27)
00136             {
00137                 /* ESC key, set exit flag */
00138                 UART_Send(TEST_UART, menu3, sizeof(menu3), BLOCKING);
00139                 exitflag = SET;
00140             }
00141             else if (buffer[idx] == 'r')
00142             {
00143                 print_menu();
00144             }
00145             else
00146             {
00147                 /* Echo it back */
00148                 UART_Send(TEST_UART, &buffer[idx], 1, BLOCKING);
00149             }
00150             idx++;
00151         }
00152     }
00153 
00154     // wait for current transmission complete - THR must be empty
00155     while (UART_CheckBusy(TEST_UART) == SET);
00156 
00157     // DeInitialize UART0 peripheral
00158     UART_DeInit(TEST_UART);
00159 
00160     /* Loop forever */
00161     while(1);
00162     return 1;
00163 }
00164 
00165 /* With ARM and GHS toolsets, the entry point is main() - this will
00166    allow the linker to generate wrapper code to setup stacks, allocate
00167    heap area, and initialize and copy code and data segments. For GNU
00168    toolsets, the entry point is through __start() in the crt0_gnu.asm
00169    file, and that startup code will setup stacks and data */
00170 int main(void)
00171 {
00172     return c_entry();
00173 }
00174 
00175 
00176 #ifdef  DEBUG
00177 /*******************************************************************************
00178 * @brief        Reports the name of the source file and the source line number
00179 *               where the CHECK_PARAM error has occurred.
00180 * @param[in]    file Pointer to the source file name
00181 * @param[in]    line assert_param error line source number
00182 * @return       None
00183 *******************************************************************************/
00184 void check_failed(uint8_t *file, uint32_t line)
00185 {
00186     /* User can add his own implementation to report the file name and line number,
00187      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00188 
00189     /* Infinite loop */
00190     while(1);
00191 }
00192 #endif
00193 /*
00194  * @}
00195  */