Hi, I'm on the way to develop the INFRARED EMITTER.
At the moment, I'm trying to use MSP430FR4133 board with given TI Libraries.
I have two questions;
1.given below code,
unsigned char send_data[8]={0xFF,0xFF,0xFF,0xFF,0x10,0xEF,0xEB,0x14}; Transmitting this data but receiving unknown data.
PLEASE Shear me solution.
2. This code required any library or driver?
#include "msp430.h"
unsigned char IR_code;
unsigned char IR_flag;
unsigned char IR_stop;
unsigned char byte_cnt;
unsigned int bit_sel;
unsigned char *send_addr;
unsigned char send_data[8]={0xFF,0xFF,0xFF,0xFF,0x10,0xEF,0xEB,0x14}; // Unsigned data will displayed
{
// Watchdog timer works as default setting
WDTCTL = WDTPW + WDTHOLD;
Init_GPIO();
Init_Clock();
IR_stop = 1; //disable IR emitter
while(1)
{
// clear the flag and counter
IR_flag = 0;
byte_cnt = 0;
bit_sel = 0;
if(IR_stop == 0)
{
// Configure IR output pin
P1SEL0|= BIT0; // use internal IR modulator
// disable Port1 & Port2 interrupt during IR emitting
P1IE = 0;
P2IE = 0;
// IR_code = scan_key(); // scan the keypad
// Configure IR modulation: ASK
SYSCFG1 = IRDSSEL + IREN;
TA1CCTL0 = CCIE;
TA1CCTL2 = OUTMOD_7; // output mode: reset/set
TA0CCTL2 = OUTMOD_7; // output mode: reset/set
// 38kHz 1/4 duty-cycle carrier waveform length setting
TA0CCR0 = 104;
TA0CCR2 = 25;
TA1CCR0 = 640; //the initial time of TA0 should be longer than TA1
TA1CCR2 = 320;
// set timer operation mode
TA0CTL = TASSEL_2 + MC_1 + TACLR; //SMCLK, UP mode
TA1CTL = TASSEL_2 + MC_1 + TACLR; //SMCLK, UP mode
// write button number into buffer
//send_data[2] = IR_code;
//send_data[3] = ~IR_code;
send_addr = &send_data[0];
/*while (1) {
if (buttonPressed) {
buttonPressed = 0;
if (!irDataValid) {
// start IR transmission
transmitCode(send_data);
}
}*/
// stop until the end of IR code
while(IR_stop == 0);
TA0CCTL0 = 0;
TA0CCTL2 = 0;
TA0CTL = 0;
TA0CCR0 = 0;
TA0CCR2 = 0; //disable timer0
TA1CCTL0 = 0;
TA1CCTL2 = 0;
TA1CTL = 0;
TA1CCR0 = 0;
TA1CCR2 = 0; //disable timer1
P1IE |= (BIT3 + BIT4 + BIT5); //enable GPIO interrupt
P2IE |= BIT7;
}
// __bis_SR_register(LPM3_bits | GIE); //enter low power mode
IR_stop = 0; // enable IR code emitting
}
}
//********Timer1 interrupt ISR*********//
#pragma vector = TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR (void)
{
switch( TA1IV )
{
case 0:
{
if(IR_flag)
{
IR_stop=1; // stop IR modulator
TA1CCTL0 &= ~CCIE; // disable timer_A0 interrupt
}
if((byte_cnt==0)&& (bit_sel==0)) // leading pulse burst of IR code
{
TA1CCR0 = 53999; // 9ms high
TA1CCR2 = 35999; // 4.5ms low
byte_cnt++; // byte counter
bit_sel++; // bit counter
}
else if((byte_cnt>= 5)&& (bit_sel==1)) // the end of IR code
{
TA1CCR0 = 2249; //0.562ms pulse burst to show the end
TA1CCR2 = 2249;
IR_flag=1;
}
else
{
if((*send_addr & bit_sel) == 0) // data "0"
{
TA1CCR0 = 4499; // 0.562ms high 0.562ms low
TA1CCR2 = 2249;
bit_sel<<=1;
}
else // data "1"
{
TA1CCR0 = 8999; // 0.562ms high 1.687ms low
TA1CCR2 = 2249;
bit_sel<<=1;
}
if(bit_sel>=256) // start a new byte
{
send_addr++;
byte_cnt++;
bit_sel=1;
}
}
break;
}
default: break;
}
}