This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

UART UCA0RXIFG Flag never SET.

Other Parts Discussed in Thread: MSP430G2553

Hi, I am working with MSP430G2553 and the editor is CCS. I am currently trying to communicate via UART with my PC and using Putty terminal. All the necessary configurations have been made and I can sent chars to the putty. However, I can not receive what I type on putty. It seems like RX interrupt is not working while TX interrupt work perfectly fine. Why is that? I apperiate any help. Thanks.

#include <msp430g2553.h>
#include <string.h>
#include <stdio.h>
/*
 * main.c
 */

void uart_conf(void);
void clck_conf(void);
char byte_to_crc[20];
unsigned short crc;
unsigned int len;
unsigned int pos;
unsigned int i;
unsigned int request_indicator=0;
char received_frame[20];
char transmitted_frame[20];
unsigned int byte_count_to_receive;
unsigned int byte_count_to_transmit;
unsigned int received_byte_counter;
unsigned int transmitted_byte_counter;

char reg_add_hi;
char reg_add_lo;
char nop_hi;
char nop_lo;
char crc_hi;
char crc_lo;

unsigned short mod_rtu_crc(char*, int);    // generate crc
void read_holding_regs(char, char , unsigned short , unsigned short);   // reading holding regs function

void main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    clck_conf();
    uart_conf();
    read_holding_regs(0x00, 0x03, 0x0001, 0x0002);
	//IFG2 &= ~UCA0RXIFG;
	UC0IE |= UCA0TXIE | UCA0RXIE;
	__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ int until Byte RXed

	while(1);
	

}


void uart_conf(void){

	UCA0CTL1 |= UCSWRST;         //Reset USCI
	UCA0CTL0 &= ~UCSYNC;  // Clear UCSYNC for UART communication;
	P1SEL |= (BIT1 | BIT2);       // Select for spec. function directions UART TX and RX
	P1SEL2 |= (BIT1 | BIT2);
	UCA0CTL1 |= UCSSEL_2;       // BTCL = SMCLK
	UCA0BR0 = 0xFF;
	UCA0BR1 = 0x05;                       // F_16MHZ / 1666 ~= 9600 KHz  0x0682 = 1666
	UCA0MCTL = UCBRS_6;    // Set modulation for minimum error rate (see spec...) 9600 Kps UCBRSx = 6 UcBRFx = 0;
	UCA0CTL1 &= ~UCSWRST;          // Un Reset USCI
	//UC0IE |= (UCA0RXIE | UCA0TXIE);     // enable interrupts



}

void clck_conf(void){

	BCSCTL1 = CALBC1_16MHZ; // Set DCO 16 MHz
	DCOCTL = CALDCO_16MHZ;

}

void read_holding_regs(char slave_add, char function, unsigned short reg_add, unsigned short nop){
	byte_to_crc[0] = slave_add;
	byte_to_crc[1] = function;
	reg_add_hi = reg_add >> 8;
	reg_add_lo = reg_add & 0x00ff;
	byte_to_crc[2] = reg_add_hi;
	byte_to_crc[3] = reg_add_lo;
	nop_hi = nop >> 8;
	nop_lo = nop & 0x00ff;
	byte_to_crc[4] = nop_hi;
	byte_to_crc[5] = nop_lo;

	len = 6;

	mod_rtu_crc(byte_to_crc, len);
	crc_hi = crc >> 8;
	crc_lo = crc & 0x00ff;

	transmitted_frame[0] = byte_to_crc[0];
	transmitted_frame[1] = byte_to_crc[1];
	transmitted_frame[2] = byte_to_crc[2];
	transmitted_frame[3] = byte_to_crc[3];
	transmitted_frame[4] = byte_to_crc[4];
	transmitted_frame[5] = byte_to_crc[5];
	transmitted_frame[6] = crc_lo;
	transmitted_frame[7] = crc_hi;

	received_byte_counter = 0;
	byte_count_to_receive = len + (int)nop + 2;    // + 2 for CRC and + No of Points because 2x nop comes back as response
	byte_count_to_transmit = len + 2;
	// start serial transmit
	__delay_cycles(64000);   //  Wait for 4 ms


}

// Compute the MODBUS RTU CRC
unsigned short mod_rtu_crc(char* bytes, int len)
{
	crc = 0xFFFF;

  for(pos = 0; pos < len; pos++){
    crc ^= (unsigned short)bytes[pos];          // XOR byte into least sig. byte of crc

    for(i = 8; i != 0; i--){    // Loop over each bit
      if((crc & 0x0001) != 0){      // If the LSB is set
        crc >>= 1;                    // Shift right and XOR 0xA001
        crc ^= 0xA001;
      }
      else{                            // Else LSB is not set
        crc >>= 1;                    // Just shift right
      }
    }
  // Note, this number has low and high bytes swapped, so use it accordingly (or swap bytes)

}
return crc;
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{

	if(received_byte_counter != byte_count_to_receive-1){        //if receive is not over
		received_byte_counter++;
		received_frame[received_byte_counter]= UCA0RXBUF;
	}
	else{
		received_frame[received_byte_counter]= UCA0RXBUF;
		UC0IE &= ~UCA0RXIE;     // disable RX interrupts
	}

}


#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
	if(transmitted_byte_counter != byte_count_to_transmit-1){        //if transmit is not over
		transmitted_byte_counter++;
		UCA0TXBUF = transmitted_frame[transmitted_byte_counter];
	}
	else{
		UCA0TXBUF = transmitted_frame[transmitted_byte_counter];
		UC0IE &= ~UCA0TXIE;     // disable TX interrupts
		//__delay_cycles(64000);   //  Wait for 4 ms
	}
}

  • Istemihan,

    I have tested your program and the RX interrupt works.

    But it did not use your corrected baudrate settings. I answered in your other thread about the UCBR configuration, too:

    It seems as if your SMCLK is wrong. I now have UCBR set to 0x82 and 0x06. Your other values do not work on my LaunchPad.

    Dennis

**Attention** This is a public forum