Jump to content

mnpumar

Members
  • Content Count

    41
  • Joined

  • Last visited

  1. mnpumar

    MSP430 UART

    Thank you so much! I'm going to give this a try tomorrow and I'll let you know how it goes.
  2. mnpumar

    MSP430 UART

    I'd like to control an MSP430G2231 connected to my PC using the launchpad. After doing a little research, it looks like UART may be what I need. I found some code examples from TI, but I don't really understand how they work. What I'd like to do is send a signal from my PC to the MSP430 which would tell it to enable/disable certain pins. Here is the code i found, would anybody mind explaining how to use it? What is the difference between these two UART code samples? How do I send/receive on my PC? Do I need some sort of terminal? Can someone please explain? //****************************************************************************** // MSP430G2xx1 Demo - Timer_A, Ultra-Low Pwr UART 2400 Echo, 32kHz ACLK // // Description: Use Timer_A CCR0 hardware output modes and SCCI data latch // to implement UART function @ 2400 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 echo's back the received character. // 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.5|--------> // | | 2400 8N1 // | CCI0A/RXD/P1.1|<-------- // #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); // D. Dang // Texas Instruments Inc. // October 2010 // Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10 //****************************************************************************** #include void main (void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer CCTL0 = OUT; // TXD Idle as Mark TACTL = TASSEL_1 + MC_2; // ACLK, continuous mode P1SEL = TXD + RXD; // P1DIR = 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/SP while (CCR0 != TAR) // Prevent async capture CCR0 = TAR; // Current state of TA counter CCR0 += Bitime; // Some time till first bit RXTXData |= 0x100; // Add mark stop bit to RXTXData RXTXData = RXTXData << 1; // Add space start bit CCTL0 = CCIS0 + OUTMOD0 + CCIE; // TXD = mark = idle while ( CCTL0 & CCIE ); // Wait for TX completion } // Function Readies UART to Receive Character into RXTXData Buffer void RX_Ready (void) { BitCnt = 0x8; // Load Bit counter CCTL0 = SCS + OUTMOD0 + CM1 + CAP + CCIE; // Sync, Neg Edge, Cap } // Timer A0 interrupt service routine #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { CCR0 += Bitime; // Add Offset to CCR0 // TX if (CCTL0 & CCIS0) // TX on CCI0B? { if ( BitCnt == 0) CCTL0 &= ~ CCIE; // All bits TXed, disable interrupt else { CCTL0 |= OUTMOD2; // TX Space if (RXTXData & 0x01) CCTL0 &= ~ OUTMOD2; // TX Mark RXTXData = RXTXData >> 1; BitCnt --; } } // RX else { if( CCTL0 & CAP ) // Capture mode = start bit edge { CCTL0 &= ~ CAP; // Switch from capture to compare mode CCR0 += Bitime_5; } else { RXTXData = RXTXData >> 1; if (CCTL0 & SCCI) // Get bit waiting in receive latch RXTXData |= 0x80; BitCnt --; // All bits RXed? if ( BitCnt == 0) //>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< { CCTL0 &= ~ CCIE; // All bits RXed, disable interrupt _BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR) } //>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< } } } //****************************************************************************** // 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 //****************************************************************************** #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); //------------------------------------------------------------------------------ // 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 + UART_RXD; // Timer function for TXD/RXD pins P1DIR = 0xFF & ~UART_RXD; // Set all pins but RXD to output 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"); for (; { // Wait for incoming character __bis_SR_register(LPM0_bits); // Update board outputs according to received byte if (rxBuffer & 0x01) P1OUT |= 0x01; else P1OUT &= ~0x01; // P1.0 if (rxBuffer & 0x02) P1OUT |= 0x08; else P1OUT &= ~0x08; // P1.3 if (rxBuffer & 0x04) P1OUT |= 0x10; else P1OUT &= ~0x10; // P1.4 if (rxBuffer & 0x08) P1OUT |= 0x20; else P1OUT &= ~0x20; // P1.5 if (rxBuffer & 0x10) P1OUT |= 0x40; else P1OUT &= ~0x40; // P1.6 if (rxBuffer & 0x20) P1OUT |= 0x80; else P1OUT &= ~0x80; // P1.7 if (rxBuffer & 0x40) P2OUT |= 0x40; else P2OUT &= ~0x40; // P2.6 if (rxBuffer & 0x80) P2OUT |= 0x80; else P2OUT &= ~0x80; // P2.7 // Echo received character TimerA_UART_tx(rxBuffer); } } //------------------------------------------------------------------------------ // 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; } } //------------------------------------------------------------------------------
  3. mnpumar

    MSP430 PC GUI Eval Tool

    Will this work with a G2231?
  4. mnpumar

    MSP430 USB Developers Package

    Hmm..this seems a little overly complicated for what I need to do. Is there any possible way to raise and lower a single pin on the launchpad through some command sent via usb? Is it possible to do this using UART? Are there any code samples of how to use the UART on the launchpad?
  5. mnpumar

    MSP430 USB Developers Package

    Thank you for the info! Since the msp430f series only comes in smt, are there still development kits available? If so, are there any you would recommend for a beginner?
  6. I'm thinking of using the MSP430 USB Developers Package for a little project i'm going to be starting, and I was wondering if anybody here has some experience with it. I can't seem to find any wiring diagrams that show how to connect the MSP430 to USB. Does anybody on here know? I suppose I could try it out with the development board, but I'd like to have something that doesn't rely on that. Also, does anybody here have experience with the HID USB Application? Is it difficult to get the MSP430 to start receiving and responding to USB messages? Here's a link to the package: http://www.ti.com/tool/msp430usbdevpack#tiDevice Thanks! EDIT: Can a moderator please move this to the general section? I posted it here by mistake.
  7. mnpumar

    Digital LED Clock

    Yes, they are multiplexed digit by digit. The hours are combined into one multiplexed grid, and the minutes are each multiplexed separately. It took me hours on end to make all the connections on the breadboard to make this possible.
  8. mnpumar

    Digital LED Clock

    I will post a full schematic when I have more time, the other digits are exactly the same with one less column. I'm swamped with work for my other classes now until Wednesday. Thanks for all the positive comments and support.
  9. My project/code/schematic is all posted here: http://www.43oh.com/forum/viewtopic.php?f=9&t=225
  10. mnpumar

    Digital LED Clock

    Thanks! Code has been uploaded thanks to bluehash Thanks! I emailed you the schematic, would you mind adding it too? Also, is there any way to make the pictures appear larger? EDIT: Forgot to author my code :S can add it to my first post again? It's attached to this reply. EDIT2: Also authored the schematic, sent it to your email. Code.zip
  11. mnpumar

    Digital LED Clock

    Thanks! The breadboarding took me 2 days straight, and a few more hours the next day after I finally made it to bed. I uploaded the full version of the pictures for you here: http://www.megaupload.com/?d=AS2R5SHU, they were too big to send via email. I also sent a copy of the link to your email, and my code.
  12. mnpumar

    Digital LED Clock

    Sure, I can post the code if people are interested.
  13. mnpumar

    Digital LED Clock

    So here it is: (EDIT: the forum seems to be cutting off some of the pictures to the right, if you'd like to see the full version of them, go here: http://img718.imageshack.us/gal.php?g=25703750f.png) 4 MSP430's working together The whole thing runs off a single 9V battery. The two digits for the hours are connected to one MSP430, and the two digits that make up the minutes are each connected to separate MSP430s. The whole thing is controlled by another MSP430 which keeps the time. The itself clock has two modes, one mode where it counts time 60x faster and counts 1 minute as one second. The other mode is where it runs like a normal clock. If you guys would like more information, please let me know. It took me a couple all-nighters to get it all wired together on a breadboard, but I managed to get it all done Can't wait to see what my professor thinks about it, haha. Special thanks to Simplevar, GeekDoc, cde, and everyone else on this forum for answering all my questions, I couldn't have done it without you guys! MSP430_Digital_LED_Clock_Schematic.pdf MSP430_Digital_LED_Clock_Code.zip
  14. mnpumar

    P2.7 As Input?

    I don't really have a button, I was just connecting the pin to ground/vcc with a wire. I got it to work by doing the following: int main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; P2OUT = 0; //P2 is output low P2DIR = BIT7; //P2 is output P2SEL = 0; //P2 is digital i/0 P2REN = 0; //P2 disable pullup resistors */ P2DIR &= ~BIT7; int i = 1; for(;{ //Digital Input while (!(P2IN & BIT7)){ Display(i); } //wait for P1.7 to go high (button is released) i = i + 1; //increase counter if (i > 12) i = 0; //maximum display is 12 while (P2IN & BIT7); //wait for P1.7 to go low (buttion is pressed) //delay(10000); } } Problem now is that it's a pretty unreliable switch. Whenever i trigger it, the number goes up a random number of times. I thought the while (P2IN & BIT7); //wait for P1.7 to go low (buttion is pressed) is supposed to prevent this from happening?
  15. mnpumar

    P2.7 As Input?

    I am not familiar with interrupts i thought i'd be more comfortable working with inputs
×