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.

MSP430FG4618 UART communication using Timer_A

Other Parts Discussed in Thread: MSP430F2013

Hello everyone,

In the code below, the debug cursor is stuck on the line TX_Byte; it doesn't enter the function. Why so?

Krishna.

______________________________________________________________________________________________________________

 

#define RXD       0x02                      // RXD on P1.1
#define TXD       0x20                      // TXD on P1.5

//   Conditions for 2400 Baud SW UART, ACLK = 32768

#define Bitime_5  0x06                      // ~ 0.5 bit length + small adjustment
#define Bitime    0x0E                      // 427us bit length ~ 2341 baud

unsigned int RXTXData;
unsigned char BitCnt;

void TX_Byte (void);
void RX_Ready (void);

//  M. Buccini / L. Westlund
//  Texas Instruments Inc.
//  October 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A
//******************************************************************************

//#include  <msp430x20x3.h>
#include <intrinsics.h>
#include <msp430xG46x.h>



void main (void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  TACCTL0 = OUT;                              // TXD Idle as Mark
  TACTL = TASSEL_1 + MC_2;                  // ACLK, continuous mode
  P2SEL = TXD + RXD;                        //
  P2DIR = TXD;                              //

// Mainloop
  for (;;)
  {
       
  RX_Ready();                               // UART ready to RX one Byte
  _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3 w/ interr until char RXed
   TX_Byte();                           // TX Back RXed Byte Received
  }
}


// Function Transmits Character from RXTXData Buffer
void TX_Byte (void)
{
  BitCnt = 0xA;                             // Load Bit counter, 8data + ST/SPo
  //while (TAR != TACCR0);                       // Prevent async capture
  TACCR0 = TAR;                             // Current state of TA counter
  TACCR0 += Bitime;                           // Some time till first bit
  RXTXData |= 0x100;                        // Add mark stop bit to RXTXData
  RXTXData = RXTXData << 1;                 // Add space start bit
  TACCTL0 =  CCIS0 + OUTMOD0 + CCIE;          // TXD = mark = idle
  while ( TACCTL0 & CCIE );                   // Wait for TX completion
}


// Function Readies UART to Receive Character into RXTXData Buffer
void RX_Ready (void)
{
  BitCnt = 0x8;                             // Load Bit counter
  TACCTL0 = SCS + OUTMOD0 + CM1 + CAP + CCIE;   // Sync, Neg Edge, Cap
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
  TACCR0 += Bitime;                           // Add Offset to CCR0

// TX
  if (TACCTL0 & CCIS0)                        // TX on CCI0B?
  {
    if ( BitCnt == 0)
    TACCTL0 &= ~ CCIE;                        // All bits TXed, disable interrupt
    else
    {
      TACCTL0 |=  OUTMOD2;                    // TX Space
      if (RXTXData & 0x01)
      TACCTL0 &= ~ OUTMOD2;                   // TX Mark
      RXTXData = RXTXData >> 1;
      BitCnt --;
    }
  }
// RX
  else
  {
    if( TACCTL0 & CAP )                       // Capture mode = start bit edge
    {
    TACCTL0 &= ~ CAP;                         // Switch from capture to compare mode
    TACCR0 += Bitime_5;
    }
    else
    {
    RXTXData = RXTXData >> 1;
      if (TACCTL0 & SCCI)                     // Get bit waiting in receive latch
      RXTXData |= 0x80;
      BitCnt --;                            // All bits RXed?
      if ( BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      {
      TACCTL0 &= ~ CCIE;                      // All bits RXed, disable interrupt
      _BIC_SR_IRQ(LPM3_bits);               // Clear LPM3 bits from 0(SR)
      }
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    }
  }
}

 

  • Krishna Thallapaka said:
    In the code below, the debug cursor is stuck on the line TX_Byte; it doesn't enter the function. Why so?

    because it never executes this instruction.
    The debug cursor is placed on the instruciton to execute next. However, in this case, teh previous instruction has stopped the CPU, so the next instruction is not executed.

    The execution continues after any of the ISRs re-enables MCLK for the main thread. However, this doesn't seem to happen.

    It is an error to place a breakpoint immediately behind an instruction that enters LPM, whether the breakpoint is set explicitely or implicitely through single-stepping. If you need to do so, then put a _no_operation(); in between (and don't set a breakpoint on it or single-step to it)

     

  • Hi Krishna,

    The CPU is stopped there because the CPUOFF bit in the Status Register is set.  The instruction immediately before the stopping point is the cause if the CPUOFF bit being set.

    The CPU will wake up when there is an interrupt.  Execution in main( ) will continue only when the Interrupt Service Routine chooses to do _BIC_SR_IRQ to clear CPUOFF (via LPM3_bits).

    The only interrupt that is enabled is CCIE in TACCTL0, which is set up for capture mode, waiting for a falling edge on Timer A CCI0A.  However, Timer A CCI0A is available only on P1.0, and it looks like your code expects it to be on P2.1 with a comment mentioning P1.1.  There seems to be similar confusion over Timer A CCI0B, which is available only on P1.1.  Your code references P2.5 and P1.5.

    So you need to change the definitions for TXD and RXD and change P2SEL and P2DIR to P1.  And hopefully your actual electrical signals are connected to the right place (P1.0 and P1.1).

    Did you know that the FG4618 has two real UARTs?  They are a lot easier to handle and much more flexible than a Timer UART.

    Jeff

  • Hello everyone,

    How do I test UART communication on MSP430F2013/FG4618 experimenter's board using Timer_A.

     

    Krishna.

  • Hello everyone,

     

    In the above code, the timer_A is not causing any interrupt. Why so?

     

    Krishna.

  • Hi again Krishna,

    Krishna Thallapaka said:

    How do I test UART communication on MSP430F2013/FG4618 experimenter's board using Timer_A.

    That board has two MCUs.  Which one are you trying to test?  The F2013 or the FG4618?

    Jeff

  • Hi again Krishna,

    Krishna Thallapaka said:

    In the above code, the timer_A is not causing any interrupt. Why so?

    Let's assume you have the correct TX and RX signals connected to P1.0 and P1.1 of the FG4618.

    You need to change these lines:

    #define RXD       0x02                      // RXD on P1.1
    #define TXD       0x20                      // TXD on P1.5

    and these lines:

    P2SEL = TXD + RXD;                        //
    P2DIR = TXD;                              //

    Jeff

  • Hello Jeff,

    Would I not need both the chips to test UART communication? Because one would act as the TX'r and the other as RX'r.

     

    Krishna.

     

  • Krishna,

    Yes.  I didn't realize you were trying to get the two chips to communicate with each other.

    I think I can help you if you can tell me which F2013 pins are connected to which FG4618 pins.  For example, maybe F2013 pins P1.5 and P1.6 are connected to FG4618 pins P3.3 and P3.2 (respectively).

    Jeff

**Attention** This is a public forum