Hi
I am working on msp430g2231 and I have very less knowledge about it.
I have written a Code to test the working of ISR(interrupt sub routine) of timer_a.
But I think there is a problem and the program is unable to execute the sub routine.
The idea is to blink an LED(P1.0) upon button press(P1.3).(Note: blinking is just to check whether the program is executing the ISR or not?)
----------------------------
and
TACCTL0= CM_3 | CCIS_1 | SCS | CAP | CCIE;
Please tell me do we need to route the button with CCI0B externally or it is already routed???
Please follow the code below and help.
-----------------------------------------------------------------------------------------------------------------------------
#include "msp430g2231.h"void main(void){ WDTCTL= WDTPW | WDTHOLD; P1OUT = 0; P1DIR = 0x01; P1SEL = BIT3; TACCTL0= CM_3 | CCIS_1 | SCS | CAP | CCIE; TACTL = TASSEL_2 | ID_3 | MC_2 | TACLR; for ( ;;) { __low_power_mode_3(); }}# pragma vector = TIMERA0_VECTOR__interrupt void TIMERA0_ISR (void){ P1OUT=0x01; }
Hi Matthias
Thanks a lot.
I am not able to understand how this code works.P1.1 and P1.2 (TXD and RXD ) are not used anywhere except for PDIR.
Please explain when and how will the interrupt generate ?
Can you please tell how can I run this code on CCS(v4).
Thanks
Hello Salony
The timer module can be programmed for a pin action to be executed when the compare value matches the free running counter. Have a look for the OUTMODx keyword in the manual. Its amazing what can be done with the Ouput-Modes: Toggle, Set, Reset, and combinations of them
Your RX from the example works in a similar way: routed directly to the timer. So there is no code needed to treat them like IO-ports as it would be needed for leds and buttons in general.
I use CSS(5.1) and would recommend you to do the same. It's free too for your purposes. post your project and perhaps I can find some time at weekend to help you merging your code with UART-Example.
Cheers, matthias
Hi Salony,
First, you need an application program running on your PC that will read
the com port. You can create one or you can install a serial port reader application
such as any of the following.
http://www.serialporttool.com/CommPalInfo.htm
http://www.232analyzer.com/232default.htm
Since you will only need to send data , I have modified the code above and
removed the "receive" actions. Try to download this into your MSP430G2231.
It should send "UART TEST OK" if the P1.3 button is pressed.
You were asking about CCSv4. I think there are plenty of tutorials
available on how to use it. Personally , I would suggest you use
IAR embedded workbench kickstart.
Link : http://www.ti.com/tool/iar-kickstart
//code
#include "msp430g2231.h"//------------------------------------------------------------------------------// Hardware-related definitions//------------------------------------------------------------------------------#define UART_TXD 0x02 // TXD on P1.1 (Timer0_A.OUT0)//------------------------------------------------------------------------------// 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//------------------------------------------------------------------------------// Function prototypes//------------------------------------------------------------------------------void TimerA_UART_init(void);void TimerA_UART_tx(unsigned char byte);void TimerA_UART_print(char *string);//------------------------------------------------------------------------------// main()//------------------------------------------------------------------------------void main(void){ 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 ; // Timer function for TXD/RXD pins P1REN=BIT3 //enable pull up resistor in case external resistor is not populated P1DIR |= 0x02 P2OUT = 0x00; P2SEL = 0x00; P2DIR = 0xFF; __enable_interrupt(); TimerA_UART_init(); // Start Timer_A UART TimerA_UART_print("G2xx1 TimerA UART\r\n"); TimerA_UART_print("READY.\r\n"); while(1) { while((BIT3&P1IN)==0) {
TimerA_UART_print("UART TEST OK");
}
while((BIT3&P1IN)==0)
{ //do nothing } }}//------------------------------------------------------------------------------// Function configures Timer_A for full-duplex UART operation//------------------------------------------------------------------------------void TimerA_UART_init(void){ TACCTL0 = OUT; // Set TXD Idle as Mark = '1' 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; // WHAT THIS SIGN INDICATES ">>=" ?? txBitCnt--; }}
That's C++ 101.
It is the C++ short version for x = x>>1 and does a right-shift of the variable, dropping th ecurent BIT0 and making BIT1 the new BIT0 (and BIT2 to BIT1etc.).
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.
Hi Michael
My program of SOFT-UART is running successfully.I am using putty for the terminal display of the result.
Can you please tell me how do i write a program on PC to modify the data received for example plotting of graph(for numerical values)?
or is there any software which will do the work directly?
In my actual program i need to get the PWM wave from an infrared sensor,convert the PWM output to respective temperature value and finally store the values and plot it against time.
thanks
Hi Rame
Take a look at this project.
It receives commands from PC and sends answers (msotly ADC conversion results) to the PC, using a LaunchPad. Onteh PC side, the application has a simple Windows Forms UI (C#) for the controls and uses a free scope library for the plotting. However, it is not an x/y plot but rather a realtime display of incoming values.However, it is worth a look if you want to know how things like this can be done.
Of course you can replace the calls to the library by your own line drawing functions.