Part Number: MSP430G2553
I am trying to read sensor data and send it to my computer through Bluetooth to be graphed. For testing purposes I am just trying to send a sine wave from a function generator before connecting my actual sensors, but I can only get a clean sine wave of about 2Hz to come through. My guess is that the issue is caused by differing speeds in the ADC sampling and UART transmission but I am pretty new to this so I can't figure out what my issue is.
#include <msp430g2553.h>
/**
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
//--------------------Disable Port 2---------------------//
P2OUT &= 0x00;
P2DIR &= 0x00;
//------------------- Configure the Clocks -------------------//
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
//------------------- Configure pins--------------------------//
P1SEL |= BIT1 + BIT2; // P1.1 UCA0RXD input
P1SEL2 |= BIT1 + BIT2; // P1.2 UCA0TXD output
P1DIR |= BIT3 + BIT4 + BIT5; //P1.3,1.4,1.5 set as outputs
P1DIR &= ~BIT0 + ~BIT6; //P1.0,1.6 set as input
//--------------------Configure ADC--------------------------//
ADC10CTL0 &= ~ENC;
ADC10CTL0 = ADC10SHT_1 + ADC10ON + ADC10SR + MSC + ADC10IE;
ADC10CTL1 = INCH_0 + SHS_0 + ADC10DIV_0 + ADC10SSEL_0 + CONSEQ_0;
ADC10AE0 |= BIT0;
//------------ Configuring the UART(USCI_A0) ----------------//
UCA0CTL1 |= UCSSEL_2 + UCSWRST; // USCI Clock = SMCLK,USCI_A0 disabled
UCA0BR0 = 104; // 104 From datasheet table
UCA0BR1 = 0; // -selects baudrate =9600,clk = SMCLK
UCA0MCTL = UCBRS_1; // Modulation value = 1 from datasheet
UCA0CTL1 &= ~UCSWRST; // Clear UCSWRST to enable USCI_A0
//---------------- Enabling the interrupts ------------------//
IE2 |= UCA0TXIE + UCA0RXIE; // Enable the Tx and Rx interrupts
_BIS_SR(GIE); // Enable the global interrupt
while(1)
{
ADC10CTL0 &= ~ENC;
while(ADC10CTL1 & ADC10BUSY)
{}
__low_power_mode_0();
ADC10CTL0 |= ENC + ADC10SC;
}
}
//-----------------------------------------------------------------------//
// Transmit and Receive interrupts //
//-----------------------------------------------------------------------//
#pragma vector = USCIAB0TX_VECTOR
__interrupt void TransmitInterrupt(void)
{
UCA0TXBUF = ADC10MEM >> 2; // UART stored and sent in UCA0TXBUF
IFG2 &= ~UCA0TXIFG; // Clear TX flag
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void ReceiveInterrupt(void)
{
}
#pragma vector = ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__low_power_mode_off_on_exit();
}
