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.

CCS/MSP430G2553: Read Serial Communication without interrupts

Part Number: MSP430G2553

Tool/software: Code Composer Studio

Hi Everybody,

In the bottom I have the code which sends "Hello World\r\n" each time i'm sending the character a

It works good, but i need to read the buffer without the interrupt help i paste the USCI0RX_ISR part inside  the while loop and disable UCA0RXIE but it's not working at all

any help will be great

Thank you all

this is the code:

#include "msp430g2553.h"
#define TXLED BIT0
#define RXLED BIT6
#define TXD BIT2
#define RXD BIT1
const char string[] = { "Hello World\r\n" };
unsigned int i; //Counter

int main(void)
{
   WDTCTL = WDTPW + WDTHOLD; // Stop WDT
   DCOCTL = 0; // Select lowest DCOx and MODx settings<
   BCSCTL1 = CALBC1_1MHZ; // Set DCO
   DCOCTL = CALDCO_1MHZ;
   P2DIR = 0xFF; // All P2.x outputs<
   P2OUT &= 0x00; // All P2.x reset
   P1SEL |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD
   P1SEL2 |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD
   P1DIR |= RXLED + TXLED;
   P1OUT &= 0x00;
   UCA0CTL1 |= UCSSEL_2; // SMCLK
   UCA0BR0 = 0x68; // 1MHz 9600
   UCA0BR1 = 0x00; // 1MHz 9600
   UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5
   UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
   UC0IE |= UCA0RXIE; // Enable USCI_A0 RX interrupt
   __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ int until Byte RXed
     while (1)
     { }
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
   P1OUT |= RXLED;
   if (UCA0RXBUF == 'a') // 'u' received?
   {
      i = 0;
      UC0IE |= UCA0TXIE; // Enable USCI_A0 TX interrupt
      UCA0TXBUF = string[i++];
   }
   P1OUT &= ~RXLED;
}

#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
   P1OUT |= TXLED;
   UCA0TXBUF = string[i++]; // TX next character
   if (i == sizeof string - 1) // TX over?
      UC0IE &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt
   P1OUT &= ~TXLED;
}

  • Hi Joe,

    You have to poll the RX IFG in a while loop to make sure that the buffer is populated before attempting to read from it, several examples of this are provided by the online community.

    Regards,
    Ryan
  • Not sure why you would want to, but you could still keep the RX ISR but use it to wake up main loop

     while (1) {
    __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ int until RX ISR wakeup.
     ...most of the old RX ISR code goes here
    }
    
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    {
    if (UCA0RXBUF == 'a')
      __bic_SR_register_on_exit(LPM0_bits);
    }
  • Thank you for the reply
    I need to do this becuase i have an external adc which works perfet without any interrupt but if i add an interrupt that delay a second after a while the external adc sends me wrong data i tried all kind of things but nothing seems to work, so i'm trying not to use interrupts in my project
  • ... but if i add an interrupt that delay a second after a while the external adc sends me wrong data ...

    That's incorrect. It is not the interrupt, but the things you do inside the interrupt routine.

    I suspect you tried to send characters from within the ADC interrupt routine, probably with polling. Are you aware how long it takes to send a character ?

    BTW, your post are awful to read. Better avoid unnecessary long chain-sentences ...

  • I'll take what you said under consideration.
    in the interrupt i only activate a led

    I think the interrupt are get me out of sync with external ADC
  • An ADC conversion takes some time (usually several microseconds), so there is room for some "stuff" to do. You only need to finish before the next value is ready.

    For two (or more) interrupt sources, you need to calculate for the worst case. In a stable design, the combined runtime of all interrupts is less than the highest interrupt frequency.

    While it's sometimes a bit more difficult, try to move code/functionality from the interrupt to the main loop, and use flag values for signalizing/synchronizing.

    It's O.K. to go on with your "interruptless" design, but it will waste considerable amount of MCU time. You can always add improvements later, but some early design decisions (like this) will restrict you.

**Attention** This is a public forum