Hello,
My project consists of receiving a DMX512 signal and save it's data on an array. Basically, to check I'm receiving the right signal, an I/O pin will wait till the signal goes from high to low than will start the timer. If the timer reach 88 microsecond that's mean I received the right signal then I will change the pin to act as RXD and start saving the data after that on an array "At baud rate of 250K" and transmitting this array after that "at a baud rate of 9.6K". However, if the signal goes high at any time before the timer ends, it will clear the timer and wait the signal to go low again.
Here is my code, but I can't get it to work. Any idea where may I went wrong?
#include "msp430g2553.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_16MHZ; // Set DCO
DCOCTL = CALDCO_16MHZ;
char data[10];
int x=0;
for (;;)
{
P1IN = BIT1;
P1OUT = 0;
P1DIR = BIT6 + BIT0;
P1IES |= 0x02; // interrupt on falling edge (start bit is high -> low)
P1IFG = 0; // clear interrupt flags before enabling
P1IE = BIT1; // enable P1 interrupt on BIT1
x=0;
//if((P1IN & BIT1))
if(P1IFG) // When P1 go from High to Low
{
TACCR0 = 1408 - 1;
TACTL = TASSEL_2 + ID_3 + MC_1 + TACLR; // SMCLK, div 8, up mode,
P1IES &= ~0x02;
P1IFG = 0;
P1IE = BIT1; // enable P1 interrupt on BIT1
while (x==0) // Timer is counting
{
if (P1IFG) // When P1 go from Low to High
{
P1OUT ^= BIT0;
TACTL |= MC_0; // stop timer
P1IFG =0; // clear interrupt flag
x=1;
}
else if (TAIFG) // If timer flag is set
{
P1IE &= ~BIT1; // disable further interrupts until Rx done
UCA0BR0 = 0x40; // 8MHz 250000
UCA0BR1 = 0; // 8MHz 250000
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
for(x=0;x<10;x++){
data[x] = UCA0RXBUF;
_delay_cycles(50);
}
UCA0BR0 = 0x82; // 16MHz 9600
UCA0BR1 = 0x6; // 16MHz 9600
for(x=0;x<10;x++)
{
while (!(IFG2&UCA0TXIFG));
UCA0TXBUF = data[x];
_delay_cycles(50);
}
UCA0RXBUF = 0;
x=1;
}
}
_delay_cycles(100000);
P1SEL &= ~BIT1 + ~BIT2 ; // Not P1.1 = RXD, P1.2=TXD
P1SEL2 &= ~BIT1 + ~BIT2 ; // Not P1.1 = RXD, P1.2=TXD
}
}
}