Regarding using a flag, I did this #include "msp430g2553.h" #include char xLSB, xMSB, yLSB, yMSB, zLSB, zMSB; unsigned char setconfigmode[5]={0xAA, 0x00, 0x3D, 0x01, 0x00}; #define TXD BIT2 #define RXD BIT1 #define BUFFER_SIZE 8 typedef unsigned char uint8_t; volatile uint8_t rx_counter = 0; volatile uint8_t flag = 0; char RXbuffer[BUFFER_SIZE]; //unsigned int bufferIndex = 0; void set_UCS() {//------------------- Configure the Clocks -------------------// WDTCTL = WDTPW + WDTHOLD; // Stop the Watch dog DCOCTL = 0; // Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_12MHZ; // Set range DCOCTL = CALDCO_12MHZ; // Set DCO step + modulation // DCO -> SMCLK (Default) IE1 &= 0xFD; /* Disable UCS interrupt */ return; } void setMSP430Pins() {//--------- Setting the UART function for P1.1 & P1.2 --------// P1SEL |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD P1SEL2 |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD return; } void uart_init(void){ P1SEL |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD P1SEL2 |= RXD + TXD ; // P1.1 = RXD, P1.2=TXD UCA0CTL1 = UCSWRST; // Set UCSWRST (hold USCI in Reset state) UCA0CTL1 |= UCSSEL_2; // CLK = SMCLK // ------------ Configuring the UART(USCI_A0) ----------------// // 115200 BAUD, CLK=12MHz UCA0BR0 = 6; UCA0BR1 = 0; // //*ours: UCBRF = 8, UCBRS = 0, UCOS16 = 1 // // BITS| 7 6 5 4 | 3 2 1 | 0 | // UCAxMCTL = | UCBRFx | UCBRSx | UCOS16 | UCA0MCTL = 0x81; //this works fine UCA0CTL1 &= ~UCSWRST; // Clear UCSWRST to enable USCI_A0-UART UCA0CTL1 &= ~UCSYNC; IFG2 |= UCA0TXIFG; // preset IFG flag always left on } /////////////////////////UART send multiple Bytes//////////////////// void uartSend(unsigned char *pucData, unsigned char ucLength) { while(ucLength) { // Wait for TX buffer to be ready for new data while(!(IFG2 & UCA0TXIFG));//check if not set //if set, TX interrupt is pending // Push data to TX buffer UCA0TXBUF = *pucData; // Update variables ucLength--; //-- length of data left pucData++; //shift pointer } // Wait until the last byte is completely sent while(UCA0STAT & UCBUSY); //UCBUSY indicates if USCI transmitting or receiving } //////////////////////////////UART receive multiple Bytes/////// void USCI_ISR( void ) { RXbuffer[rx_counter] = UCA0RXBUF; if( ++rx_counter >= RXbuffer[1] ) { IE2 &= ~UCA0RXIE; //Disable RX intterupt rx_counter = 0; flag = 1; } } //¦----------------------------- Delay Function ---------------------------------------¦ // This function will give us 1ms wait time, so for getting 10 ms, // then delay_ms(10) will give 10ms and delay_ms(100) will give 100ms void delay_ms(unsigned int ms) { unsigned int i; for (i = 0; i<= ms; i++) __delay_cycles(6000); // 6000 will give us 1ms } //¦----------------------------- Main -------------------------------------------¦ void main(void) { set_UCS(); uart_init(); _BIS_SR(GIE); // Enable the global interrupt IE2 |= UCA0RXIE; // Enable the Receive interrupt //Make sure the BNO055 in config mode uartSend(setconfigmode,5); // while (1) // { if (flag) { xMSB = RXbuffer[2]; xLSB = RXbuffer[3]; yMSB = RXbuffer[4]; yLSB = RXbuffer[5]; zMSB = RXbuffer[6]; zLSB = RXbuffer[7]; flag=0; IFG2 = ~UCA0RXIFG; IE2 |= UCA0RXIE; // Enable the Receive interrupt } // } delay_ms(20); // delay_ms(20) } I see the packet coming from the BNO055 via a TTL RS 232 cable and Termite. However, seems my RX ISR still not working fine as I can not see the packet there. I only see the last byte of it when checking the RXBUF. Would you please help me with this? Thank you
↧