
mnpumar
-
Content Count
41 -
Joined
-
Last visited
Posts posted by mnpumar
-
-
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; } } //------------------------------------------------------------------------------
-
Will this work with a G2231?
-
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?
-
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?
-
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.
-
mnpumar, did you charlieplex the LEDs?
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.
-
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.
-
-
Well done!
I have to admit, I didn't think you'd get this working this fast.
Great photos. I think we'd all appreciate seeing the master and slave code, if you're okay with posting it here. Heck, add a schematic and a description and you have a Project of the Month submission!
Congrats again. I hope you get a great grade!
Thanks! Code has been uploaded thanks to bluehash
OP post updated. Thanks for the email.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.
-
excellent work! i was skeptical on your design in the very beginning. i am amazed how u pull in out in just a few days. must be many hours of hard work.
congrats.
Thanks! The breadboarding took me 2 days straight, and a few more hours the next day after I finally made it to bed.
uh-oh. I'm unable to see this at work.mnpumar, could you send a zip file of your images to a_d_m_i_n_@43oh.com (remove the underscores)
I'll try to put it here. I really wish to see it.
good going!
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.
-
very nice!!
are you going to post the code for it?
Sure, I can post the code if people are interested.
-
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!
- bluehash and rivalslayer
-
2
-
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?
-
Is there any reason why you did not them up as interrupts? I think it should be easier that way, rather than poll P2.7
I am not familiar with interrupts i thought i'd be more comfortable working with inputs
-
Just tried this:
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 */
int i = 1;
for(;
{ //Digital Input
while (P2IN & BIT7); //wait for P1.7 to go low (buttion is pressed)
TurnON(1,0); //display
while (!(P2IN & BIT7)); //wait for P1.7 to go high (button is released)
i = i + 1; //increase counter
if (i > 12) i = 0; //maximum display is 12
delay(10000);
TurnOFF(1,0);
}
}
The LED stays on and never turns off from the beginning :?
-
I'm trying to use P2.7 as an input pin, but it doesn't seem to be working.
Here's the code I'm using:
int main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; P2OUT = 0; //P2 is output low P2DIR = BIT6 + BIT7; //P2 is output P2SEL = 0; //P2 is digital i/0 P2REN = 0; //P2 disable pullup resistors */ int i = 1; for(;{ //Digital Input while (P2IN & BIT7); //wait for P1.7 to go low (buttion is pressed) Display(i); //display while (!(P2IN & BIT7)); //wait for P1.7 to go high (button is released) i = i + 1; //increase counter if (i > 12) i = 0; //maximum display is 12 } }
Whole code is here if necessary:
#include "io430.h" void delay(unsigned int n){ while (n > 0) n--; } void TurnON(unsigned x, unsigned y) { unsigned YBITS[5] = {BIT0, BIT1, BIT2, BIT3, BIT4}; unsigned XBITS[3] = {BIT5, BIT6, BIT7}; P1OUT &= ~YBITS[y]; P1SEL &= ~YBITS[y]; P1DIR |= YBITS[y]; P1OUT |= YBITS[y]; if(x < 3) { P1OUT &= ~XBITS[x]; P1SEL &= ~XBITS[x]; P1DIR |= XBITS[x]; P1OUT |= XBITS[x]; }else { P2OUT &= ~BIT6; P2SEL &= ~BIT6; P2DIR |= BIT6; P2OUT |= BIT6; } } void TurnOFF(unsigned x, unsigned y) { unsigned YBITS[5] = {BIT0, BIT1, BIT2, BIT3, BIT4}; unsigned XBITS[3] = {BIT5, BIT6, BIT7}; P1OUT &= ~YBITS[y]; if(x < 3) { P1OUT &= ~XBITS[x]; }else { P2OUT &= ~BIT6; } } void Display(unsigned number) { if(number == 1) { TurnON(3,0); TurnOFF(3,0); TurnON(3,1); TurnOFF(3,1); TurnON(3,2); TurnOFF(3,2); TurnON(3,3); TurnOFF(3,3); TurnON(3,4); TurnOFF(3,4); } if(number == 2) { TurnON(1,0); TurnOFF(1,0); TurnON(2,0); TurnOFF(2,0); TurnON(3,0); TurnOFF(3,0); TurnON(3,1); TurnOFF(3,1); TurnON(3,2); TurnOFF(3,2); TurnON(2,3); TurnOFF(2,3); TurnON(2,2); TurnOFF(2,2); TurnON(1,2); TurnOFF(1,2); TurnON(1,3); TurnOFF(1,3); TurnON(1,4); TurnOFF(1,4); TurnON(2,4); TurnOFF(2,4); TurnON(3,4); TurnOFF(3,4); } else if(number == 3) { Display(1); TurnON(1,0); TurnOFF(1,0); TurnON(2,0); TurnOFF(2,0); TurnON(2,3); TurnOFF(2,3); TurnON(2,2); TurnOFF(2,2); TurnON(1,2); TurnOFF(1,2); TurnON(1,4); TurnOFF(1,4); TurnON(2,4); TurnOFF(2,4); } else if(number == 4) { Display(1); TurnON(1,0); TurnOFF(1,0); TurnON(3,0); TurnOFF(3,0); TurnON(1,1); TurnOFF(1,1); TurnON(1,2); TurnOFF(1,2); TurnON(2,2); TurnOFF(2,2); } else if(number == 5) { TurnON(1,0); TurnOFF(1,0); TurnON(2,0); TurnOFF(2,0); TurnON(3,0); TurnOFF(3,0); TurnON(1,1); TurnOFF(1,1); TurnON(2,2); TurnOFF(2,2); TurnON(1,2); TurnOFF(1,2); TurnON(3,2); TurnOFF(3,2); TurnON(3,3); TurnOFF(3,3); TurnON(1,4); TurnOFF(1,4); TurnON(2,4); TurnOFF(2,4); TurnON(3,4); TurnOFF(3,4); } else if(number == 6) { Display(5); TurnON(1,3); TurnOFF(1,3); } if(number == 7) { Display(1); TurnON(2,0); TurnOFF(2,0); TurnON(1,0); TurnOFF(1,0); } else if(number == 8) { Display(6); TurnON(3,1); TurnOFF(3,1); } else if(number == 9){ Display(7); TurnON(1,1); TurnOFF(1,1); TurnON(1,2); TurnOFF(1,2); TurnON(2,2); TurnOFF(2,2); } else if(number==10){ Display(7); TurnON(1,1); TurnOFF(1,1); TurnON(1,2); TurnOFF(1,2); TurnON(1,3); TurnOFF(1,3); TurnON(1,4); TurnOFF(1,4); TurnON(2,4); TurnOFF(2,4); TurnON(0,0); TurnOFF(0,0); TurnON(0,1); TurnOFF(0,1); TurnON(0,2); TurnOFF(0,2); TurnON(0,3); TurnOFF(0,3); TurnON(0,4); TurnOFF(0,4); }else if(number == 11){ Display(1); TurnON(0,0); TurnOFF(0,0); TurnON(0,1); TurnOFF(0,1); TurnON(0,2); TurnOFF(0,2); TurnON(0,3); TurnOFF(0,3); TurnON(0,4); TurnOFF(0,4); }else if(number == 12){ Display(2); TurnON(0,0); TurnOFF(0,0); TurnON(0,1); TurnOFF(0,1); TurnON(0,2); TurnOFF(0,2); TurnON(0,3); TurnOFF(0,3); TurnON(0,4); TurnOFF(0,4); } } int main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; P2OUT = 0; //P2 is output low P2DIR = BIT6 + BIT7; //P2 is output P2SEL = 0; //P2 is digital i/0 P2REN = 0; //P2 disable pullup resistors */ int i = 1; for(;{ //Digital Input while (P2IN & BIT7); //wait for P1.7 to go low (buttion is pressed) Display(i); //display while (!(P2IN & BIT7)); //wait for P1.7 to go high (button is released) i = i + 1; //increase counter if (i > 12) i = 0; //maximum display is 12 } }
EDIT: I tried replacing display(i) with just TurnON(1,0), and the light turned on instantly and ever turned off, even when i applied VCC to pin 2.7...
-
LOL forgot to add infinate loop...guess these things happen when you stay up all night breadboarding/coding
-
I have wired up a layout in which the LEDs are connected in a grid. The rows are all connected to transistors which switch between the positive supply and zero, and the columns switch between an open circuit and a connection to ground
I am using the following code:
#include "io430.h" void TurnON(unsigned x, unsigned y) { unsigned YBITS[5] = {BIT0, BIT1, BIT2, BIT3, BIT4}; unsigned XBITS[3] = {BIT5, BIT6, BIT7}; P1OUT &= ~YBITS[y]; P1SEL &= ~YBITS[y]; P1DIR |= YBITS[y]; P1OUT |= YBITS[y]; if(x < 3) { P1OUT &= ~XBITS[x]; P1SEL &= ~XBITS[x]; P1DIR |= XBITS[x]; P1OUT |= XBITS[x]; }else { P2OUT &= ~BIT6; P2SEL &= ~BIT6; P2DIR |= BIT6; P2OUT |= BIT6; } } void TurnOFF(unsigned x, unsigned y) { unsigned YBITS[5] = {BIT0, BIT1, BIT2, BIT3, BIT4}; unsigned XBITS[3] = {BIT5, BIT6, BIT7}; P1OUT &= ~YBITS[y]; if(x < 3) { P1OUT &= ~XBITS[x]; }else { P2OUT &= ~BIT6; } } int main( void ) { // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; TurnON(1,0); TurnOFF(1,0); }
The problem is that when I run it with TurnON then TurnOFF, the LED doesn't light up. When run it with just TurnON, the led lights up. However, when I try to display a number on the grid without using TurnOFF, such as a 2, the entire grid just lights up.
What am I doing wrong? How do I make the LEDs turn on and off and still see them?
Thanks
-
for breadboarding (w/o debugger connection and eventually w/o launchpad), u need to tie the RESET pin to Vcc (3.3v) otherwise your firmware won't start.
see this is my hookup, i am running the wires via the jumper block headers but it's the same.
http://www.simpleavr.com/msp430-projects/3p4w-clock/3p4w04.jpg
I wish I could give you 100000 thanks for this! I just spent the last 4 hours trying to figure out why this wasn't working, and it was the reset pin! Thank you so much!!
-
I disabled everything in the code, all it's supposed to do is turn on P1.1 and P1.2, and I tested those pins with a volt meter and they are 0V. Do I still need to connect any other pins than VCC and GND for this to work?
Are you programming it on the breadboard? Then yes. You need to connect test and rst.
I'm not programming it on the breadboard. I program it on the launchpad, then take it off the launchpad and put it on the breadboard. How do I run the MCU just off 3.5V source? Would test and rst be connected to ground?
-
Edit: looking at the code again, it will turn p1.0 and p1.1 on, and never off since you commented out the instructions for that. AND you defined your variable clicks INSIDE the interrupt, with a value of 0. EVERY time the interrupt is called, clicks will reset to 0. It will never reach 20 or 10, so it will never toggle the pins on in the first place.
The code works fine with the MSP430 connected to the launchpad. When I take it off and connect it to the breadboard, nothing happens.
-
I disabled everything in the code, all it's supposed to do is turn on P1.1 and P1.2, and I tested those pins with a volt meter and they are 0V. Do I still need to connect any other pins than VCC and GND for this to work?
-
I am trying to get an MSP430G32231 to work on a breadboard. Here is what I did:
I connected the MSP430G2231 to the breadboard. I connected VCC from the lanuchpad to the top right pin of the MSP430 on the breadboard. I then connected a wire from the top right pin of the mcu to the GND pin on the launchpad. However, the MCU does not respond.
What am I doing wrong???
Here's a picture of the setup:
And the code:
// use timer_a to generate one second ticks // built with msg430-gcc, flash w/ mspdebug // #ifdef MSP430 #include "signal.h" #endif #include #include volatile unsigned char second_passed=0; // advance indicator volatile unsigned long ticks=0; // 'clock' in seconds struct t{ unsigned hour; unsigned minute1; unsigned minute2; unsigned seconds; }time; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz factory calibration value DCOCTL = CALDCO_1MHZ; P1DIR |= BIT0; P1DIR |= BIT1;// P1.0 output CCTL0 = CCIE; // CCR0 interrupt enabled CCR0 = 50000; TACTL = TASSEL_2 + MC_1; // SMCLK, upmode _BIS_SR(GIE); // enable interrupt //Initialize time to 12:00 time.hour = 12; time.minute1 = 0; time.minute2 = 0; time.seconds = 0; while (1) { if (second_passed) { time.seconds += 1; //Increase time by one second if(time.seconds == 60) //Check if a minute has passed { if(time.minute2 < 9) { time.minute2 += 1; //Send a pluse to minute2 MCU } else if(time.minute2 == 9 && time.minute1 <5)//Checks if 10 minutes have passed { time.minute2 = 0; time.minute1 += 1; } else if(time.minute1 == 5 && time.minute2 == 9)//Checks if an hour has passed { time.minute1 = 0; //Reset minutes back to zero //Send a pluse to Minute1 MCU time.minute2 = 0; //Send a pluse to Minute2 MCU if(time.hour == 12)//check if its 12:00 { time.hour = 1; //Rest time back to 1:00 //Send a pluse to hours MCU } else { time.hour += 1;//increase time by an hour //Send a pluse to hours MCU } } time.seconds = 0;//reset seconds to 0 }//end of if seconds = 60 second_passed = 0; }//end of if second_passed }//end of while //_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt }//end of main // Timer A0 interrupt service routine #ifdef MSP430 interrupt(TIMERA0_VECTOR) Timer_A(void) #else #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) #endif { static unsigned int clicks=0; // we will get called at 1Mhz/50k = 20 times a seconds clicks++; if (clicks >= 20) { clicks = 0; ticks++; // advance clock for each second second_passed = 1; // have a flag to tell back main loop }//if // the followng can be a HHMM colon seperator led // take them out if not needed if (clicks >= 10){ P1OUT |= BIT0; P1OUT |= BIT1;// half second on } else { //P1OUT &= ~BIT0; // half second off //P1OUT &= ~BIT1; } //P1OUT ^= 0x01; // P1.0 } /* for digits: while(input voltage at pinx >0){ -increase digit, and depending on its position, determine whether it should be reset to 0 or off. -wait for input voltage at pinx to go back to zero } */ /* while (1) { if (PIIN &= BIT1) { // detect a rising edge (hi) while (P1IN &= BIT1); // wait for falling edge (low) // do your led display pin toggling here }//if }//while */
-
I think I can actually get it down to 10 pins by following this charliplexing example: http://ominoushum.com/life/
I post back when i get the right layout down.
EDIT: Is it possible to implement NPN transistors into that type of layout so I can use a higher voltage to power the LEDs?
Edit2: I attempted to come up with a solution like this:
However, when I simulate it, it does not work. My intention was that when V2 (representing the input of the msp430) is 3V, it would output 9V, and when V2 was 0, it would output a connection to ground. Does anyone know why this doesn't work? (the nmos can be replaced by another npn after the inverter).
MSP430 UART
in General
Posted
Thank you so much! I'm going to give this a try tomorrow and I'll let you know how it goes.