Jump to content
43oh

General Purpose I/O control over serial?


Recommended Posts

Hi Everyone,

I just received my TI LaunchPAd kit and have been searching for a general purpose IO program for it to speed up my hardware development (via a PC) before I dive into specific MSP code.

 

I was hoping there might already be something out there that allows simple serial terminal control of the MSP430G2231 as if it were an "instrument". The TI example program "msp430g2xx1_ta_uart9600.c Timer_A, Ultra-Low Pwr Full-duplex UART 9600, 32kHz ACLK" is a start but only allows for setting of 8 digital output pins and the setting is done at the byte level so a bit of a pain compared to working at a terminal with "English" commands.

 

An ideal program (IMO) would be

  • compatible with keyboard commands from 9600 baud terminal software (e.g Putty) i.e. simple ASCII readable commands and responses, terminated with character strings, optional echo.
    Allow setting of individual pins as digital input, digital output , pwm output, or analog input
    Allow setting and reading of individual pin values
    Reading of internal temperature

 

the command set could be something like:

S[x],[i/o/p/a] set pin "x" as "i" input, "o" output, "p" pwm output , "a" analog input

R[x] read pin "x" , returns "err" if (previously) set as an output, otherwise returns "1" or "0" if set as a digital input or value "0" to "1024" if an analog input

W[x],[0-1024] write pin "x" the value 0-1024 . 0 or 1 allowable for digital outputs, 0-1024 allowable for PWM output. Return "err" if out of range or pin previously configured as digital or analog input.

T[C/F] get temperature in degrees "C" or "F" to 1 decimal place eg. "23.5"

 

The aim is to avoid writing PC software to manage bits /byte formatting and specific MSP code when trying to prototype/debug (slow) hardware when commands from a terminal program would seem the most appropriate way to develop an idea quickly.

Link to post
Share on other sites

the closest thing i can think of is joby's launchpad spi explorer.

 

http://blog.hodgepig.org/2010/09/10/575/

 

it's kind of pc side uart driving the launchpad to do spi control on other devices connecting to the launchpad in a spi bus.

 

it's an interactive shell where you issue commands via a terminal program and have specific syntax similar to bus pirate, etc.

 

the codes are very well organized and it's easy to re-purpose it as the the command parsing is inside parse.c and parse.h.

Link to post
Share on other sites
the closest thing i can think of is joby's launchpad spi explorer.

 

http://blog.hodgepig.org/2010/09/10/575/

 

it's kind of pc side uart driving the launchpad to do spi control on other devices connecting to the launchpad in a spi bus.

 

it's an interactive shell where you issue commands via a terminal program and have specific syntax similar to bus pirate, etc.

 

the codes are very well organized and it's easy to re-purpose it as the the command parsing is inside parse.c and parse.h.

 

Thank you. It would take some time to pour over the code and understand the syntax. For my immediate needs I re purposed the example 9600 baud UART code. Using the 2 LEDS P1.0 and P1.6 as outputs and the other lines as digital inputs.

 

However "grafting" the temperature sensor code for the example fails, I no longer get working serial communications.

The other (minor) issue is i couldn't set P1.3 to pull down, so I set all other pins to pull up for simplicity.

 

I guess I can carry on wishing for a well documented + simple function library /frame work for simple pin reading/writing. I'm not interested in going to low power mode, or omtimising the very last byte of code size- I rather have a quicker firmware development so I can tackle the other hardware and software.

 

My (horrible code) is:

//******************************************************************************
//  MSP430G2xx1 Demo - Timer_A, Ultra-Low Pwr UART 9600 Echo, 32kHz ACLK
//
//  Description: Use Timer_A CCR0 hardware output modes and SCCI data latch
//  to implement UART function @ 9600 baud. Software does not directly read and
//  write to RX and TX pins, instead proper use of output modes and SCCI data
//  latch are demonstrated. Use of these hardware features eliminates ISR
//  latency effects as hardware insures that output and input bit latching and
//  timing are perfectly synchronised with Timer_A regardless of other
//  software activity. In the Mainloop the UART function readies the UART to
//  receive one character and waits in LPM3 with all activity interrupt driven.
//  After a character has been received, the UART receive function forces exit
//  from LPM3 in the Mainloop which configures the port pins (P1 & P2) based
//  on the value of the received byte (i.e., if BIT0 is set, turn on P1.0).

//  ACLK = TACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO
//  //* An external watch crystal is required on XIN XOUT for ACLK *//  
//
//               MSP430G2xx1
//            -----------------
//        /|\|              XIN|-
//         | |                 | 32kHz
//         --|RST          XOUT|-
//           |                 |
//           |   CCI0B/TXD/P1.1|-------->
//           |                 | 9600 8N1
//           |   CCI0A/RXD/P1.2|<--------
//
//  D. Dang
//  Texas Instruments Inc.
//  October 2010
//  Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
// Modified Peter R.H. 12/30/2010 onwards

#include "msp430g2231.h"


//------------------------------------------------------------------------------
// Hardware-related definitions
//------------------------------------------------------------------------------
#define UART_TXD   0x02                     // TXD on P1.1 (Timer0_A.OUT0)
#define UART_RXD   0x04                     // RXD on P1.2 (Timer0_A.CCI1A)

//------------------------------------------------------------------------------
// Conditions for 9600 Baud SW UART, SMCLK = 1MHz
//------------------------------------------------------------------------------
#define UART_TBIT_DIV_2     (1000000 / (9600 * 2))
#define UART_TBIT           (1000000 / 9600)

//------------------------------------------------------------------------------
// Global variables used for full-duplex UART communication
//------------------------------------------------------------------------------
unsigned int txData;                        // UART internal variable for TX
unsigned char rxBuffer;                     // Received UART character

//------------------------------------------------------------------------------
// Function prototypes
//------------------------------------------------------------------------------
void TimerA_UART_init(void);
void TimerA_UART_tx(unsigned char byte);
void TimerA_UART_print(char *string);
//void ConfigureAdcTempSensor(void);

//  vars

long temp;
long IntDegF;
long IntDegC;

unsigned int TXByte;


//------------------------------------------------------------------------------
// main()
//------------------------------------------------------------------------------
void main(void)
{

// this does not work 
// temp reading setup
//  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
//  ADC10CTL1 = INCH_10 + ADC10DIV_3;         // Temp Sensor ADC10CLK/4
//  ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;
//  __enable_interrupt();                     // Enable interrupts.
//  TACCR0 = 30;                              // Delay to allow Ref to settle
//  TACCTL0 |= CCIE;                          // Compare-mode interrupt.
//  TACTL = TASSEL_2 | MC_1;                  // TACLK = SMCLK, Up mode.
//  LPM0;                                     // Wait for delay.
//  TACCTL0 &= ~CCIE;                         // Disable timer Interrupt
//  __disable_interrupt();
// end fo temp


   WDTCTL = WDTPW + WDTHOLD;               // Stop watchdog timer

   DCOCTL = 0x00;                          // Set DCOCLK to 1MHz
   BCSCTL1 = CALBC1_1MHZ;
   DCOCTL = CALDCO_1MHZ;

   P1OUT = 0x00;                           // Initialize all GPIO

   P1SEL = UART_TXD + UART_RXD;            // Timer function for TXD/RXD pins
   // Set all pins but RXD, P1.3, P1.4, P1.5, P1.7 to output
   P1DIR = 0xFF & ~UART_RXD & ~0x08 & ~0x10 & ~0x20 & ~0x80; 

   //unable to set P1.3 to pull low so set all the others to pull up  (!)
   P1IN |= BIT4; //enables input
   P1REN |= BIT4; // enables resistor
   P1OUT |= BIT4; //resistor set to pull up

   P1IN |= BIT5; //enables input
   P1REN |= BIT5; // enables resistor 
   P1OUT |= BIT5; //resistor set to pull up

   P1IN |= BIT7; //enables input
   P1REN |= BIT7; // enables resistor
   P1OUT |= BIT7; //resistor set to pull up

   P2OUT = 0x00;
   P2SEL = 0x00;
   P2DIR = 0xFF;

   __enable_interrupt();


   TimerA_UART_init();                     // Start Timer_A UART
   TimerA_UART_print("\r\r\rREADY.\r\n");

   for (;
   {


       // Wait for incoming character
       __bis_SR_register(LPM0_bits);

       // Echo received character
       TimerA_UART_tx(rxBuffer);

       // Update board outputs according to received byte
       if (rxBuffer == '1') P1OUT |= 0x01;
       if (rxBuffer == '!') P1OUT &= ~0x01;
       if (rxBuffer == '6') P1OUT |= 0x40;
       if (rxBuffer == '^') P1OUT &= ~0x40;

       if (rxBuffer == 't') 
       {


       	ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
           __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled

       	// oF = ((A10/1024)*1500mV)-923mV)*1/1.97mV = A10*761/1024 - 468
   		temp = ADC10MEM;
   		IntDegF = ((temp - 630) * 761) / 1024;
   		// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
   		temp = ADC10MEM;

   		IntDegC = ((temp - 673) * 423) / 1024;
       	TXByte = (unsigned char)(IntDegC);
       	TimerA_UART_tx(TXByte);
       	TXByte = (unsigned char)(',');
       	TimerA_UART_tx(TXByte);
       	TXByte = (unsigned char)(IntDegF);
       	TimerA_UART_tx(TXByte);
       }

       if (rxBuffer == 'r')  
       {
       	TimerA_UART_tx(';');

       	 if ((8 & P1IN)) TimerA_UART_tx('1');       // if P1.3 set
   		 else TimerA_UART_tx('0');

   		 if ((16 & P1IN)) TimerA_UART_tx('1');      // if P1.4 set
   		 else TimerA_UART_tx('0');

       	 if ((32 & P1IN)) TimerA_UART_tx('1');      // if P1.5 set
   		 else TimerA_UART_tx('0');

       	 if ((128 & P1IN)) TimerA_UART_tx('1');     // if P1.6 set
   		 else TimerA_UART_tx('0');

       	TimerA_UART_tx('.');
       }

   }
}
//------------------------------------------------------------------------------
// Function configures Timer_A for full-duplex UART operation
//------------------------------------------------------------------------------
void TimerA_UART_init(void)
{
   TACCTL0 = OUT;                          // Set TXD Idle as Mark = '1'
   TACCTL1 = SCS + CM1 + CAP + CCIE;       // Sync, Neg Edge, Capture, Int
   TACTL = TASSEL_2 + MC_2;                // SMCLK, start in continuous mode
}
//------------------------------------------------------------------------------
// Outputs one byte using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_tx(unsigned char byte)
{
   while (TACCTL0 & CCIE);                 // Ensure last char got TX'd
   TACCR0 = TAR;                           // Current state of TA counter
   TACCR0 += UART_TBIT;                    // One bit time till first bit
   TACCTL0 = OUTMOD0 + CCIE;               // Set TXD on EQU0, Int
   txData = byte;                          // Load global variable
   txData |= 0x100;                        // Add mark stop bit to TXData
   txData <<= 1;                           // Add space start bit
}

//------------------------------------------------------------------------------
// Prints a string over using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_print(char *string)
{
   while (*string) {
       TimerA_UART_tx(*string++);
   }
}
//------------------------------------------------------------------------------
// Timer_A UART - Transmit Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A0_ISR(void)
{
   static unsigned char txBitCnt = 10;

   TACCR0 += UART_TBIT;                    // Add Offset to CCRx
   if (txBitCnt == 0) {                    // All bits TXed?
       TACCTL0 &= ~CCIE;                   // All bits TXed, disable interrupt
       txBitCnt = 10;                      // Re-load bit counter
   }
   else {
       if (txData & 0x01) {
         TACCTL0 &= ~OUTMOD2;              // TX Mark '1'
       }
       else {
         TACCTL0 |= OUTMOD2;               // TX Space '0'
       }
       txData >>= 1;
       txBitCnt--;
   }
}      
//------------------------------------------------------------------------------
// Timer_A UART - Receive Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = TIMERA1_VECTOR
__interrupt void Timer_A1_ISR(void)
{
   static unsigned char rxBitCnt = 8;
   static unsigned char rxData = 0;

   switch (__even_in_range(TAIV, TAIV_TAIFG)) { // Use calculated branching
       case TAIV_TACCR1:                        // TACCR1 CCIFG - UART RX
           TACCR1 += UART_TBIT;                 // Add Offset to CCRx
           if (TACCTL1 & CAP) {                 // Capture mode = start bit edge
               TACCTL1 &= ~CAP;                 // Switch capture to compare mode
               TACCR1 += UART_TBIT_DIV_2;       // Point CCRx to middle of D0
           }
           else {
               rxData >>= 1;
               if (TACCTL1 & SCCI) {            // Get bit waiting in receive latch
                   rxData |= 0x80;
               }
               rxBitCnt--;
               if (rxBitCnt == 0) {             // All bits RXed?
                   rxBuffer = rxData;           // Store in global variable
                   rxBitCnt = 8;                // Re-load bit counter
                   TACCTL1 |= CAP;              // Switch compare to capture mode
                   __bic_SR_register_on_exit(LPM0_bits);  // Clear LPM0 bits from 0(SR)
               }
           }
           break;
   }
}
//------------------------------------------------------------------------------

//this does not work
// ADC10 interrupt service routine
//#pragma vector=ADC10_VECTOR
//__interrupt void ADC10_ISR (void)
//{
//  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
//}

//#pragma vector=TIMERA0_VECTOR
//__interrupt void ta0_isr(void)
//{
//  TACTL = 0;
//  LPM0_EXIT;                                // Exit LPM0 on return
//}


Link to post
Share on other sites

for the temperature read setup, u are using timer compare 0 interrupt both for uart and "delay to allow ref to settle", u can't have both easily (except u can relocate the interrupt handler at run-time)

 

the LPM0 will sleep forever w/o wake-up as the uart timer handler does not turn off any sleep mode

 

 

an easy way out is to turn the "Ref delay" into a wait-for and not use interrupt. and i think u don't need the delay anyway as u only read temperature upon a 't' command from host.

 

...

__enable_interrupt(); // Enable interrupts.

TACCR0 = 30; // Delay to allow Ref to settle

TACCTL0 |= CCIE; // Compare-mode interrupt.

TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode.

LPM0; // Wait for delay.

TACCTL0 &= ~CCIE; // Disable timer Interrupt

__disable_interrupt();

...

 

can be changed to

 

TACTL = TASSEL_2 | MC_1;

while (TAR < 30);

Link to post
Share on other sites

 

TACTL = TASSEL_2 | MC_1;

while (TAR < 30);

I put those lines (anywhere) in my code and serial comms either doesn't work, or stops after a few chars. Am I missing something?

What would be a compete code block to get the temperature ADC reading (including any delay needed to settle) either in the "t" section or the main loop? thank you.

Link to post
Share on other sites

sorry nemi,

 

i don't have a launchpad w/ me and did not tried out.

it should be

 

TACTL = TASSEL_2 | MC_2;

while (TAR < 30);

 

MC_1 is up mode and requires CCR0 set, use MC_2 for continuous mode.

 

 

and actually i think u can skip the whole block safely, as the delay is for power-up settlement to get a good voltage reference (for temperature adc channel). when u receive a 't' command i am sure the internal voltage reference is settled well.

 

u do need to un-comment your adc read interrupt handler though

 

#pragma vector=ADC10_VECTOR

__interrupt void ADC10_ISR (void)

{

<<<<< this handler will be called when adc finishes conversion, we just wakes up CPU to continue.

__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)

}

 

 

and u don't need to wait for ref to settle on each read, it is needed only after your initial setup.

the adc reading mechanism looks ok

 

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled

>>>> the ADC10_ISR() interrupt handlder will be called after adc conversion is completed and

>>>> inside the ISR there is a line to wake u up and u resume here and continue the next statement,

>>>> which is a read from ADC10MEM register.

// oF = ((A10/1024)*1500mV)-923mV)*1/1.97mV = A10*761/1024 - 468

temp = ADC10MEM;

Link to post
Share on other sites

Well it doesn't crash, but the 't' command retuns nothing until another character is sent from the PC, and it always repsonds with the same values even if i warm the chip. Very confusing...

 

 

//******************************************************************************
//  MSP430G2xx1 Demo - Timer_A, Ultra-Low Pwr UART 9600 Echo, 32kHz ACLK
//
//  Description: Use Timer_A CCR0 hardware output modes and SCCI data latch
//  to implement UART function @ 9600 baud. Software does not directly read and
//  write to RX and TX pins, instead proper use of output modes and SCCI data
//  latch are demonstrated. Use of these hardware features eliminates ISR
//  latency effects as hardware insures that output and input bit latching and
//  timing are perfectly synchronised with Timer_A regardless of other
//  software activity. In the Mainloop the UART function readies the UART to
//  receive one character and waits in LPM3 with all activity interrupt driven.
//  After a character has been received, the UART receive function forces exit
//  from LPM3 in the Mainloop which configures the port pins (P1 & P2) based
//  on the value of the received byte (i.e., if BIT0 is set, turn on P1.0).

//  ACLK = TACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO
//  //* An external watch crystal is required on XIN XOUT for ACLK *//  
//
//               MSP430G2xx1
//            -----------------
//        /|\|              XIN|-
//         | |                 | 32kHz
//         --|RST          XOUT|-
//           |                 |
//           |   CCI0B/TXD/P1.1|-------->
//           |                 | 9600 8N1
//           |   CCI0A/RXD/P1.2|<--------
//
//  D. Dang
//  Texas Instruments Inc.
//  October 2010
//  Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
// Modified Peter R.H. 12/30/2010 onwards

#include "msp430g2231.h"


//------------------------------------------------------------------------------
// Hardware-related definitions
//------------------------------------------------------------------------------
#define UART_TXD   0x02                     // TXD on P1.1 (Timer0_A.OUT0)
#define UART_RXD   0x04                     // RXD on P1.2 (Timer0_A.CCI1A)

//------------------------------------------------------------------------------
// Conditions for 9600 Baud SW UART, SMCLK = 1MHz
//------------------------------------------------------------------------------
#define UART_TBIT_DIV_2     (1000000 / (9600 * 2))
#define UART_TBIT           (1000000 / 9600)

//------------------------------------------------------------------------------
// Global variables used for full-duplex UART communication
//------------------------------------------------------------------------------
unsigned int txData;                        // UART internal variable for TX
unsigned char rxBuffer;                     // Received UART character

//------------------------------------------------------------------------------
// Function prototypes
//------------------------------------------------------------------------------
void TimerA_UART_init(void);
void TimerA_UART_tx(unsigned char byte);
void TimerA_UART_print(char *string);
//void ConfigureAdcTempSensor(void);

//  vars

long temp;
long IntDegF;
long IntDegC;

unsigned int TXByte;


//------------------------------------------------------------------------------
// main()
//------------------------------------------------------------------------------
void main(void)
{

   WDTCTL = WDTPW + WDTHOLD;               // Stop watchdog timer

   //for temperature reading
   TACTL = TASSEL_2 | MC_2;
   while (TAR < 30);
   // ---

   DCOCTL = 0x00;                          // Set DCOCLK to 1MHz
   BCSCTL1 = CALBC1_1MHZ;
   DCOCTL = CALDCO_1MHZ;

   P1OUT = 0x00;                           // Initialize all GPIO

   P1SEL = UART_TXD + UART_RXD;            // Timer function for TXD/RXD pins
   // Set all pins but RXD, P1.3, P1.4, P1.5, P1.7 to output
   P1DIR = 0xFF & ~UART_RXD & ~0x08 & ~0x10 & ~0x20 & ~0x80; 

   //unable to set P1.3 to pull low so set all the others to pull up  (!)
   P1IN |= BIT4; //enables input
   P1REN |= BIT4; // enables resistor
   P1OUT |= BIT4; //resistor set to pull up

   P1IN |= BIT5; //enables input
   P1REN |= BIT5; // enables resistor 
   P1OUT |= BIT5; //resistor set to pull up

   P1IN |= BIT7; //enables input
   P1REN |= BIT7; // enables resistor
   P1OUT |= BIT7; //resistor set to pull up

   P2OUT = 0x00;
   P2SEL = 0x00;
   P2DIR = 0xFF;

   __enable_interrupt();


   TimerA_UART_init();                     // Start Timer_A UART
   TimerA_UART_print("\r\r\rREADY.\r\n");

   for (;
   {


       // Wait for incoming character
       __bis_SR_register(LPM0_bits);

       // Echo received character
       TimerA_UART_tx(rxBuffer);

       // Update board outputs according to received byte
       if (rxBuffer == '1') P1OUT |= 0x01;
       if (rxBuffer == '!') P1OUT &= ~0x01;
       if (rxBuffer == '6') P1OUT |= 0x40;
       if (rxBuffer == '^') P1OUT &= ~0x40;

       if (rxBuffer == 't') 
       {

	ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
       __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
   	temp = ADC10MEM;
       	// oF = ((A10/1024)*1500mV)-923mV)*1/1.97mV = A10*761/1024 - 468
   		IntDegF = ((temp - 630) * 761) / 1024;
   		// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
   		IntDegC = ((temp - 673) * 423) / 1024;

       	TXByte = (unsigned char)(IntDegC);
       	TimerA_UART_tx(TXByte);
       	TXByte = (unsigned char)(',');
       	TimerA_UART_tx(TXByte);
       	TXByte = (unsigned char)(IntDegF);
       	TimerA_UART_tx(TXByte);
       }

       if (rxBuffer == 'r')  
       {
       	TimerA_UART_tx(';');

       	 if ((8 & P1IN)) TimerA_UART_tx('1');       // if P1.3 set
   		 else TimerA_UART_tx('0');

   		 if ((16 & P1IN)) TimerA_UART_tx('1');      // if P1.4 set
   		 else TimerA_UART_tx('0');

       	 if ((32 & P1IN)) TimerA_UART_tx('1');      // if P1.5 set
   		 else TimerA_UART_tx('0');

       	 if ((128 & P1IN)) TimerA_UART_tx('1');     // if P1.6 set
   		 else TimerA_UART_tx('0');

       	TimerA_UART_tx('.');
       }

   }
}
//------------------------------------------------------------------------------
// Function configures Timer_A for full-duplex UART operation
//------------------------------------------------------------------------------
void TimerA_UART_init(void)
{
   TACCTL0 = OUT;                          // Set TXD Idle as Mark = '1'
   TACCTL1 = SCS + CM1 + CAP + CCIE;       // Sync, Neg Edge, Capture, Int
   TACTL = TASSEL_2 + MC_2;                // SMCLK, start in continuous mode
}
//------------------------------------------------------------------------------
// Outputs one byte using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_tx(unsigned char byte)
{
   while (TACCTL0 & CCIE);                 // Ensure last char got TX'd
   TACCR0 = TAR;                           // Current state of TA counter
   TACCR0 += UART_TBIT;                    // One bit time till first bit
   TACCTL0 = OUTMOD0 + CCIE;               // Set TXD on EQU0, Int
   txData = byte;                          // Load global variable
   txData |= 0x100;                        // Add mark stop bit to TXData
   txData <<= 1;                           // Add space start bit
}

//------------------------------------------------------------------------------
// Prints a string over using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_print(char *string)
{
   while (*string) {
       TimerA_UART_tx(*string++);
   }
}
//------------------------------------------------------------------------------
// Timer_A UART - Transmit Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A0_ISR(void)
{
   static unsigned char txBitCnt = 10;

   TACCR0 += UART_TBIT;                    // Add Offset to CCRx
   if (txBitCnt == 0) {                    // All bits TXed?
       TACCTL0 &= ~CCIE;                   // All bits TXed, disable interrupt
       txBitCnt = 10;                      // Re-load bit counter
   }
   else {
       if (txData & 0x01) {
         TACCTL0 &= ~OUTMOD2;              // TX Mark '1'
       }
       else {
         TACCTL0 |= OUTMOD2;               // TX Space '0'
       }
       txData >>= 1;
       txBitCnt--;
   }
}      
//------------------------------------------------------------------------------
// Timer_A UART - Receive Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = TIMERA1_VECTOR
__interrupt void Timer_A1_ISR(void)
{
   static unsigned char rxBitCnt = 8;
   static unsigned char rxData = 0;

   switch (__even_in_range(TAIV, TAIV_TAIFG)) { // Use calculated branching
       case TAIV_TACCR1:                        // TACCR1 CCIFG - UART RX
           TACCR1 += UART_TBIT;                 // Add Offset to CCRx
           if (TACCTL1 & CAP) {                 // Capture mode = start bit edge
               TACCTL1 &= ~CAP;                 // Switch capture to compare mode
               TACCR1 += UART_TBIT_DIV_2;       // Point CCRx to middle of D0
           }
           else {
               rxData >>= 1;
               if (TACCTL1 & SCCI) {            // Get bit waiting in receive latch
                   rxData |= 0x80;
               }
               rxBitCnt--;
               if (rxBitCnt == 0) {             // All bits RXed?
                   rxBuffer = rxData;           // Store in global variable
                   rxBitCnt = 8;                // Re-load bit counter
                   TACCTL1 |= CAP;              // Switch compare to capture mode
                   __bic_SR_register_on_exit(LPM0_bits);  // Clear LPM0 bits from 0(SR)
               }
           }
           break;
   }
}
//------------------------------------------------------------------------------


// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
 __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}




Link to post
Share on other sites

i didn't explain well.

when i said we could omit the "settlement" delay means only to the delay, u still need to setup the ADC registers.

 

ie. have to add back this two lines

 

ADC10CTL1 = INCH_10 + ADC10DIV_3; // Temp Sensor ADC10CLK/4

ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;

 

u can add them back just before

 

TACTL = TASSEL_2 | MC_2;

while (TAR < 30);

 

w/o them, when u start conversion, and go sleep, it will never finish and wake u up.

instead u are awaken by the wake-up from the uart routine when it detects another incoming character.

and ADC10MEM will already give u zero.

 

 

i cannot tried your code as i am in linux and mspgcc. but i am pretty sure is the lack of ADC setup.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...