Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Receive interrupt in UART in MSP430F2274

Status
Not open for further replies.

vinothmct

Member level 1
Joined
May 2, 2012
Messages
38
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,584
I tried to receive and transmit data using UART . I was able to transmit data but when i type characters on hyperterminal . It is not getting displayed . Can anyone tell me the problem in my code

#include "target.h"
extern void (*buttonIsr)(void);
void handleButtonPress(void);
int main( void )
{
clockinit();
uartinit();
buttonIsr = &handleButtonPress;
HAL_ENABLE_INTERRUPTS(); //Enable Interrupts
while (1)
{
toggleLed(0);
delayMs(1000);
}
}

void handleButtonPress(void)
{
toggleLed(1);
sendstring("\nLight Toggled");
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}

clock.c

//Initiate the clock
#include "target.h"
void (*buttonIsr)(void);
void (*debugConsoleIsr)(char);
void clockinit()
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
{
while(1); // Stop if calibration constants erased
}
BCSCTL1 = CALBC1_8MHZ; // Set DCO = 8MHz for MCLK
DCOCTL = CALDCO_8MHZ;
BCSCTL2 |= DIVS_1; //SMCLK = DCO/2 (4MHz)
BCSCTL3 |= LFXT1S_2; // Use VLO for ACLK
/*PORT 1:
1.0 LED 1
1.1 LED 2
1.2 Button - connects to GND when closed
1.3 Accelerometer Interrupt
1.4
1.5
1.6
1.7
*/
P1DIR = BIT0+BIT1;
P1OUT &= ~BIT2;
P1IE = BIT2; //Enable Button Interrupt
P1IES = BIT2; //Interrupt on high-to-low transition
P1REN = BIT2; //enable resistor for button
P1OUT = BIT2; //make resistor a PULL-UP
P1SEL = 0; //NOTE: default value is NOT 0!
P1IFG = 0;
}

//UART initiation function
void uartinit()
{
P3SEL = (BIT4+BIT5); //select pin and port3.4and5
//ME1|=UTXE0+URXE0;

UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 26; UCA0BR1 = 0;
UCA0MCTL = UCBRS_0 + +UCBRF_1 + UCOS16; // Modulation UCBRSx=1, over sampling
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE;// Enable USCI_A0 RX interrupt
//IE2_bit=UCA0RXIE
}

signed int toggleLed(unsigned char led)
{
if (led > 1)
return -1;
P1OUT ^= (1 << led);
return 0;
}

void delayMs(unsigned int ms)
{
unsigned int a, b;
for (a = ms; a > 0; a--) // outer loop takes 5 ck per round
for (b = TICKS_PER_MS; b > 0; b--) // inner loop takes 5 ck per round
asm("nop");
}

//send strings through UART
void sendstring( char *str)
{
int i=0;
for(i=0;i< strlen(str); i++)
{
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF=str;
//toggleLed(1);
}
}

#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
if (P1IFG & BIT2)
buttonIsr();

if (P1IFG & BIT3)
{
//accelerometerIsr();
// if (wakeupFlags & WAKEUP_AFTER_ACCELEROMETER)
//HAL_WAKEUP();
}
P1IFG = 0; // clear the interrupt
}

//Transmit UART

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top