irda.c

Go to the documentation of this file.
00001 /*
00002  * File:        irda.c
00003  * Purpose:     IRDA handling functions
00004  * Author:      Peter Ivanov, Olimex Ltd.
00005  * Modified by:
00006  * Created:     2007-05-19 11:29:32
00007  * Last modify: 2007-06-10 12:24:59 ivanovp {Time-stamp}
00008  * Copyright:   (C) Peter Ivanov, Olimex Ltd., 2007
00009  * Licence:     GPL
00010  */
00016 #include <msp430xG461x.h>
00017 #include "irda.h"
00018 
00019 void InitUCA_UART(void) 
00020 {
00021 
00022     // msb first, no parity, one stop, 8 bit
00023     UCA0CTL0 = 0x0;
00024 
00025     // clock -> SMCLK
00026     UCA0CTL1 = UCSSEL1;
00027 
00028     // Set 9600 baud rate
00029     // UCBRx  = 833
00030     // UCBRSx = 2
00031     // UCBRFx = 0
00032     // SMCLK  = 8 MHz
00033     UCA0BR0   = 0x41;
00034     UCA0BR1   = 0x03;
00035     UCA0MCTL  = 0x04;
00036     
00037     // Baud rate 115200
00038     //UCA0BR0   = 0x45;
00039     //UCA0BR1   = 0x00;
00040     //UCA0MCTL  = 0x04;
00041 
00042     // Set 9600 baud rate
00043     // UCBRx  = 833
00044     // UCBRSx = 2
00045     // UCBRFx = 0
00046     // SMCLK  = 2 MHz
00047     // UCA0BR0   = /*must to calculate*/0x00;           
00048     // UCA0BR1   = /*must to calculate*/0x00;   
00049     // UCA0MCTL  = /*must to calculate*/0x00;
00050 
00051 
00052 
00053     // IrDA encoder/decoder enabled - pulse length 5
00054     UCA0IRTCTL = UCIREN + UCIRTXPL5;
00055 
00056     // second functionality of pin
00057     P4SEL |= 0xc0;              // P4.6,47 UART option select
00058     P4DIR |= 0x40;              // P4.6 output direction
00059 
00060     // P7.7 - as otuput
00061     P7SEL &= ~0x80; // gpio
00062     P7DIR |= 0x80;  // output
00063     P7OUT |= 0x80;  // high/disable
00064 }
00065 
00066 void IRDAEnable(void) 
00067 {
00068     // P7.7 to low
00069     P7OUT &= ~0x80;
00070 }
00071 
00072 void IRDADisable(void) 
00073 {
00074     // P7.7 to high
00075     P7OUT |= 0x80;
00076 }
00077 
00078 void WriteByteUCA_UART(unsigned char data) 
00079 {
00080 
00081     //while ((IFG2&UCA0TXIFG)==0);      // wait while not ready
00082     while(UCA0STAT&UCBUSY);
00083     UCA0TXBUF = data;           // write
00084 }
00085 
00086 unsigned char ReadByteUCA_UART(void) 
00087 {
00088     //while ((IFG2&UCA0RXIFG)==0);      // wait for RX buffer (full)
00089     while(UCA0STAT&UCBUSY);
00090     return (UCA0RXBUF);
00091 }
00092 
00093 
00094 void InitIRDA(void)
00095 {
00096     // init uart interface
00097     InitUCA_UART();
00098 
00099     // enable module
00100     IRDAEnable();
00101 }
00102 
00103 unsigned char TestIRDA(void)
00104 {
00105     // This test is make with other board, which return echo via IRDA interface
00106 
00107     unsigned char i;
00108     unsigned char sample;
00109     unsigned char success;
00110 
00111     sample = 32;
00112     success = 0;
00113 
00114     InitIRDA();
00115 
00116 
00117     for(i=0; i<sample; i++) 
00118     {
00119 
00120         WriteByteUCA_UART(0x55);
00121 
00122         if(ReadByteUCA_UART() == 0x55) 
00123         {
00124             success++;
00125             break;
00126         }
00127     }
00128 
00129 
00130     for(i=0; i<sample; i++) 
00131     {
00132 
00133         WriteByteUCA_UART(0x11);
00134 
00135         if(ReadByteUCA_UART() == 0x11) 
00136         {
00137             success++;
00138             break;
00139         }
00140     }
00141 
00142     for(i=0; i<sample; i++) 
00143     {
00144         WriteByteUCA_UART(0xA0);
00145 
00146         if(ReadByteUCA_UART() == 0xA0) 
00147         {
00148             success++;
00149             break;
00150         }
00151     }
00152 
00153     for(i=0; i<sample; i++) 
00154     {
00155 
00156         WriteByteUCA_UART(0x66);
00157 
00158         if(ReadByteUCA_UART() == 0x66) 
00159         {
00160             success++;
00161             break;
00162         }
00163     }
00164 
00165     if(success == 4)
00166         return 0;
00167     else
00168         return 1;
00169 }
00170 

Generated on Sun Dec 9 17:17:10 2007 for Sample MSP430-4619LCD Project by  doxygen 1.5.1