<markdown>

# 하드웨어 만들기 - RF - EPS - PAYLOAD - 솔라셀

# 소프트웨어(주요기능)

1. EPS 제어(충전, 리셋) 1. RF에서 RX로 신호를 받아서 메시지 등록, 1. 다른칩 죽었는지 서로 감시 1. 시간되면 LED 깜박임 1. 인공위성정보 비콘으로 보냄 1. 전체 reset 하는 command. 1. 인자 업데이트

#### RF/BEACON 1. 비콘의 TX - 입력: 배터리 레벨, VBUS, 솔라패널 전류, 베터리 충전 여부, COMS, PAYLOAD 모듈동작상태, 온도, - 처리: RF칩에서 받아 들이는 신호로 만들기. - 출력: RF칩에 신호보내기.

#### RF/COMS 1. COMS RX - 입력: RF칩에서 신호 받음 - 처리: 입력 받은 신호를 I2C로 가공 - 출력: OBC에 I2C로 받은 신호 전달.(예약 메시지) 1. OBC 감시 - 입력: OBC에서 신호를 받는다. - 처리: OBC에 신호가 있는지 없는지 체크 - 출력: 입력 신호가 없으면 OBC에 리셋을 날려줌.

#### OBC 1. EPS 전원제어 (베터리, 수퍼캡 충전 방전) - 입력: 베터리 전압, 베터리 충전상태, 수퍼캡 충전상태, 수퍼캡 전압 - 처리:

1. 안테나 deployment 실행 - 처리: 20분이 지나면 안타나 deployment 핀 신호 인가 - 출력: deployment 완료 플래그 설정 (플래쉬메모리)

1. COMS, BEACON, PAYLOAD 감시

1. 메시지 스케쥴링 예약: COMS RX에서 메시지 받기 - 입력: 예약 메시지 신호 받기 - 처리: 시간을 파싱하여, 플래쉬 메모리에 스케쥴 예약 - 출력: 예약 완료 메시지 RX에 보내기 1. 메시지 예약 실행 - 입력: 시간, 슈퍼캡이 충전 되어 있는가?, 밤/낮, 회전상태 - 처리: 시간 보면서 예약 테이블에 스케쥴링된 메시지 실행 - 출력: PAYLOAD에 I2C로 메시지 보내기 1. 메시지 예약 삭제

read button and led on

#include <msp430x16x.h>

void main (void) {

WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
P6DIR |= BIT0;
P1OUT = BIT2; //pull up
while(1)
{
  if((P6IN & BIT1) == 0) { // LOW?
	  P6OUT |= BIT0;
  } else {
	  P6OUT &= ~BIT0;
  }
 }

}

#### LED: 모스코드 1. I2C로 받은 메시지를 LED 키기. - 입력: OBC에서 받은 메시지 - 처리: I2C로 받은 메시지를 모스 코드로 바꾼다. - 출력: 모스신호에 따라 LED 키기 2. PWM 으로 LED 제어 - ?

## 코드 morse, uart0

//******************************************************************************
//  MSP-FET430P140 Demo - USART1, Ultra-Low Pwr UART 9600 Echo ISR, 32kHz ACLK
//
//  Description: Echo a received character, RX ISR used. Normal mode is LPM3,
//  USART1 RX interrupt triggers TX Echo.
//  ACLK = UCLK1 = LFXT1 = 32768, MCLK = SMCLK = DCO~ 800k
//  Baud rate divider with 32768hz XTAL @9600 = 32768Hz/9600 = 3.41 (0003h 4Ah )
//  //* An external watch crystal is required on XIN XOUT for ACLK *//	
//
//
//                MSP430F149
//            -----------------
//        /|\|              XIN|-
//         | |                 | 32kHz
//         --|RST          XOUT|-
//           |                 |
//           |             P3.4|----------->
//           |                 | 9600 - 8N1
//           |             P3.5|<-----------
//
//
//  M. Buccini
//  Texas Instruments Inc.
//  Feb 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
//******************************************************************************

#include  <msp430x14x.h>
#include "morse.h"

char message[255];
uint8_t step = 0;
uint8_t sending = 0;

void main(void)
{
  volatile unsigned int i;
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P6DIR |= 0x01;

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P3SEL |= 0x30;                            // P3.4,5 = USART0 TXD/RXD
  ME1|= UTXE0 + URXE0;                     // Enable USART0 TXD/RXD
  UCTL0 |= CHAR;                            // 8-bit character
  UTCTL0 |= SSEL0;                          // UCLK = ACLK
  UBR00 = 0x03;                             // 32k/9600 - 3.41
  UBR10 = 0x00;                             //
  UMCTL0 = 0x4A;                            // Modulation
  UCTL0 &= ~SWRST;                          // Initialize USART state machine
  IE1 |= URXIE0;                            // Enable USART0 RX interrupt

 // _BIS_SR(LPM0_bits + GIE);                 // Enter LPM3 w/ interrupt
  _EINT();

  while (1) {
	  if (sending == 1) {
		  for(i=0; i < step;i++ ) {
			ascii(message[i]);
		  }
		  step=0;
		  sending=0;
	  }
  }
}

#pragma vector=USART0RX_VECTOR
__interrupt void usart0_rx (void)
{

  while (!(IFG1 & UTXIFG0));                // USART1 TX buffer ready?
  TXBUF0 = RXBUF0;                          // RXBUF1 to TXBUF1
  message[step] = RXBUF0;
  step++;
  if (RXBUF0 == 13)   // CR
  {
	  P6OUT ^= 0x01;
	  sending = 1;
  }
}



#include "morse.h"

//uint8_t done = 0b10000000;
uint8_t done = 0x80;

uint8_t output_pin;

void delay(void)
{
    volatile unsigned int i;
    i = 15000;                              // Delay
    do (i--);
    while (i != 0);
}

void mark(uint8_t t)
{
	volatile unsigned int i;
	for(i = 0; i < t; i++)
	{
		P6OUT &= ~0x01;                         // Turn On
		delay();
	}
	P6OUT |= 0x01;                          // Turn Off
	delay();
}

void space(uint8_t t)
{
	volatile unsigned int i;
	for(i = 0; i < t; i++)
	{
		P6OUT |= 0x01;
		delay();
	}
}

void morse(uint8_t m)
{
	while (m != done) {
   		mark(m & done ? 3 : 1);
   		space(1);
   		m = m << 1;
 	}
	space(3);
}


void ascii(char c) {
	uint8_t number_code[] = {
// 		0b11111100,	0b01111100, 0b00111100, 0b00011100, 0b00001100, 0b00000100,
// 		0b10000100, 0b11000100, 0b11100100, 0b11110100 // 0-9
		0xfc, 0x7c, 0x3c, 0x1c, 0xc, 0x4, 0x84, 0xc4, 0xe4, 0xf4
	};

	uint8_t alphabet_code[] = {
//		0b01100000, 0b10001000, 0b10101000, 0b10010000, 0b01000000, 0b00101000,
//		0b11010000, 0b00001000, 0b00100000, 0b01111000, 0b10110000, 0b01001000,
//		0b11100000, 0b10100000, 0b11110000, 0b01101000, 0b11011000, 0b01010000,
//		0b00010000, 0b11000000, 0b00110000, 0b00011000, 0b01110000, 0b10011000,
//		0b10111000, 0b11001000 // A-Z
		0x60, 0x88, 0xa8, 0x90, 0x40, 0x28, 0xd0, 0x8, 0x20, 0x78, 0xb0, 0x48, 0xe0, 0xa0, 0xf0, 0x68, 0xd8, 0x50, 0x10, 0xc0, 0x30, 0x18, 0x70, 0x98, 0xb8, 0xc8
	};

	if (c >= '0' && c <= '9') {
		morse(number_code[c- '0']);
	} else if (c >= 'a' && c <= 'z') {
		morse(alphabet_code[c - 'a']);
	} else if (c == ' ') {
		space(7);
	} else {
		morse(done);
	}
}

———- #### 타이머 watchdog timer

#include  <msp430x14x.h>

void main(void)
{
  WDTCTL = WDT_MDLY_32;                     // Set Watchdog Timer interval to ~30ms
  IE1 |= WDTIE;                             // Enable WDT interrupt
  P6DIR |= 0x01;                            // Set P1.0 to output direction

  _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 w/ interrupt
}

// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
  P6OUT ^= 0x01;                            // Toggle P1.0 using exclusive-OR
}

그냥 타이머

#include  <msp430x14x.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P6DIR |= 0x01;                            // P1.0 output
  CCTL0 = CCIE;                             // CCR0 interrupt enabled
  CCR0 = 50000;
  TACTL = TASSEL_2 + MC_2;                  // SMCLK, contmode

  _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 w/ interrupt
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
  P6OUT ^= 0x01;                            // Toggle P1.0
  CCR0 += 50000;                            // Add Offset to CCR0
}

PWM

//*******************************************************************************
//  MSP-FET430P140 Demo - Timer_A, PWM TA1-2, Up Mode, 32kHz ACLK
//
//  Description: This program generates two PWM outputs on P1.2,3 using
//  Timer_A configured for up mode. The value in CCR0, 512-1, defines the PWM
//  period and the values in CCR1 and CCR2 the PWM duty cycles. Using 32kHz
//  ACLK as TACLK, the timer period is 15.6ms with a 75% duty cycle on P1.2
//  and 25% on P1.3. Normal operating mode is LPM3.
//  ACLK = TACLK = LFXT1 = 32768Hz, MCLK = default DCO ~800kHz.
//  //* External watch crystal on XIN XOUT is required for ACLK *//	
//
//               MSP430F149
//            -----------------
//        /|\|              XIN|-
//         | |                 | 32kHz
//         --|RST          XOUT|-
//           |                 |
//           |         P1.2/TA1|--> CCR1 - 75% PWM
//           |         P1.3/TA2|--> CCR2 - 25% PWM
//
//  M. Buccini
//  Texas Instruments Inc.
//  Feb 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
//******************************************************************************

#include  <msp430x14x.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1DIR |= 0x0C;                            // P1.2 and P1.3 output
  P1SEL |= 0x0C;                            // P1.2 and P1.3 TA1/2 otions
  CCR0 = 512-1;                             // PWM Period
  CCTL1 = OUTMOD_7;                         // CCR1 reset/set
  CCR1 = 384;                               // CCR1 PWM duty cycle
  CCTL2 = OUTMOD_7;                         // CCR2 reset/set
  CCR2 = 128;                               // CCR2 PWM duty cycle
  TACTL = TASSEL_1 + MC_1;                  // ACLK, up mode

  _BIS_SR(LPM3_bits);                       // Enter LPM3
}

#### Low power mode (3 or 4)

#### 핀인터럽트 (전체핀) (하나핀)?

external interupt latch up?


port 1,2,3 이 가능 .

#### ADC

//******************************************************************************
//  MSP-FET430P140 Demo - ADC12, Sample A0, Set P1.0 if A0 > 0.5*AVcc
//
//  Description: A single sample is made on A0 with reference to AVcc.
//  Software sets ADC10SC to start sample and conversion - ADC12SC
//  automatically cleared at EOC. ADC12 internal oscillator times sample (16x)
//  and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC12
//  conversion complete, ADC12_ISR will force exit from LPM0 in Mainloop on
//  reti. If A0 > 0.5*AVcc, P1.0 set, else reset.
//
//                MSP430F149
//             -----------------
//         /|\|              XIN|-
//          | |                 |
//          --|RST          XOUT|-
//            |                 |
//      Vin-->|P6.0/A0      P1.0|--> LED
//
//  M. Buccini
//  Texas Instruments Inc.
//  Feb 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
//******************************************************************************

#include  <msp430x14x.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  ADC12CTL0 = SHT0_2 + ADC12ON;             // Set sampling time, turn on ADC12
  ADC12CTL1 = SHP;                          // Use sampling timer
  ADC12IE = 0x01;                           // Enable interrupt
  ADC12CTL0 |= ENC;                         // Conversion enabled
  P6SEL |= 0x02;                            // P6.0 ADC option select
  P6DIR |= 0x01;                            // P1.0 output

  for (;;)
  {
    ADC12CTL0 |= ADC12SC;                   // Sampling open
    _BIS_SR(CPUOFF + GIE);                  // LPM0, ADC12_ISR will force exit
  }
}

// ADC12 interrupt service routine
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR (void)
{
    if (ADC12MEM0 < 0x7FF)
      P6OUT &= ~0x01;                       // Clear P1.0 LED off
    else
      P6OUT |= 0x01;                        // Set P1.0 LED on
    _BIC_SR_IRQ(CPUOFF);                    // Clear CPUOFF bit from 0(SR)
}

#### UART & Serial port

 //******************************************************************************
//  MSP-FET430F149 Demo - ADC12, Sample A1, Send the level at Serial Port
//
//  Description: A single sample is made on A1 with reference to AVcc.
//  Software  start sample and conversion - Send out the
//  Analog voltage level to the serial port as two bytes.
//
//Additionally if the voltage is over 0.5*Vcc it makes LED at P6.2 glow
//
//                MSP430F149
//             -----------------
//         /|\|              XIN|-
//          | |                 |
//          --|RST          XOUT|-
//            |                 |
//      Vin-->|P6.1/A1      P6.2|-->
//            |                 |
//            |             P3.4|----------->
//            |                 | 9600 - 8N1
//            |             P3.5|<-----------
//
// referencedesigner.com
// Some of the Original codes are from Texas Instruments
//******************************************************************************

#include  <msp430x14x.h>

unsigned int delay ( unsigned int x)
{
unsigned int i,j;
for (i = 0; i<= x; i++)
  {
  for(j=0;j<=1000; j++) ;
  }
return 0;
}


void main(void)
{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop Watch Dog Timer
  ADC12CTL0 = SHT0_2 + ADC12ON;             // Set sampling time, turn on ADC12
  ADC12CTL1 =  SHP;
  ADC12IE = 0x01;                           // Enable interrupt
  ADC12MCTL0 = 0x01 ;
  ADC12CTL0 |= ENC ;                        // Conversion enabled
  P6SEL |= 0x02 ;                          // P6.1 ADC option select
  P6DIR |= 0x04;                           // P6.2 is output for LED

  // Serial Port Settings

  P3SEL |= 0x30;                            // P3.4,5 = USART0 TXD/RXD
  ME1 |= UTXE0 + URXE0;                     // Enable USART0 TXD/RXD
  UCTL0 |= CHAR;                            // 8-bit character
  UTCTL0 |= SSEL0;                          // UCLK = ACLK
  UBR00 = 0x03;                             // 32k/9600 - 3.41
  UBR10 = 0x00;                             //
  UMCTL0 = 0x4A;                            // Modulation
  UCTL0 &= ~SWRST;                          // Initialize USART state machine
  IE1 |= URXIE0;                            // Enable USART0 RX interrupt

  for (;;)
  {
    // This should actually happen in a timer interrupt where
    // we may like to sample only once in, say 1 second
    delay(500);
    ADC12CTL0 |= ADC12SC;                   // Sampling open
    _BIS_SR(CPUOFF + GIE);                  // LPM0, ADC12_ISR will force exit
  }
}

// ADC12 interrupt service routine

#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR (void)
{
 unsigned short lResultRSSI ;
 unsigned char part1, part2;

    if (ADC12MEM0 < 0x7FF)
      P6OUT &= ~0x04;                       // Clear P6.2 - LED off
 else
      P6OUT |= 0x04;                        // Set P6.2 - LED on
    _BIC_SR_IRQ(CPUOFF);                    // Clear CPUOFF bit from 0(SR)

   lResultRSSI = ADC12MEM0 ;                          // RXBUF0 to TXBUF0

  part1 = (lResultRSSI & 0x00FF); // lsb
  part2 = (lResultRSSI & 0xFF00) >> 8; // msb

  while (!(IFG1 & UTXIFG0));
  TXBUF0 = part2; // We send MSB first

  while (!(IFG1 & UTXIFG0));
  TXBUF0 = part1;
}

#### PWM - hardware pwm: http://gushh.net/blog/msp430-servo/ - PWM DC Motor Control Using Timer_A of the MSP430: http://www.ti.com/lit/an/slaa120/slaa120.pdf

#### I2C - EEPROM (메시지) - 24LC256 http://ww1.microchip.com/downloads/en/devicedoc/21203m.pdf - msp430 http://read.pudn.com/downloads143/doc/623226/C/I2Croutines.c__.htm

##### MSP430 1611 I2C 관련 레지스터 - U0CTL:

U0CTL |= I2C+SYNC;
U0CTL &= ~I2CEN;
U0CTL |= I2CEN;

- I2CTCTL = I2CSSEL_2; - I2CSCLH = 0x03; - I2CSCLL = 0x03; - I2CNDAT = 0x03; - I2CSA = 0x50; - I2CIE = RXRDYIE; - I2CTCTL |= I2CSTT + I2CSTP;

Setting I2CEN = 0 has the following effects:

- I2C communication stops - SDA and SCL are high impedance - I2CTCTL, bits 3-0 are cleared and bits 7-4 are unchanged - I2CDCTL and I2CDR register is cleared - Transmit and receive shift registers are cleared - U0CTL, I2CNDAT, I2CPSC, I2CSCLL, I2CSCLH registers are unchanged - I2COA, I2CSA, I2CIE, I2CIFG, and I2CIV registers are unchanged

When I2RM=1, I2CSTP must be set before the last I2CDR value is written. Othwerwise, correct STOP generation will not occur.

RXRDYIFG

Receive ready interrupt/status. This flag is set when the I2C module has received new data. RXRDYIFG is automatically cleared when I2CDR is read and the receive buffer is empty. A receiver overrun is indicated if bit I2CRXOVR = 1. RXRDYIFG is used in receive mode only.

TXRDYIFG

Transmit ready interrupt/status. This flag is set when the I2C module is ready for new transmit data (master transmit mode) or when another master is requesting data (slave transmit mode). TXRDYIFG is automatically cleared when I2CDR and the transmit buffer are full. A transmit underflow is indicated if I2CTXUDF = 1. Unused in receive mode.

eeprom http://www.eetkorea.com/STATIC/PDF/201105/EEKOL_2011MAY24_STOR_AN_01.pdf

//******************************************************************************
//  MSP-FET430P140 Demo - I2C, Master Interface to DAC8571, Read/Write
//
//  Description: I2C communication with a DAC8571 in read and write mode is
//  demonstrated. MSP430 writes a 0x00 to the DAC to initialize communication
//  and then reads the value from the DAC, increments it by 1, and Transmits
//  it back to the DAC8571 in a repetitive manner to generate a ramp
//  ACLK = n/a, MCLK = SMCLK = default DCO ~ 800k, SCL = SMCLK/10
//  //* MSP430F169 Device Required *//
//
//                                 /|\  /|\
//                  DAC8571        10k  10k     EEPROM
//                    slave         |    |        master
//              -----------------|  |    |  -----------------
//             |             SDA |<-|---+->|P3.1             |
//             |                 |  |      |                 |
//             |                 |  |      |                 |
//      GND <--|A0           SCL |<-+----->|P3.3             |
//             |                 |         |                 |
//             |                 |         |                 |
//             |              Vdd|<---+--->|Vcc              |
//             |             Vref|<---|    |                 |
//             |              GND|<------->|GND              |
//             |                 |         |                 |
//
//
//   DAC8571 I2C address = 0x4C (A0 = GND)
//
//
//  H. Grewal
//  Texas Instruments Inc.
//  Feb 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
//******************************************************************************

#include  <msp430x16x.h>

volatile unsigned int i;

int PtrTransmit;
unsigned char I2CBuffer[3];

/*---------------------------------------------------------------------------*/
void InitI2C(void)
// Description:
//   Initialization of the I2C Module
{
  P3SEL = 0x0A;          // select module function for the used I2C pins
  P3DIR &= ~0x0A;

  // Recommended initialisation steps of I2C module as shown in User Guide:
  U0CTL |= I2C+SYNC;     // (1) Select I2C mode with SWRST=1
  U0CTL &= ~I2CEN;       // (2) disable the I2C module
                         // (3) Configure the I2C module with I2CEN=0 :
                                // U0CTL default settings:
                                //   7-bit addressing, no DMA, no feedback
  I2CTCTL = I2CTRX+I2CSSEL_2;   // byte mode, repeat mode, clock source = SMCLK,
                                // transmit mode
  I2CSA = 0x50;         // define Slave Address
                                // In this case the Slave Address defines the
                                // control byte that is sent to the EEPROM.
//  I2CPSC = 0x00;                // I2C clock = clock source/1
//  I2CTCTL = I2CSSEL_1;                      // SMCLK

  I2CSCLH = 0x03;               // SCL high period = 5*I2C clock
  I2CSCLL = 0x03;               // SCL low period  = 5*I2C clock
  U0CTL |= I2CEN;        // (4) set I2CEN via software
}

void I2CWriteInit(void)
// Description:
//   Initialization of the I2C Module for Write operation.
{
  U0CTL |= MST;           // define Master Mode
  I2CTCTL |= I2CTRX;      // I2CTRX=1 => Transmit Mode (R/W bit = 0)
  I2CIFG &= ~TXRDYIFG;
  I2CIE = TXRDYIE;        // enable Transmit ready interrupt
}

/*---------------------------------------------------------------------------*/
void I2CReadInit(void)
// Description:
//   Initialization of the I2C Module for Read operation.
{
  I2CTCTL &= ~I2CTRX;     // I2CTRX=0 => Receive Mode (R/W bit = 1)
  I2CIE = RXRDYIE;        // enable Receive ready interrupt
}

/*---------------------------------------------------------------------------*/
void EEPROM_ByteWrite(unsigned int Address, unsigned char Data)
// Description:
//   Byte Write Operation. The communication via the I2C bus with an EEPROM
//   (2465) is realized. A data byte is written into a user defined address.
{
  unsigned char adr_hi;
  unsigned char adr_lo;

  while (I2CDCTL&I2CBUSY); // wait until I2C module has finished all operations

  adr_hi = Address >> 8;         // calculate high byte
  adr_lo = Address & 0xFF;       //     and low byte of address

  I2CBuffer[2] = adr_hi;         // store single bytes that have to be sent
  I2CBuffer[1] = adr_lo;         //   in the I2CBuffer.
  I2CBuffer[0] = Data;
  PtrTransmit = 2;               // set I2CBuffer Pointer

  I2CWriteInit();
  I2CNDAT = 3;           // 1 control byte + 3 bytes should be transmitted
  I2CTCTL |= I2CSTT+I2CSTP;   // start and stop condition generation
                              //      => I2C communication is started
}


/*---------------------------------------------------------------------------*/
void EEPROM_AckPolling(void)
// Description:
//   Acknowledge Polling. The EEPROM will not acknowledge if a write cycle is
//   in progress. It can be used to determine when a write cycle is completed.
{ unsigned int count;
  while (I2CDCTL&I2CBUSY); // wait until I2C module has finished all operations
  P6OUT ^= 0x01;
  count=0;
  U0CTL &= ~I2CEN;       // clear I2CEN bit => necessary to re-configure I2C module
  I2CTCTL |= I2CRM;      // transmission is software controlled
  U0CTL |= I2CEN;        // enable I2C module
  I2CIFG = NACKIFG;      // set NACKIFG
  while (NACKIFG & I2CIFG)
  {
    I2CIFG=0x00;            // clear I2C interrupt flags
    U0CTL |= MST;           // define Master Mode
    I2CTCTL |= I2CTRX;      // I2CTRX=1 => Transmit Mode (R/W bit = 0)
    I2CTCTL |= I2CSTT;      // start condition is generated
    while (I2CTCTL&I2CSTT); // wait till I2CSTT bit was cleared
    I2CTCTL |= I2CSTP;      // stop condition is generated after slave address was sent
                            //      => I2C communication is started
    while (I2CDCTL&I2CBUSY); // wait till stop bit is reset
    count=count+1;
    P6OUT ^= 0x01;
  }
  U0CTL &= ~I2CEN;       // clear I2CEN bit => necessary to re-configure I2C module
  I2CTCTL &= ~I2CRM;     // transmission is by the I2C module
  U0CTL |= I2CEN;        // enable I2C module

  return;
}

unsigned char EEPROM_RandomRead(unsigned int Address)
// Description:
//   Random Read Operation. Data is read from the EEPROM. The EEPROM
//   address is defined with the parameter Address.
{
  unsigned char adr_hi;
  unsigned char adr_lo;

  while (I2CDCTL&I2CBUSY);  // wait until I2C module has finished all operations

  adr_hi = Address >> 8;         // calculate high byte
  adr_lo = Address & 0xFF;       //     and low byte of address

  I2CBuffer[1] = adr_hi;         // store single bytes that have to be sent
  I2CBuffer[0] = adr_lo;         //   in the I2CBuffer.
  PtrTransmit = 1;               // set I2CBuffer Pointer

  I2CWriteInit();
  I2CNDAT = 2;         // 1 control byte + 2 bytes should be transmitted
  I2CIFG &= ~ARDYIFG;  // clear Access ready interrupt flag
  I2CTCTL |= I2CSTT;   // start condition generation
                       //      => I2C communication is started
  while ((~I2CIFG)&ARDYIFG);  // wait untill transmission is finished
  I2CReadInit();
  I2CNDAT = 1;         // 1 byte should be received

  I2CIFG &= ~ARDYIFG;         // clear Access ready interrupt flag
  I2CTCTL |= I2CSTT+I2CSTP;   // start receiving and finally generate
                              //                  re-start and stop condition
  while ((~I2CIFG)&ARDYIFG);  // wait untill transmission is finished
  return I2CBuffer[0];
}


/*---------------------------------------------------------------------------*/
unsigned char EEPROM_CurrentAddressRead(void)
// Description:
//   Current Address Read Operation. Data is read from the EEPROM. The current
//   address from the EEPROM is used.
{
  while (I2CDCTL&I2CBUSY); // wait until I2C module has finished all operations
  I2CReadInit();
  U0CTL |= MST;         // define Master Mode
  I2CNDAT = 1;          // 1 byte should be received
  I2CIFG &= ~ARDYIFG;         // clear Access ready interrupt flag
  I2CTCTL |= I2CSTT+I2CSTP;   // start receiving and finally generate
                              //              re-start and stop condition
  while ((~I2CIFG)&ARDYIFG);  // wait untill transmission is finished
  return I2CBuffer[0];
}


void main(void)
{
  volatile int a,b, c;
  WDTCTL = WDTPW | WDTHOLD;                 // Disable the Watchdog.
  P6DIR |= 0x01;  //LED
  InitI2C();
  _EINT();

  EEPROM_ByteWrite(0x0000,0x12);
  __delay_cycles(300);

  EEPROM_AckPolling();          // Wait for EEPROM write cycle completion
  EEPROM_ByteWrite(0x0001,0x34);
  EEPROM_AckPolling();
  EEPROM_ByteWrite(0x0002,0x54);
  EEPROM_AckPolling();

  a=EEPROM_RandomRead(0x00);
  b=EEPROM_RandomRead(0x01);
  c=EEPROM_CurrentAddressRead();

  while(1)
  {
  }
}

//// I2C Interrupt Vector (I2CIV) handler
#pragma vector=USART0TX_VECTOR
__interrupt void USART0 (void)
{
  switch( I2CIV )
  {
  case 10:
  {
      I2CBuffer[0]=I2CDRB;   // store received data in buffer
      break;
  }
   case 12:
   {
    I2CDRB = I2CBuffer[PtrTransmit];
    PtrTransmit = PtrTransmit-1;
    if (PtrTransmit <0)
    {
    	I2CIE &= ~TXRDYIE;        // disable interrupts
    }
    break;
    }
  }
}
#include  "msp430g2553.h"

//Address word + "HELLO WORLD"
unsigned char txdata[14] = {0x00, 0x00, 0x00, 0x48, 0x45, 0x4C, 0x4C, 0x4F, 0x20, 0x57, 0x4F, 0x52, 0x4C, 0x44};

unsigned char rxdata[12];
unsigned char tx_byte_count;
unsigned char rx_byte_count;
unsigned char tx_byte_counter;
unsigned char rx_byte_counter;
unsigned char i;
unsigned char tx_rx;

void i2c_tx(unsigned char tx_count);
void i2c_rx(unsigned char rx_count);


void main(void)
{
   WDTCTL = WDTPW + WDTHOLD;                  //Stop WDT

   BCSCTL1 = CALBC1_1MHZ;                     //Set DCO to 1MHz
   DCOCTL = CALDCO_1MHZ;
   P1SEL = BIT1 + BIT2;                     //Set RXD and TXD
   P1SEL2 = BIT1 + BIT2;
   UCA0CTL1 |= UCSSEL_2;                     //Have USCI use SMCLK AKA 1MHz main CLK
   UCA0BR0 = 104;                           //Baud = 9600
   UCA0BR1 = 0;
   UCA0MCTL = UCBRS_1;                        //Modulation
   UCA0CTL1 &= ~UCSWRST;                     //Start USCI

   P1SEL |= BIT6 + BIT7;                     //Set I2C pins
   P1SEL2|= BIT6 + BIT7;
   UCB0CTL1 |= UCSWRST;                     //Enable SW reset
   UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;         //I2C Master, synchronous mode
   UCB0CTL1 = UCSSEL_2 + UCSWRST;               //Use SMCLK, keep SW reset
   UCB0BR0 = 12;                           //fSCL = SMCLK/12 = ~100kHz
   UCB0BR1 = 0;
   UCB0I2CSA = 0b1010000;                     //Slave Address
   UCB0CTL1 &= ~UCSWRST;                     //Clear SW reset, resume operation
   IE2 |= UCB0TXIE;                        //Enable TX interrupt
   IE2 |= UCB0RXIE;                        //Enable RX interrupt

   __delay_cycles(20000);                     //Just a start up delay

   i2c_tx(13);                              //i2c TX 13 bytes(Address word + "HELLO WORLD"
   __delay_cycles(20000);                     //Allow 24LC256 to write data
   i2c_tx(2);                              //i2c TX address
   i2c_rx(12);                              //i2c RX data

   for(i = 1; i < 12; i++)
   {
      while(!(IFG2 & UCA0TXIFG));
      UCA0TXBUF = rxdata[i];                  //UART TX data
   }
   __bis_SR_register(CPUOFF + GIE);            //Wait for a reset
}

void i2c_tx(unsigned char tx_count)
{
   tx_rx = 0;
   tx_byte_count = tx_count + 1;
   tx_byte_counter = tx_count;                  // Load TX byte counter
   UCB0CTL1 |= UCTR + UCTXSTT;                  // I2C TX, start condition
   __bis_SR_register(CPUOFF + GIE);            // Enter LPM0 w/ interrupts
                                       // Remain in LPM0 until all data is TX'd
}

void i2c_rx(unsigned char rx_count)
{
   tx_rx = 1;
   rx_byte_count = rx_count + 1;
   rx_byte_counter = rx_count;                  // Load RX byte counter
   UCB0CTL1 &= ~UCTR;                        // I2C RX
   UCB0CTL1 |= UCTXSTT;                     // I2C start condition
   __bis_SR_register(CPUOFF + GIE);            // Enter LPM0 w/ interrupts
                                       // Remain in LPM0 until all data is RX'd
}

//interrupt(USCIAB0TX_VECTOR) USCIAB0TX_ISR(void)
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)            //For mspgcc
{
   if(tx_rx == 0)
   {
      if (tx_byte_counter > 0)               //Check TX byte counter
      {
         UCB0TXBUF = txdata[tx_byte_count - tx_byte_counter];         // Load TX buffer
         tx_byte_counter--;                  //Decrement TX byte counter
      }
      else if(tx_byte_counter == 0)
      {
         UCB0CTL1 |= UCTXSTP;               //I2C stop condition
         while (UCB0CTL1 & UCTXSTP);            //Ensure stop condition got sent
         IFG2 &= ~UCB0TXIFG;                  //Clear USCI_B0 TX int flag
         __bic_SR_register_on_exit(CPUOFF);      //Exit LPM0
      }
   }
   else if(tx_rx == 1)
   {
      if (rx_byte_counter > 0)               //Check RX byte counter
      {
         rxdata[rx_byte_count - rx_byte_counter] = UCB0RXBUF;
         rx_byte_counter--;                  //Decrement RX byte counter
      }
      else if(rx_byte_counter == 0)
      {
         UCB0CTL1 |= UCTXSTP;               // I2C stop condition
         while (UCB0CTL1 & UCTXSTP);            // Ensure stop condition got sent
         rxdata[rx_byte_count - (rx_byte_counter + 1)] = UCB0RXBUF;
         rxdata[rx_byte_count - (rx_byte_counter + 1)] = UCB0RXBUF;
         IFG2 &= ~UCB0RXIFG;                  // Clear USCI_B0 RX int flag
         __bic_SR_register_on_exit(CPUOFF);      // Exit LPM0
      }
   }
}

uart to eeprpm and morse

//******************************************************************************
//  MSP-FET430P140 Demo - USART1, Ultra-Low Pwr UART 9600 Echo ISR, 32kHz ACLK
//
//  Description: Echo a received character, RX ISR used. Normal mode is LPM3,
//  USART1 RX interrupt triggers TX Echo.
//  ACLK = UCLK1 = LFXT1 = 32768, MCLK = SMCLK = DCO~ 800k
//  Baud rate divider with 32768hz XTAL @9600 = 32768Hz/9600 = 3.41 (0003h 4Ah )
//  //* An external watch crystal is required on XIN XOUT for ACLK *//	
//
//
//                MSP430F149
//            -----------------
//        /|\|              XIN|-
//         | |                 | 32kHz
//         --|RST          XOUT|-
//           |                 |
//           |             P3.4|----------->
//           |                 | 9600 - 8N1
//           |             P3.5|<-----------
//
//
//  M. Buccini
//  Texas Instruments Inc.
//  Feb 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
//******************************************************************************

#include  <msp430x16x.h>
#include "morse.h"

char message[255];
uint8_t step = 0;
uint8_t sending = 0;

void initUart() {
	  P3SEL |= 0x30;                            // P3.4,5 = USART0 TXD/RXD
	  ME1|= UTXE0 + URXE0;                     // Enable USART0 TXD/RXD
	  UCTL0 |= CHAR;                            // 8-bit character
	  UTCTL0 |= SSEL0;                          // UCLK = ACLK
	  UBR00 = 0x03;                             // 32k/9600 - 3.41
	  UBR10 = 0x00;                             //
	  UMCTL0 = 0x4A;                            // Modulation
	  UCTL0 &= ~SWRST;                          // Initialize USART state machine
	  IE1 |= URXIE0;                            // Enable USART0 RX interrupt
}

void main(void)
{
  volatile unsigned int i;
  volatile unsigned char x;
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P6DIR |= 0x01;
  initUart();

// // _BIS_SR(LPM0_bits + GIE);                 // Enter LPM3 w/ interrupt

  _EINT();
//   sending = 1;
   step = 10;

	while (1) {
	  if (sending == 1) {
		  UCTL0 &= ~CHAR;

		  InitI2C();

		  for(i=0; i < step;i++ ) {
			  x= EEPROM_ByteWrite(i, message[i]);
		 	  EEPROM_AckPolling();
		  }

		  for(i=0; i < step;i++ ) {
			  x= EEPROM_RandomRead(i);
			  ascii(x);
		  }
		  step=0;
		  sending=0;

		  //Re-Configuring the USART Module for UART or SPI Operation
		  UCTL0 &= ~I2C; //Clear I2C, SYNC, and I2CEN (CLR.B  &U0CTL)
		  UCTL0 &= ~SYNC;
		  UCTL0 &= ~I2CEN;
		  UCTL0 |= SWRST;                          // Set SWRST (MOV.B  #SWRST,&U0CTL)

		  initUart();
	  }
  }
}

#pragma vector=USART0RX_VECTOR
__interrupt void usart0_rx (void)
{

  while (!(IFG1 & UTXIFG0));                // USART1 TX buffer ready?
  TXBUF0 = RXBUF0;                          // RXBUF1 to TXBUF1
  message[step] = RXBUF0;

  _EINT();

  step++;
  if (RXBUF0 == 13)   // CR
  {
	  P6OUT ^= 0x01;
	  sending = 1;
  }
}

eeprom to uart tx

//******************************************************************************
//  MSP-FET430P140 Demo - USART0, Ultra-Low Pwr UART 9600 Echo ISR, 32kHz ACLK
//
//  Description: Echo a received character, RX ISR used. In the Mainloop UART0
//  is made ready to receive one character with interrupt active. The Mainloop
//  waits in LPM3. The UART0 ISR forces the Mainloop to exit LPM3 after
//  receiving one character which echo's back the received character.
//  ACLK = UCLK0 = LFXT1 = 32768, MCLK = SMCLK = DCO~ 800k
//  Baud rate divider with 32768hz XTAL @9600 = 32768Hz/9600 = 3.41 (0003h 4Ah )
//  //* An external watch crystal is required on XIN XOUT for ACLK *//	
//
//                MSP430F149
//            -----------------
//        /|\|              XIN|-
//         | |                 | 32kHz
//         --|RST          XOUT|-
//           |                 |
//           |             P3.4|----------->
//           |                 | 9600 - 8N1
//           |             P3.5|<-----------
//
//
//  M. Buccini
//  Texas Instruments Inc.
//  Feb 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
//******************************************************************************

#include  <msp430x16x.h>
#include "24lc256.h"
#include "morse.h"

unsigned char message[255];
int step = 36;

void initUart()
{
	  P3SEL |= 0x30;                            // P3.4,5 = USART0 TXD/RXD
	  ME1 |= UTXE0 + URXE0;                     // Enable USART0 TXD/RXD
	  UCTL0 |= CHAR;                            // 8-bit character
	  UTCTL0 |= SSEL0;                          // UCLK = ACLK
	  UBR00 = 0x03;                             // 32k/9600 - 3.41
	  UBR10 = 0x00;                             //
	  UMCTL0 = 0x4A;                            // Modulation
	  UCTL0 &= ~SWRST;                          // Initialize USART state machine
	  IE1 |= URXIE0;                            // Enable USART0 RX interrupt

}

void main(void)
{
  volatile unsigned int i;

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  initUart();
  _EINT();


  U0CTL &= ~CHAR;
  InitI2C();

  for(i=0; i < step;i++ ) {
	  message[i]= EEPROM_RandomRead(i);
//	  ascii(x);
  }

  U0CTL &= ~I2C; //Clear I2C, SYNC, and I2CEN (CLR.B  &U0CTL)
  U0CTL &= ~SYNC;
  U0CTL &= ~I2CEN;
  U0CTL |= SWRST;                          // Set SWRST (MOV.B  #SWRST,&U0CTL)

  initUart();
// Mainloop
  for (;;)
  {
	  _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3 w/interrupt
	  for(i=0; i< step; i++) {
		  while (!(IFG1 & UTXIFG0));                // USART0 TX buffer ready?
	  	  	  TXBUF0 = message[i];                          // RXBUF0 to TXBUF0
  	  }
  }
}

// UART0 RX ISR will for exit from LPM3 in Mainloop
#pragma vector=USART0RX_VECTOR
__interrupt void usart0_rx (void)
{
  _BIC_SR_IRQ(LPM3_bits);                   // Clear LPM3 bits from 0(SR)
}

#### SPI

#### 타이머 인터럽트: counter

#### pulseIn? RF?

#### delay 구현 조사

static void __inline__ delay(register unsigned int n)
{
    __asm__ __volatile__ (
		"1: \n"
		" dec	%[n] \n"
		" jne	1b \n"
        : [n] "+r"(n));
}

void delay_ms(unsigned int n)
{
  while (n--)
  {
    delay(F_CPU/4000);
  }
}

#### RTC Software Realtime Clock http://www.43oh.com/forum/viewtopic.php?f=10&t=2477

#### 7020-1

uart to 7020

main.c

#include  <msp430x16x.h>
#include "morse.h"
#include "rf.h"

char message[255];
char _message[255] = {'h','e','l','l','o',' ','o','s','s','i',' ', '1'};

uint8_t step = 0;
uint8_t sending = 0;

void initUart() {
	  P3SEL |= 0x30;                            // P3.4,5 = USART0 TXD/RXD
	  ME1|= UTXE0 + URXE0;                     // Enable USART0 TXD/RXD
	  UCTL0 |= CHAR;                            // 8-bit character
	  UTCTL0 |= SSEL0;                          // UCLK = ACLK
	  UBR00 = 0x03;                             // 32k/9600 - 3.41
	  UBR10 = 0x00;                             //
	  UMCTL0 = 0x4A;                            // Modulation
	  UCTL0 &= ~SWRST;                          // Initialize USART state machine
	  IE1 |= URXIE0;                            // Enable USART0 RX interrupt
}

void main(void)
{
  volatile unsigned int i;
  volatile unsigned char x;
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P6DIR |= 0x01;
  initUart();
  initRF();
// // _BIS_SR(LPM0_bits + GIE);                 // Enter LPM3 w/ interrupt

  _EINT();
//   sending = 1;
   step = 10;
   __delay_cycles(1000000);

   while(1) {
	   for(i=0; i < 12;i++ ) {
		  ascii(_message[i]);
	   }
   }
	while (1) {
	  if (sending == 1) {
		  UCTL0 &= ~CHAR;

		  InitI2C();

		  for(i=0; i < step-1;i++ ) {
			  x= EEPROM_ByteWrite(i, message[i]);
		 	  EEPROM_AckPolling();
		  }

		  for(i=0; i < step-1;i++ ) {
			  x = EEPROM_RandomRead(i);
			  ascii(x);
		  }
		  step=0;
		  sending=0;

		  //Re-Configuring the USART Module for UART or SPI Operation
		  UCTL0 &= ~I2C; //Clear I2C, SYNC, and I2CEN (CLR.B  &U0CTL)
		  UCTL0 &= ~SYNC;
		  UCTL0 &= ~I2CEN;

		  UCTL0 |= SWRST;                          // Set SWRST (MOV.B  #SWRST,&U0CTL)

		  initUart();
	  }
  }
}

#pragma vector=USART0RX_VECTOR
__interrupt void usart0_rx (void)
{

  while (!(IFG1 & UTXIFG0));                // USART1 TX buffer ready?
  TXBUF0 = RXBUF0;                          // RXBUF1 to TXBUF1
  message[step] = RXBUF0;

  _EINT();

  step++;
  if (RXBUF0 == 13)   // CR
  {
	  //P6OUT ^= 0x01;
	  sending = 1;
  }
}

rc.c

#include  "rf.h"

unsigned char r0[4] = {0x71, 0x39, 0x33,0xa0}; //433Mhz
unsigned char r1[3] = {0x02, 0x90, 0x11};
unsigned char r2[4] = {0x80, 0x0f, 0x00, 0xd2};
unsigned char r2_high[4] = {0x80, 0x0f, 0x7e, 0xd2};

void adf702x_write_register(unsigned char r)
{
	volatile int i;

	for(i = 7; i >= 0; i--)
	{
	// _
	P5OUT &= ~BIT1;                            // low
	if(r & (1<<i)) {
		P5OUT |= BIT3;
	} else {
		P5OUT &= ~BIT3;
	}
	__delay_cycles(30);

	// _|-
	P5OUT |= BIT1;                            // high
	//P5OUT |= BIT3;
	__delay_cycles(30);
	}

	//_|-|
	P5OUT &= ~BIT1;                            // low
	//__delay_cycles(100);

}

void adf702x_write_r0()
{
	volatile int i;

	//P5OUT &= ~BIT3;

	for(i=0;i<4;i++)
	{
		adf702x_write_register(r0[i]);
	}

	P5OUT |= BIT4;                            // high
	__delay_cycles(60);
	P5OUT &= ~BIT4;
	//P5OUT &= ~BIT3;
}

void adf702x_write_r1()
{
	volatile int i;

	for(i=0;i<3;i++)
	{
		adf702x_write_register(r1[i]);
	}

	P5OUT |= BIT4;                            // high
	__delay_cycles(60);
	P5OUT &= ~BIT4;

}

void adf702x_write_r2(int isHigh)
{
	volatile int i;

	//P5OUT &= ~BIT3;                            // low

	if (isHigh == 0) {
		for(i=0;i<4;i++)
		{
			adf702x_write_register(r2[i]);
		}
	}else {
		for(i=0;i<4;i++)
		{
			adf702x_write_register(r2_high[i]);
		}
	}

	P5OUT |= BIT4;                            // SLE high_low
	__delay_cycles(60);
	P5OUT &= ~BIT4;

	//P5OUT &= ~BIT3;
}

void initRF()
{
	// DATA I/I is 5.0
	//SCLK_PIN is 5.1
	//SDATA_PIN is 5.3
	//SLE PIN is 5.4
	// CE PIN is 5.5
	P5DIR |= BIT0 + BIT1 + BIT3 + BIT4 + BIT5;
	P5OUT |= BIT5;                            // CE is HIGH

	P5OUT |= BIT0; // DATA is HIGH

	adf702x_write_r0();
	//__delay_cycles(100);
	adf702x_write_r1();
 	//__delay_cycles(100);
	adf702x_write_r2(1);
 	//__delay_cycles(100);
    adf702x_write_r2(0);
}

morse.c

#include "morse.h"
#include "rf.h"

//uint8_t done = 0b10000000;
uint8_t done = 0x80;

uint8_t output_pin;

void delay(void)
{
    volatile unsigned int i;
    i = 10000;                              // Delay
    do (i--);
    while (i != 0);
}

void mark(uint8_t t)
{
	volatile unsigned int i;
//	P5OUT |= BIT0;
	adf702x_write_r2(1);
	P6OUT &= ~0x01;
	for(i = 0; i < t; i++)
	{                         // Turn On
		delay();
	}
//	P5OUT &= ~BIT0;
	adf702x_write_r2(0);
	P6OUT |= 0x01;                          // Turn Off
	delay();
}

void space(uint8_t t)
{
	volatile unsigned int i;
//	P5OUT &= ~BIT0;
	adf702x_write_r2(0);
	P6OUT |= 0x01;

	for(i = 0; i < t; i++)
	{
		delay();
	}
}

void morse(uint8_t m)
{
	while (m != done) {
   		mark(m & done ? 3 : 1);
   		space(1);                                                                                                                                             		m = m << 1;
 	}
	space(3);
}


void ascii(char c) {

	uint8_t number_code[] = {
// 		0b11111100,	0b01111100, 0b00111100, 0b00011100, 0b00001100, 0b00000100,
// 		0b10000100, 0b11000100, 0b11100100, 0b11110100 // 0-9
		0xfc, 0x7c, 0x3c, 0x1c, 0xc, 0x4, 0x84, 0xc4, 0xe4, 0xf4
	};

	uint8_t alphabet_code[] = {
//		0b01100000, 0b10001000, 0b10101000, 0b10010000, 0b01000000, 0b00101000,
//		0b11010000, 0b00001000, 0b00100000, 0b01111000, 0b10110000, 0b01001000,
//		0b11100000, 0b10100000, 0b11110000, 0b01101000, 0b11011000, 0b01010000,
//		0b00010000, 0b11000000, 0b00110000, 0b00011000, 0b01110000, 0b10011000,
//		0b10111000, 0b11001000 // A-Z
		0x60, 0x88, 0xa8, 0x90, 0x40, 0x28, 0xd0, 0x8, 0x20, 0x78, 0xb0, 0x48, 0xe0, 0xa0, 0xf0, 0x68, 0xd8, 0x50, 0x10, 0xc0, 0x30, 0x18, 0x70, 0x98, 0xb8, 0xc8
	};

	if (c >= '0' && c <= '9') {
		morse(number_code[c- '0']);
	} else if (c >= 'a' && c <= 'z') {
		morse(alphabet_code[c - 'a']);
	} else if (c == ' ') {
		space(7);
	} else {
		morse(done);
	}
}

7021-n

4k일때는 잘되는것 같은데, 9.6k 일때 핀 인터럽트가 밀리는것 같다.

#include  <msp430x16x.h>
#include "morse.h"
#include "rf.h"

char message[255];
//char _message[255] = {'h','e','l','l','o',' ','o','s','s','i',' ', '1'};

char _message[255] = {'a','b','c', 'd','e','f','g','h','i','j','k','l'};

uint8_t step = 0;
uint8_t sending = 0;
int i =7;
int m =0;

void initUart() {
	  P3SEL |= 0x30;                            // P3.4,5 = USART0 TXD/RXD
	  ME1|= UTXE0 + URXE0;                     // Enable USART0 TXD/RXD
	  UCTL0 |= CHAR;                            // 8-bit character
	  UTCTL0 |= SSEL0;                          // UCLK = ACLK
	  UBR00 = 0x03;                             // 32k/9600 - 3.41
	  UBR10 = 0x00;                             //
	  UMCTL0 = 0x4A;                            // Modulation
	  UCTL0 &= ~SWRST;                          // Initialize USART state machine
	  IE1 |= URXIE0;                            // Enable USART0 RX interrupt
}

void init_txrx_interrupt()
{
	  P1OUT = BIT2; //pull up
	  P1IE |= BIT2; // interrupt enable
	  P1IES |= BIT2; // interrupt hi/lo falling edge
	  //P1IES &= ~BIT2; // interrupt lo/hi edge
	  P1IFG &= ~BIT2; // P1.2 IFG cleared just in case

	  P5DIR |= BIT0;

	  _EINT();
}

void main(void)
{
  volatile unsigned int i;
  volatile unsigned char x;
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P6DIR |= 0x01;
  initUart();
  init7021_n();
  init_txrx_interrupt();

  // // _BIS_SR(LPM0_bits + GIE);                 // Enter LPM3 w/ interrupt

  _EINT();
//   sending = 1;
   step = 10;
   __delay_cycles(1000000);

//   while(1) {
//	   for(i=0; i < 12;i++ ) {
//		  ascii(_message[i]);
//	   }
//   }

	while (1) {
	  if (sending == 1) {
		  UCTL0 &= ~CHAR;

		  InitI2C();

		  for(i=0; i < step-1;i++ ) {
			  x= EEPROM_ByteWrite(i, message[i]);
		 	  EEPROM_AckPolling();
		  }

		  for(i=0; i < step-1;i++ ) {
			  x = EEPROM_RandomRead(i);
			  ascii(x);
		  }
		  step=0;
		  sending=0;

		  //Re-Configuring the USART Module for UART or SPI Operation
		  UCTL0 &= ~I2C; //Clear I2C, SYNC, and I2CEN (CLR.B  &U0CTL)
		  UCTL0 &= ~SYNC;
		  UCTL0 &= ~I2CEN;

		  UCTL0 |= SWRST;                          // Set SWRST (MOV.B  #SWRST,&U0CTL)

		  initUart();
	  }
  }
}

#pragma vector=USART0RX_VECTOR
__interrupt void usart0_rx (void)
{

  while (!(IFG1 & UTXIFG0));                // USART1 TX buffer ready?
  TXBUF0 = RXBUF0;                          // RXBUF1 to TXBUF1
  message[step] = RXBUF0;

  _EINT();

  step++;
  if (RXBUF0 == 13)   // CR
  {
	  //P6OUT ^= 0x01;
	  sending = 1;
  }
}

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
	//P6OUT ^= BIT0; // Toggle LED at P6.0
	//P5OUT ^= BIT0; // Toggle LED at P5.0

	if(_message[m] & (1<<i)) {
		P5OUT |= BIT0;
	} else {
		P5OUT &= ~BIT0;
	}

	i--;

	if (i < 0){i = 7;m++;};
	if (m >= 12){m = 0; };

	P1IFG &= ~BIT2; // P1.2 IFG cleared
}

##### Transfer Frames Format

AX.25

할일

- Callsign 받기

##### I2C msp430 communication

master

led 6.0 button 6.1

#include  <msp430x16x.h>
void delay (void);
char TXData = 0;

void main (void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  P3SEL |= 0x0A;                            // Select I2C pins
  U0CTL |= I2C + SYNC;                      // Recommended init procedure
  U0CTL &= ~I2CEN;                          // Recommended init procedure
  I2CTCTL |= I2CSSEL1 + I2CTRX;             // SMCLK, transmit
  I2CNDAT = 0x03;                           // Write Three bytes
  I2CSA = 0x0048;                           // Slave Address is 048h
  U0CTL |= I2CEN;                           // Enable I2C

  U0CTL |= MST;                             // Master mode
  I2CTCTL |= I2CSTT + I2CSTP;               // Initiate transfer
  while ((I2CIFG & TXRDYIFG) == 0);         // Wait for transmitter to be ready
  I2CDRB = TXData;                          // Load  I2CDRB
  while ((I2CIFG & TXRDYIFG) == 0);         // Wait for transmitter to be ready
  I2CDRB = TXData;                          // Load  I2CDRB
  while ((I2CIFG & TXRDYIFG) == 0);         // Wait for transmitter to be ready

  while(1)
  {

	  if((P6IN & BIT1) == 0) { // LOW?
		  I2CDRB = 1;
		  P6OUT |= BIT0;
	  }
   }
}

slave

#include  <msp430x16x.h>

char RXData = 0;

void main (void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P6DIR |= BIT0;
  P6OUT &= ~BIT0;

  P3SEL |= 0x0A;                            // Select I2C pins
  U0CTL |= I2C + SYNC;                      // Recommended init procedure
  U0CTL &= ~I2CEN;                          // Recommended init procedure
  I2CTCTL |= I2CSSEL1;                      // SMCLK
  I2COA = 0x0048;                           // Own Address is 048h
  I2CIE = RXRDYIE;                          // Enable RXRDYIFG interrupt
  U0CTL |= I2CEN;                           // Enable I2C

  _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 w/ interrupt
  while(1){
	  if (RXData !=0)
		  P6OUT |= BIT0;
 	  else
		  P6OUT &= ~BIT0;
  }
}


// Common ISR for I2C Module
#pragma vector=USART0TX_VECTOR
__interrupt void I2C_ISR(void)
{
 switch( I2CIV )
 {
   case  2: break;                          // Arbitration lost
   case  4: break;                          // No Acknowledge
   case  6: break;                          // Own Address
   case  8: break;                          // Register Access Ready
   case 10:                                 // Receive Ready
      RXData = I2CDRB;                      // RX data
     _BIC_SR_IRQ(CPUOFF);                   // Clear LPM0
     break;
   case 12:  break;                         // Transmit Ready
   case 14: break;                          // General Call
   case 16: break;                          // Start Condition
 }
}

#### msp430 blink assembly

blink

;*******************************************************************************
;   MSP430x1xx Demo - Software Toggle P1.0
;
;   Description; Toggle P1.0 by xor'ing P0.1 inside of a software loop.
;   ACLK = n/a, MCLK = SMCLK = default DCO ~ 800k
;
;                MSP430x1xx
;             -----------------
;         /|\|              XIN|-
;          | |                 |
;          --|RST          XOUT|-
;            |                 |
;            |             P6.0|-->LED
;
;   M.Buccini
;   Texas Instruments, Inc
;   September 2004
;   Built with CCE for MSP430 Version: 1.00
;*******************************************************************************
            .cdecls C,LIST,"msp430x16x.h"  ; Include device header file

;-------------------------------------------------------------------------------
            .text                           ; Progam Start
;-------------------------------------------------------------------------------
RESET       mov.w   #300h,SP                ; Initialize 'x1121 stackpointer
StopWDT     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
SetupP1     bis.b   #001h,&P6DIR            ; P1.0 output
                                            ;
Mainloop    xor.b   #001h,&P6OUT            ; Toggle P6.0
Wait        mov.w   #050000,R15             ; Delay to R15
L1          dec.w   R15                     ; Decrement R15
            jnz     L1                      ; Delay over?
            jmp     Mainloop                ; Again
                                            ;
;-------------------------------------------------------------------------------
;           Interrupt Vectors
;-------------------------------------------------------------------------------
            .sect   ".reset"                ; MSP430 RESET Vector
            .short  RESET                   ;

            .end
</markdown>