Tool/software: Code Composer Studio
First post on here so apologies if I mess something up.
I'm coming from an arduino background so a lot of the lower level functions are quite new to me. I've been using some code examples and modifying them to try and understand how to transmit and receive command strings and data over the virtual com port.
I've got the code below:
#include "msp430g2553.h" #include <stdio.h> #include <string.h> char outputstring[7] = "test\r\n"; char inputbuffer[5]; char cmdword[5]; char rxchar; unsigned int i = 0; unsigned int rxindex = 0; unsigned int cmdflag = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop the Watch dog //------------------- Configure the Clocks -------------------// DCOCTL = 0; // Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation //---------------- Configuring the LED's ----------------------// P1DIR |= BIT0 + BIT6; // P1.0 and P1.6 output P1OUT &= ~BIT0 + BIT6; // P1.0 and P1.6 = 0 //--------- Setting the UART function for P1.1 & P1.2 --------// P1SEL |= BIT1 + BIT2; // P1.1 UCA0RXD input P1SEL2 |= BIT1 + BIT2; // P1.2 UCA0TXD output //------------ 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; // Enable the Transmit interrupt IE2 |= UCA0RXIE; // Enable the Receive interrupt _BIS_SR(LPM0_bits + GIE); } #pragma vector = USCIAB0TX_VECTOR __interrupt void TransmitInterrupt(void) { if(i < sizeof(inputbuffer)) { UCA0TXBUF = inputbuffer[i++]; } else { cmdflag = 0; i=0; } } #pragma vector = USCIAB0RX_VECTOR __interrupt void ReceiveInterrupt(void) { rxchar = UCA0RXBUF; inputbuffer[rxindex++] = rxchar; if(rxchar == 13) { cmdflag = 1; } IFG2 &= ~UCA0RXIFG; }
which seems to be triggering
USCIAB0TX_VECTOR
The purpose of the code is to receive a command word, put it into "inputbuffer" and once character 13 is received, it should raise "cmdflag" so the main loop can start transmitting it back again.
I've taken out some of this code to try and figure out what's going on, and I've put a breakpoint in the transmit interrupt, and it seems to be going off all the time.
I'm sure I've missed something quite obvious, as I'm new to all of this. Any help would be much appreciated!