Hi,
I am using MSP430F148 controller. While using USART0 for communication, using serial interrupt, i am not able to receive data (can transmit though), but when i use it by simple polling, i am able to receive data. I am unable to understand, whether it is problem with some compiler settings regarding declaring it as interrupt or some thing wrong in my code. I use Code Composer essentials Compiler v3.1.please help me out. The sample code is mentioned below.
Sample code with simple polling for receiving and sending data:
void main (void)
{
UART0_Init();
while(1)
{
if((IFG1 & URXIFG0))
{
Char_In = RXBUF0;
if(Char_In == '$')
serial_send('A');
}
}
}
void UART0_Init(void)
{
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x03; // 32k/9600 - 3.41, 9600-8-N-1 baud rate
UBR10 = 0x00; //
UMCTL0 = 0x4A; // Modulation4A
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // Enable USART0 RX interrupt
}
void serial_send(unsigned char Char_Out)
{
while (!(IFG1 & UTXIFG0));
TXBUF0 = Char_Out;
}
While using interrupt based code, i used serial receive interrupt defined as below.
Sample code using serial receive interrupt:
void main (void)
{
UART0_Init();
while(1);
/*if((IFG1 & URXIFG0))
{
Char_In = RXBUF0;
if(Char_In == '$')
serial_send('A');
}*/
}
__interrupt void usart0_rx (void);
USART0RX_ISR(usart0_rx)
__interrupt void usart0_rx (void)
{
Char_In = RXBUF0;
if(Char_In == '$')
{
while (!(IFG1 & UTXIFG0));
TXBUF0 = 'A';
}
}