I have tried the below code in MSP432P401R for IR transmission but it is not working.Actually this code is modified from the MSP430 IR code for IR booster pack.
-Can I have a IR booster pack for MSP432P401R. If I can then below code will work or not.If not please correct or provide me a code for it.
#include "msp.h"
/* DriverLib Includes */
#include "driverlib.h"
/* Standard Includes */
#include <stdint.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[4]={0x55, 0xaa, 0x00, 0xff};
#define EN_DECIMAL_PT 0x7F
#define DIS_DECIMAL_PT 0xFF
#define BEAT_FREQ 512
#define BUTDEB_LEN (BEAT_FREQ / 4)
#define MAX_STATE 9
#define STATE_LEN 4
// xmit - flag to start 38kHz IR LED modulation
// xmitstate - state machine for serial protocol
// currstate - currently selected digit [0-9]
// decimalmask - mask to set or clear decimal point
// butdeb - Button debounce counters
volatile int xmit=0, xmitstate=0, currstate=0, savestate=0,
decimalmask = DIS_DECIMAL_PT, butdeb[2] = {0,0};
// Seven segment bit fields. Active low. {[0-9] E(rror)}
unsigned const char digits[] = { 0x82, 0xBB, 0xA4, 0xA1, 0x99,
0xC1, 0xC0, 0xAB, 0x80, 0x89,
0xC4 };
/* Application Defines */
#define TIMER_PERIOD 0x2DC6
/* Timer_A UpMode Configuration Parameter */
const Timer_A_UpModeConfig upConfig =
{
TIMER_A_CLOCKSOURCE_ACLK, // ACLK Clock Source
TIMER_A_CLOCKSOURCE_DIVIDER_1, // ACLK/1 = 32.768khz
TIMER_PERIOD, // 5000 tick period
TIMER_A_TAIE_INTERRUPT_DISABLE, // Disable Timer interrupt
TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE , // Enable CCR0 interrupt
TIMER_A_DO_CLEAR // Clear value
};
int main(void) {
/* Stop watchdog timer */
MAP_WDT_A_holdTimer();
/* Configuring P1.0 as output */
MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
/* Configuring P5.0 as output */
MAP_GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN0);
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN0);
/* Starting and enabling ACLK (32kHz) */
MAP_CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ);
MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_4);
/* Configuring Timer_A0 for Up Mode */
MAP_Timer_A_configureUpMode(TIMER_A0_BASE, &upConfig);
/* Configuring Timer_A1 for Up Mode */
MAP_Timer_A_configureUpMode(TIMER_A1_BASE, &upConfig);
/* Enabling interrupts and starting the timer */
MAP_Interrupt_enableSleepOnIsrExit();
MAP_Interrupt_enableInterrupt(INT_TA1_0);
MAP_Timer_A_startCounter(TIMER_A1_BASE, TIMER_A_UP_MODE);
/* Enabling MASTER interrupts */
MAP_Interrupt_enableMaster();
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
P5SEL0|= BIT0; // use internal IR modulator
// disable Port5 & Port2 interrupt during IR emitting
P2IE = 0;
P5IE = 0;
// 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;
*/
// write button number into buffer
send_data[2] = IR_code;
send_data[3] = ~IR_code;
send_addr = &send_data[0];
// 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
P5IE |= (BIT3 + BIT4 + BIT5); //enable GPIO interrupt
P2IE |= BIT7;
}
MAP_PCM_gotoLPM0(); //enter low power mode
IR_stop = 0; // enable IR code emitting
}
}
//******************************************************************************
//
//This is the TIMERA interrupt vector service routine.
//
//******************************************************************************
void TA1_0_IRQHandler(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;
}
}