Part Number: MSP430FR5969
Tool/software: Code Composer Studio
Hello,
as I posted a week ago, I want to mesure an external wave signal and capturing the increase value of the timer. Once I achieved that, I want to to transmit the increase value of the timer by using UART ut (serial port). I used a code that captures a temperature signal and transmit the value, as an example to implement the code on my program but it does not work.
****HERE IS THE EXAMPLE CODE USED*****
#include <stdio.h> #include <stdint.h> #include <msp430.h> long valor; // Global variable of 16 bits void UART_print(char *string); // Function used to transmit by serial port int main(void) { char result[50]; // String to transmit by serial port WDTCTL = WDTPW | WDTHOLD; // Stop WDT // Configure GPIOs to it's lowest power state P1OUT = 0; // All P1.x reset P1DIR = 0xFF; // All P1.x outputs P2OUT = 0; // All P2.x reset P2DIR = 0xFF; // All P2.x outputs P3OUT = 0; // All P3.x reset P3DIR = 0xFF; // All P3.x outputs P4OUT = 0; // All P4.x reset P4DIR = 0xFF; // All P4.x outputs PJOUT = 0; // All PJ.x reset PJDIR = 0xFFFF; // All PJ.x outputs // Set up XT1 PJSEL0 = BIT4 | BIT5; // For XT1 P2SEL1 |= BIT1 | BIT0; // Configure UART pins P2SEL0 &= ~(BIT1 | BIT0); // Configure UART pins // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Clock System Setup CSCTL0_H = CSKEY >> 8; // Unlock CS registers CSCTL1 = DCOFSEL_0; // Set the freq. of DCO = 1 MHz CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK; CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers CSCTL4 &= ~LFXTOFF; // New: Configure UART. UCA0CTLW0 |= UCSSEL__SMCLK | UCSWRST; // No parity, LSB first, 8-bit data, 1 stop, Funciona amb el SMCLK!! UCA0BRW = 6; // Baud rate register prescale. Configure 9600 baud. This value works for SMCLK =1MHz UCA0MCTLW |= 0x2081; // UCBRS = 0x20, UCBRF = 8; UCOS16 = 1 UCA0CTLW0 &= ~UCSWRST; // Enable eUSCI_A do { CSCTL5 &= ~LFXTOFFG; // Clear XT1 fault flag SFRIFG1 &= ~OFIFG; } while (SFRIFG1 & OFIFG); // Test oscillator fault flag do { __delay_cycles(1000000); // Wait 1 s valor=0x1010; //Variable to transmit. For example number 16. sprintf(result,"Codi: %d \r\n",valor); // Generates a string UART_print(result); // Send the result UART while(UCA0STATW & UCBUSY); // Not clear if it is necessary } while(1); return 0; } void UART_print(char *string) // Send a zero-terminated string through the UART { char byte = *string++; while(byte != 0) { while(!(UCA0IFG & UCTXIFG)); // Wait until TX buffer ready UCA0TXBUF = byte; // Send the next byte of info byte = *string++; // Get the next character to send } }
This program works, but when I try to implement it on my program, it has some errors and i do not know how to solve it.
****HERE IS MY CODE****
#include <stdio.h> #include <stdint.h> #include <msp430.h> long value; // Global variable of 16 bits unsigned int n = 0; volatile unsigned int vinitial; volatile unsigned int vfinal; volatile unsigned int result; void UART_print(char *string); int main(void) { char results[50]; // Character string to transmit by serial port WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer // Configure GPIO P1OUT &= ~0x01; // Clear P1.0 output P1DIR |= 0x01; P1SEL1 &= ~BIT3; // Set P1.3 to input direction P1SEL0 |= BIT3; P1DIR &= ~BIT3; P2SEL1 |= BIT1 | BIT0; // Configure UART pins P2SEL0 &= ~(BIT1 | BIT0); // Configure UART pins // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Clock System Setup CSCTL0_H = CSKEY >> 8; // Unlock CS registers CSCTL1 = DCOFSEL_0; // Set DCO to 1MHz CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set SMCLK = MCLK = DCO ACLK = VLOCLK CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1 CSCTL4 &= ~LFXTOFF; CSCTL0_H = 0x00; // Lock CS module (use byte mode to upper byte) __delay_cycles(1000); // Allow clock system to settle UCA0CTLW0 |= UCSSEL__SMCLK | UCSWRST; // No parity, LSB first, 8-bit data, 1 stop, It works with SMCLK UCA0BRW = 6; // Baud rate register prescale. Configure 9600 baud. This value is correct if SMCLK works at 1 MHz UCA0MCTLW |= 0x2081; // UCBRS = 0x20, UCBRF = 8; UCOS16 = 1 UCA0CTLW0 &= ~UCSWRST; // Enable eUSCI_A // Timer0_A3 Setup TA1CCTL2 = CM_1 | CCIS_0 | SCS | CAP | CCIE; // Capture rising edge, // Use CCI2A=P1.3, // Synchronous capture, // Enable capture mode, // Enable capture interrupt TA1CTL = TASSEL__SMCLK | MC__CONTINUOUS ; // Use SMCLK as clock source, Start timer in continuous mode. TA1EX0 = 0X00; __bis_SR_register(LPM0_bits | GIE); do { __delay_cycles(1000000); // Wait 1 s value=result; // Output value sprintf(results,"The result is: %d \r\n",value); // It generates a string with the result UART_print(results); // Send the increase value of the timer through the backchannel UART while(UCA0STATW & UCBUSY); // I do not know if it is necessary } while(1); return 0; } } // Timer1_A3 CC1-4, TA Interrupt Handler #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector = TIMER1_A1_VECTOR __interrupt void Timer1_A1_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(TIMER1_A1_VECTOR))) Timer1_A1_ISR (void) #else #error Compiler not supported! #endif { switch (__even_in_range(TA1IV, TA1IV_TAIFG)) { case TA1IV_TA1CCR1: break; case TA1IV_TA1CCR2: if (n == 0){ vinitial = TA1CCR2; n = 1; } else { vfinal = TA1CCR2; n=0; } result = (vfinal-vinitial); __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU break; case TA1IV_TA1IFG: break; default: break; } } void UART_print(char *string) // Send a zero-terminated string through the UART { char byte = *string++; while(byte != 0) { while(!(UCA0IFG & UCTXIFG)); // Wait until TX buffer ready UCA0TXBUF = byte; // Send the next byte of info byte = *string++; // Get the next character to send } }
It has some errors and I do not know how to solve it.
Thank you for your help and sorry for the inconvenience.
Adrian.