Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

msp430g2553

$
0
0

Hi

am new to the msp430,and trying to receive a string and transmit the same,am not getting the output.can anyone tell me the what is the problem.This is my code

 
 
 unsigned char rcvdata,datareceived;
 unsigned char Rxbuff[5];
 unsigned int  Rxdatalen;
 unsigned int datalen;
 unsigned char databuf[5];
 unsigned char Rxtoutcnt;
 unsigned char compltflag=1;
 
 
void delay_ms(unsigned int cnt)
{
 volatile unsigned int i,j;
 
for(i=0;i<cnt;i++)
for(j=0;j<88;j++);
 
}
 
void init_serial(void)
{
 
   P1IN = 0X04;
   P1DIR = 0x08;
   P1OUT = 0x00;
  P1SEL = BIT1+BIT2;
P1SEL2= BIT1+BIT2;
UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 104;
UCA0BR1 = 0;
UCA0MCTL = UCBRS0;
UCA0CTL1 &=~ UCSWRST;
IE2 |= UCA0RXIE;
}
 
 
void init_timer (void)
{
   TACCTL0 = CCIE;
TACCR0 = 5225-1;
TACTL = TASSEL_2 + MC_1;
 
}
 
 
 
void main(void) 
{
    
WDTCTL = WDTPW + WDTHOLD;      // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
init_timer();
init_serial();
__bis_SR_register(GIE);
 
while(1)
{
if(datareceived == 1)
serialmsg();
}
}
 
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
 
   if (IFG2&UCA0RXIFG)
   {
rcvdata = UCA0RXBUF;
compltflag = 0;
Rxbuff[Rxdatalen]= rcvdata;
 
if(++Rxdatalen>=BUFSIZE)
Rxdatalen = 0;
 
datareceived = 0;
Rxtoutcnt = 0;
clearbit(P1OUT,3);
   }
}
 
unsigned char serialmsg(void)
{
setbit(P1OUT,3);
unsigned int j;
unsigned int cnt;
 
for(cnt=0;cnt<Rxdatalen;cnt++)
databuf[cnt]=Rxbuff[cnt];
 
datalen=Rxdatalen;
 
for(j=0;j<sizeof(databuf);j++)
{
UCA0TXBUF = databuf[j];
while(!(IFG2&UCA0TXIFG));
}
    delay_ms(10);
   
}
 
 
 
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
 
Rxtoutcnt = (Rxtoutcnt+1);
 
if(Rxtoutcnt==2)
{
if(compltflag == 0)
{
datareceived = 1;
Rxtoutcnt = 0;
compltflag = 1;
}
}
 
}
 

 

 

Thanks&Regards

 


Viewing all articles
Browse latest Browse all 2077

Trending Articles