• Main Page
  • Data Structures
  • Files
  • File List
  • Globals

UART.c

Go to the documentation of this file.
00001 //******************************************************************************
00002 //THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
00003 //REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
00004 //INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
00005 //FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
00006 //COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
00007 //TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
00008 //POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
00009 //INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
00010 //YOUR USE OF THE PROGRAM.
00011 //
00012 //IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
00013 //CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
00014 //THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
00015 //OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
00016 //OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
00017 //EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
00018 //REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
00019 //OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
00020 //USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
00021 //AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
00022 //YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
00023 //(U.S.$500).
00024 //
00025 //Unless otherwise stated, the Program written and copyrighted
00026 //by Texas Instruments is distributed as "freeware".  You may,
00027 //only under TI's copyright in the Program, use and modify the
00028 //Program without any charge or restriction.  You may
00029 //distribute to third parties, provided that you transfer a
00030 //copy of this license to the third party and the third party
00031 //agrees to these terms by its first use of the Program. You
00032 //must reproduce the copyright notice and any other legend of
00033 //ownership on each copy or partial copy, of the Program.
00034 //
00035 //You acknowledge and agree that the Program contains
00036 //copyrighted material, trade secrets and other TI proprietary
00037 //information and is protected by copyright laws,
00038 //international copyright treaties, and trade secret laws, as
00039 //well as other intellectual property laws.  To protect TI's
00040 //rights in the Program, you agree not to decompile, reverse
00041 //engineer, disassemble or otherwise translate any object code
00042 //versions of the Program to a human-readable form.  You agree
00043 //that in no event will you alter, remove or destroy any
00044 //copyright notice included in the Program.  TI reserves all
00045 //rights not specifically granted under this license. Except
00046 //as specifically provided herein, nothing in this agreement
00047 //shall be construed as conferring by implication, estoppel,
00048 //or otherwise, upon you, any license or other right under any
00049 //TI patents, copyrights or trade secrets.
00050 //
00051 // 
00052 //You may not use the Program in non-TI devices.
00053 //
00054 //This software has been submitted to export control regulations
00055 //The ECCN is EAR99 
00056 //*****************************************************************************
00071 #include "msp430.h"
00072 #include "main.h"
00073 #include "UART.h"
00074 
00075 
00076   
00083 void InitUART(void){ 
00084 
00085   UCAxCTL1 |= UCSWRST;            // **Stops USCI state machine** 
00086   
00087   UART_PxREN &= ~(UART_TX_PAD|UART_RX_PAD); //Disable port pull resistors
00088   UART_PxDIR &= ~UART_RX_PAD;               // Configure Px.X as input
00089   UART_PxDIR |= UART_TX_PAD;                // Configure Px.X as output
00090   UART_PxSEL |= (UART_TX_PAD|UART_RX_PAD); // Px.x & Px.X = USCI_Ax TXD & RXD
00091   
00092   UCAxCTL0 = 0x00;                // No parity, 8-N-1 mode
00093   UCAxCTL1 |= UCSSEL_2;           // Select SMCLK as clock source for the UART
00094   UCAxBR = UART_BAUDRATE_REG;     // defines baudrate
00095   UCAxMCTL =  (UCBRF_0|UCBRS_6);  // Modulation UCBRSx = 6
00096   
00097   UCAxIFG &= ~UCAxRXIFG;          //Clear RX IFG
00098   
00099   UCAxCTL1 &= ~UCSWRST;           // **Initialize USCI state machine**
00100   UCAxIE |= UCAxRXIE;             // Enable USCI_A1 RX interrupt
00101   
00102 }  
00103 
00111 void StopUARTRx(void){
00112 
00113   UCAxIE &= ~UCAxRXIE;             // Disable USCI RX interrupt 
00114   
00115 }
00116 
00117 
00125 void StartUARTRx(void){
00126   
00127   UCAxIFG &= ~UCAxRXIFG;           // Clear RX IFG
00128   UCAxIE |= UCAxRXIE;              // Enable USCI RX interrupt
00129 }
00130 
00131 
00138 void WriteUART(unsigned char data)
00139 {  
00140   unsigned char TimeOutCounter = 0;
00141   // USCI_A0 TX buffer ready?
00142   while (!(UCAxIFG & UCAxTXIFG)){ 
00143             __delay_cycles(1000);
00144         TimeOutCounter++;
00145         if(TimeOutCounter >= 200)
00146           return ;    
00147                      
00148   }
00149   //if so...then send byte
00150   UCAxTXBUF = data;
00151 
00152 }
00153 
00162 void putsUART(unsigned char *buffer, unsigned short StringSize)
00163 {
00164   unsigned short i;
00165   unsigned char TimeOutCounter = 0;
00166   
00167   // transmit till NULL character is encountered 
00168   for(i=0;i<StringSize;i++)
00169   {
00170   // USCI_A0 TX buffer ready?
00171   while (!(UCAxIFG & UCAxTXIFG)){ 
00172             __delay_cycles(1000);
00173         TimeOutCounter++;
00174         if(TimeOutCounter >= 200)
00175           return ;    
00176                       
00177   }                    //wait until Tx buffer is empty      
00178   UCAxTXBUF = *buffer++;    // transfer data word to TX reg
00179             
00180   }
00181 
00182 }
00183 
00184 
00185 
00186 
00187 
00188 

Generated on Fri Dec 17 2010 12:09:22 for Multi-cell Lithium-Ion Battery Manager System using MSP430 and BQ76PL536 by  doxygen 1.7.1