hi,
i am trying with rc5 protocol with msp430g2553 for decoding Ir receive sequence.i have use gpio interrupt for IR output and timer for decoding the sequence.
but only one cmd is executing when i test by giving TACCR0 = 1778; value i have configured system for 1MHZ
when i try with different value for TACCR0 different cmds are executing
for example:
if TACCR0 =2450
1 and 9 command is working .
am not getting where i went wrong it seems k with the logic part can any one let me know with rc5 protocol fully.
i have gone through the document "slla 175"where they mentioned that 1.78ms for receiving each b it and 25 ms for 14 bit approximately. the code is given below
#include "msp430g2553.h"
#include "string.h"
//function prototype
void send_uart(char *data);
void send_uart1(char data);
#define IRDATA BIT4 // IR receiver on P1.4
#define RED BIT0 // Red LED on P1.0
#define T_INTERVAL 2450 // Timing between IRDATA samples - should be closer to 1778 with 1MHz clock, but mine runs fast. YMMV
int data = 0; // Hold the incoming IRDATA stream
int command = 0; // The command received
int address = 0; // The device address received
int toggle = 0; // The toggle bit from the IRDATA stream
int uiUartTransmitflag=0;
void main( void )
{
char chr[5];
//Initialization
WDTCTL = WDTPW + WDTHOLD; // Stop WDT , not used
//Calibrate DCO
BCSCTL1 = CALBC1_1MHZ; // DCO at 1 MHz
DCOCTL = CALDCO_1MHZ; // DCO at 1 MHz
BCSCTL2 &= ~SELS; // SMCLK source
// UART Set-Up
P1SEL |= 0x06; // Use P1.1 and P1.2 as USCI_A0
P1SEL2|= 0x06; // Use P1.1 and P1.2 as USCI_A0
P1DIR |= 0x04; // Set 1.2 as output
UCA0CTL1 |= UCSSEL_2; // Use SMCLK / DCO
UCA0BR0 = 104; // 1 MHz -> 9600 N=Clock/Baud
UCA0BR1 = 0; // 1 MHz -> 9600
UCA0MCTL = UCBRS1; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI
/*
* Set up the I/O pins
*/
// P1REN |= DEBUG_PIN ; // pullup resistor for timing debug pin
P1OUT |= RED ; // Set all these HIGH
P1DIR |= RED ; // Set all these as outputs
P1DIR &= ~IRDATA; // IRDATA is an input
P1IE = IRDATA; // enable interrupts, watching IRDATA for a change
P1IES = IRDATA; // watch for falling edge change on IRDATA
TACCR0 = T_INTERVAL; // Set the timing interval for TimerA
//General Interrupt Enable
_BIS_SR(GIE);
//Repeat this section
while(1)
{
// send_uart("Hello World\n\r");
// __delay_cycles(500000);
if(uiUartTransmitflag == 1){
uiUartTransmitflag=0;
chr[0]= ( char) command;
chr[1]= (char)address;
chr[2]= (char) toggle;
send_uart("Command,address,toggle\n\r");
send_uart1(chr[0]+0x30);
send_uart1(chr[1]+0x30);
send_uart1(chr[2]+0x30);
send_uart("\n\r");
// __delay_cycles(500000);
}
}
}
#pragma vector = PORT1_VECTOR;
void __interrupt Port_1(void)
{
P1IE &= ~IRDATA; // Turn off P1 interrupts while we work
P1IFG &= ~IRDATA; // clear the P1 interrupt flag for IRDATA
data = 1; // first start bit, inverted from receiver
//TODO: wait for second start bit within T_INTERVAL; abandon if it doesn't come.
// start timer
TACCTL0 |= CCIE; // enable timer interrupts
TACTL = TASSEL_2; // TimerA0 clock selection - SMCLK
TACCR0 &= ~CCIFG; // clear any pending timerA interrrupt flags
TACTL |= MC_1; // start the timer in UP mode
}
#pragma vector = TIMER0_A0_VECTOR
void __interrupt Timer0(void)
{
/*
* Need to track the state of a few things... the last toggle bit, the last command issued,
* the count of how many bits we have parsed.
*/
static int lastToggle;
static int lastCommand;
static char repeat = 0;
static int count = 0; // stop after all the bits have been read in
TACCTL0 &= ~CCIE; // clear the interrupt flag
if (count > 13) { // all bits read in and shifted into the data variable
TACTL &= MC_0; // stop the timer
TACTL |= TACLR; // clear the timer settings to zero it out
command = data & 0x3F;
address = (data >> 6) & 0x1F ;
toggle = (data >> 11) & 1;
P1IE |= IRDATA; // we have our IR command, reset and start listening for the next one
P1IFG &= ~IRDATA;
count = 0;
if (lastCommand == command && lastToggle == toggle) { // if we only want one toggle per keypress
repeat = 1;
// uiUartTransmitflag=1;
} else {
uiUartTransmitflag=1;
lastCommand = command;
lastToggle = toggle;
repeat = 0;
}
} else {
// read IRDATA and store the value in DATA
//P1OUT &= ~DEBUG_PIN; // uncomment this and the one a few lines down to see P1.3 toggle with each sample of IRDATA. Use a two channel oscilloscope to adjust T_INTERVAL as necessary.
if (data > 0) data <<= 1; // shift left one bit
if ((P1IN & IRDATA) != IRDATA) { // invert IRDATA if it is low, because the receiver is active low - append 'data' with a 1
data |= 1;
}
//P1OUT |= DEBUG_PIN; // as above, uncomment for timing debug use
count++;
TACCTL0 |= CCIE; // turn the timer interrupts back on for the next bit
}
}
void send_uart(char *data)
{
// P1OUT ^= BIT6; // Toggle LED
unsigned int i;
unsigned int size = strlen(data); //get length of data to be sent
for (i = 0; i < size; i++) {
while (!(IFG2 & UCA0TXIFG)); //Wait UART to finish before next send
UCA0TXBUF = data[i];
}
}
void send_uart1(char data)
{
while (!(IFG2 & UCA0TXIFG)); //Wait UART to finish before next send
UCA0TXBUF = data;
}
can any one let me know where i went wrong...
thanks & regards,