roadrunner84 466 Posted March 20, 2013 Share Posted March 20, 2013 Looks like that (but uses ugly delays), both up and down should be debounced unless you're using only one flank (so do one thing on press and nothing on release) Quote Link to post Share on other sites
oPossum 1,083 Posted March 20, 2013 Share Posted March 20, 2013 Code was to show minimalist way to use UART, not how to debounce switches. Quote Link to post Share on other sites
yyrkoon 250 Posted March 20, 2013 Share Posted March 20, 2013 I think no matter what, that debounce in code is going to end up ugly. Personally, from all the debounce stuff I have read through in the past few months. That is probably the shortest, and most concise approach. I was reading a post on HAD a couple weeks ago, and one of the guys in that article had well over 200 lines worth of debounce code . . . Somehow, he managed to win the mini "contest" they seemed to be doing. Personally, I thought his code was junk, but meh, whatever. Quote Link to post Share on other sites
AMPS 0 Posted March 22, 2013 Share Posted March 22, 2013 i m using code composer studio . is it possible to load program from there. A simple well documented hardware uart "Hello World" example.Updated, thanks for member comments 3/13/13 Notes: This code is for launchpad rev 1.5 This is hardware UART, your launchpad jumpers must be set for hardware UART The TI TUSB3410 is a TERRIBLE usb-> UART chip and is very buggy on WIN7 64bit. If your still having issues, it could be a driver issue. Try on XP or use a different USB -> serial device. //Nate Zimmer UART example // Press button to print hello to terminal #include <msp430g2553.h> // System define for the micro that I am using #define RXD BIT1 //Check your launchpad rev to make sure this is the case. Set jumpers to hardware uart. #define TXD BIT2 // TXD with respect to what your sending to the computer. Sent data will appear on this line #define BUTTON BIT3 void UART_TX(char * tx_data); // Function Prototype for TX void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop Watch dog timer BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1 MHz DCOCTL = CALDCO_1MHZ; P1DIR &=~BUTTON; // Ensure button is input (sets a 0 in P1DIR register at location BIT3) P1OUT |= BUTTON; // Enables pullup resistor on button P1REN |= BUTTON; P1SEL = RXD + TXD ; // Select TX and RX functionality for P1.1 & P1.2 P1SEL2 = RXD + TXD ; // UCA0CTL1 |= UCSSEL_2; // Have USCI use System Master Clock: AKA core clk 1MHz UCA0BR0 = 104; // 1MHz 9600, see user manual UCA0BR1 = 0; // UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1 UCA0CTL1 &= ~UCSWRST; // Start USCI state machine while(1) // While 1 is equal to 1 (forever) { if(!((P1IN & BUTTON)==BUTTON)) // Was button pressed? { UART_TX("Hello World! \r\n"); // If yes, Transmit message & drink beer __delay_cycles(100000); //Debounce button so signal is not sent multiple times } } } void UART_TX(char * tx_data) // Define a function which accepts a character pointer to an array { unsigned int i=0; while(tx_data[i]) // Increment through array, look for null pointer (0) at end of string { while ((UCA0STAT & UCBUSY)); // Wait if line TX/RX module is busy with data UCA0TXBUF = tx_data[i]; // Send out element i of tx_data array on UART bus i++; // Increment variable for array address } } Quote Link to post Share on other sites
roadrunner84 466 Posted March 22, 2013 Share Posted March 22, 2013 @AMPS: Yes, but what are you getting at? Quote Link to post Share on other sites
muzay 0 Posted June 27, 2013 Share Posted June 27, 2013 Thank you for the post, it worked really well on my g2553. But i really urgently need to solve my problem , i'm new in coding. i want to send ADC result on uart continuosly... i need to accomplish sth like this function: unsigned int value; ---------- ... .. UART_TX(value); -------------- it gives me random numbers, thats all i could not achieve ofcourse, could you please help me, thank you in advanced.. ........................ #include <msp430g2553.h> // System define for the micro that I am using #define RXD BIT1 //Check your launchpad rev to make sure this is the case. Set jumpers to hardware uart. #define TXD BIT2 // TXD with respect to what your sending to the computer. Sent data will appear on this line #define BUTTON BIT3 unsigned int value2; //void UART_TX(char * tx_data); // Function Prototype for TX void UART_TX(unsigned int * value); // Function Prototype for TX void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop Watch dog timer BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1 MHz DCOCTL = CALDCO_1MHZ; P1DIR &=~BUTTON; // Ensure button is input (sets a 0 in P1DIR register at location BIT3) P1OUT |= BUTTON; // Enables pullup resistor on button P1REN |= BUTTON; P1SEL = RXD + TXD ; // Select TX and RX functionality for P1.1 & P1.2 P1SEL2 = RXD + TXD ; // UCA0CTL1 |= UCSSEL_2; // Have USCI use System Master Clock: AKA core clk 1MHz UCA0BR0 = 104; // 1MHz 9600, see user manual UCA0BR1 = 0; // UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1 UCA0CTL1 &= ~UCSWRST; // Start USCI state machine // set adc ADC10CTL1 = INCH_5 + ADC10DIV_3 ; // Channel 5, ADC10CLK/4 ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; //Vcc & Vss as reference ADC10AE0 |= BIT5; ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start, single measure! while(1) // While 1 is equal to 1 (forever) { if(!((P1IN & BUTTON)==BUTTON)) // Was button pressed? { value2=ADC10MEM & 0x00FF; UART_TX(&value2); // If yes, Transmit message & drink beer //UART_TX(value); // send ADC value __delay_cycles(100000); //Debounce button so signal is not sent multiple times } } } void UART_TX(unsigned int * value) // Define a function which accepts a character pointer to an array { unsigned int i=0; while(value) // Increment through array, look for null pointer (0) at end of string { while ((UCA0STAT & UCBUSY)); // Wait if line TX/RX module is busy with data UCA0TXBUF = value; // Send out element i of tx_data array on UART bus i++; // Increment variable for array address } } // 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) } Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.