Dears Now I am not using interrupts to talk to the BNO055, but using this code. However, I always get the reception stuck after few tens or hundreds of runs at this check (while(!(IFG2 & UCA0RXIFG))), in the rx_receiver8bytes function or when I hit the pause and rerun the code (not always). When checking the buffer I find EE 07, which means bus over run. I tried to modify my code such that it do polling again (up to a max number of polls) when getting this error message but found it complicated. Would anyone help me with this. Many thanks #include #include char xLSB, xMSB, yLSB, yMSB, zLSB, zMSB; unsigned char setconfigmode[5]={0xAA, 0x00, 0x3D, 0x01, 0x00}; unsigned char setpowermode[5]={0xAA, 0x00, 0x3E, 0x01, 0x00}; unsigned char setAMGmode[5]={0xAA, 0x00, 0x3D, 0x01, 0x07}; unsigned char readACC[4]={0xAA, 0x01, 0x08, 0x06}; #define TXD BIT2 #define RXD BIT1 typedef unsigned char uint8_t; volatile uint8_t flag = 0; volatile uint8_t rx_counter = 0; volatile int ind1 = 0; volatile int ind3 = 0; volatile int ind2 = 0; volatile int ind4 = 0; #define BUFFER_SIZE 8 char RXbuffer[BUFFER_SIZE]; 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 } //¦----------------------------- Delay Function ---------------------------------------¦ void delay_ms(unsigned int ms) { unsigned int i; for (i = 0; i = 2 ) {//reset RX IFG (done above)/reset rx_counter/ ++flag rx_counter = 0; flag++; ind1++; } } /////////////////////////////UART receiver2///////////////////////// void uart_receiver8bytes(void){ while(!(IFG2 & UCA0RXIFG)); //wait until RX flag is set RXbuffer[rx_counter] = UCA0RXBUF; //copy byte from RXBUF & increment rx_counter rx_counter++; if( rx_counter >= 8 ) {//reset RX IFG (done above)/reset rx_counter/ ++flag rx_counter = 0; flag++; ind2++; } } //¦----------------------------- Main -------------------------------------------¦ void main(void) { set_UCS(); uart_init(); while(1){ //Make sure the BNO055 in config mode if(flag==0) uartSend(setconfigmode,5); while(flag==0){ uart_receiver2bytes(); } delay_ms(20); //Set the power mode if(flag==1) uartSend(setpowermode,5); while(flag==1){ uart_receiver2bytes(); } delay_ms(20); // //Set the AMG mode if (flag==2) uartSend(setAMGmode,5); while(flag==2){ uart_receiver2bytes(); } delay_ms(80); //Get ACC readings if (flag==3) uartSend(readACC,4); while(flag==3){ uart_receiver8bytes(); } delay_ms(10); //all done, reset the flag if (flag==4) { flag=0; } } }
↧