Hello
I am talking to an IMU (BNO05) via MSP430 launchpad. they are connected via the UART. Below is the code that I use to read the acceleration data. However, when I press the pause
buttom then I get ABNORMAL PROGRAM TERMINATION, given that I am getting the data. Why is that? is it because I am using the __bic_SR_register_on_exit(LPM0_bits); in the
RX ISR and __bic_SR_register_on_exit(LPM3_bits+GIE); in the main?
Another question:
If I used while(1) in the main as below, i.e., no __bis_SR_register(LPM0_bits); in the RX ISR, then how will the program leave the ISR (based on what condition)?
Thank you
#include "msp430g2553.h"
char xLSB;
char xMSB;
char yLSB;
char yMSB;
char zLSB;
char zMSB;
typedef struct uart // UART
{ char *bufTXpnt; // UART TX buffer pointer
unsigned int TXbuflen; // the lenght of TX block
char *bufRXpnt; // UART RX buffer pointer
unsigned int RXbuflen; // the lenght of RX block
char TXbuffer[20];
char RXbuffer[20];
} uartstruct;
void setMSP430Pins() {
//--------- Setting the UART function for P1.1 & P1.2 --------//
P1SEL |= BIT1 + BIT2; // P1.1 UCA0RXD input
P1SEL2 |= BIT1 + BIT2; // P1.2 UCA0TXD output
return;
}
void set_UCS() {
//------------------- Configure the Clocks -------------------//
// DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_12MHZ; // Set range
DCOCTL = CALDCO_12MHZ; // Set DCO step + modulation
}
void uart_init(void){
IE2 &= ~(UCA0TXIE | UCA0RXIE | UCB0TXIE | UCB0RXIE); // Disable all USCIx0 TX & RX interrupts
UCA0CTL1|=UCSWRST;
UCA0CTL1|= UCSSEL_2;
//------------ Configuring the UART(USCI_A0) ----------------//
// 115200 BAUD, CLK=12MHz
UCA0BR0 = 6; //this is working
UCA0BR1 = 0; //this is working
//*ours: UCBRF = 8, UCBRS = 0, UCOS16 = 1
// UCBRF = 11, 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
IFG2 |= UCA0TXIFG; // preset IFG flag always left on
IE2|=UCA0RXIE;
}
#define TXSTRING(pnt) (TXdata((pnt), sizeof(pnt)-1)) // cool macro to get string and string len
uartstruct uart; // declare a struct from typedef uartstruct
void TXdata( char* pnt, unsigned int len){
uart.bufTXpnt = pnt;
uart.TXbuflen = len;
uart.bufRXpnt = uart.RXbuffer; // reset it to beginning of ram buffer
IE2 |= UCA0TXIE + UCA0RXIE; // enable USCI_A0 TX & RX interrupt
}
//¦----------------------------- US0TX ISR ---------------------------------------¦
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCIAB0TX(void) // Shared A0/B0 TX IRQ vector
{
if (IFG2 & UCA0TXIFG){ // check for UART TX
if (uart.TXbuflen){ // if not zero
UCA0TXBUF = *uart.bufTXpnt++;
--uart.TXbuflen;
}
else IE2 &= ~UCA0TXIE; // suspend IE if zero
}
else IFG2 &= ~UCA0TXIFG; // clear a false UCB0 trigger
}
//¦----------------------------- US0RX ISR ---------------------------------------¦
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIAB0RX(void) // A0/B0 RX IRQ vector
{
if (IFG2 & UCA0RXIFG){ // check for UART RX
*uart.bufRXpnt++ = UCA0RXBUF; // copy data byte
if (uart.bufRXpnt == uart.RXbuffer+8 && uart.RXbuffer[0]==0xBB) // got 8 bytes in yet? <<<<
uart.RXbuflen=uart.RXbuffer[1];
__bic_SR_register_on_exit(LPM0_bits); // wakeup main <<<<
}
else IFG2 &= ~UCA0RXIFG;
}
//¦----------------------------- Main -------------------------------------------¦
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop the Watch dog
setMSP430Pins();
set_UCS();
uart_init();
// The following is OK to get the sensors activated and getting the data
TXSTRING("\xAA\x00\x3E\x01\x00"); // Normal Power mode
TXSTRING("\xAA\x00\x3D\x01\x07"); // Send this to the BNO055 to set up the AMG mode
TXSTRING("\xAA\x01\x08\x06");
__bis_SR_register(LPM3_bits + GIE);
}
#include "msp430g2553.h"
char xLSB;
char xMSB;
char yLSB;
char yMSB;
char zLSB;
char zMSB;
typedef struct uart // UART
{ char *bufTXpnt; // UART TX buffer pointer
unsigned int TXbuflen; // the lenght of TX block
char *bufRXpnt; // UART RX buffer pointer
unsigned int RXbuflen; // the lenght of RX block
char TXbuffer[20];
char RXbuffer[20];
} uartstruct;
void setMSP430Pins() {
//--------- Setting the UART function for P1.1 & P1.2 --------//
P1SEL |= BIT1 + BIT2; // P1.1 UCA0RXD input
P1SEL2 |= BIT1 + BIT2; // P1.2 UCA0TXD output
return;
}
void set_UCS() {
//------------------- Configure the Clocks -------------------//
// DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_12MHZ; // Set range
DCOCTL = CALDCO_12MHZ; // Set DCO step + modulation
}
void uart_init(void){
IE2 &= ~(UCA0TXIE | UCA0RXIE | UCB0TXIE | UCB0RXIE); // Disable all USCIx0 TX & RX interrupts
UCA0CTL1|=UCSWRST;
UCA0CTL1|= UCSSEL_2;
//------------ Configuring the UART(USCI_A0) ----------------//
// 115200 BAUD, CLK=12MHz
UCA0BR0 = 6; //this is working
UCA0BR1 = 0; //this is working
//*ours: UCBRF = 8, UCBRS = 0, UCOS16 = 1
// UCBRF = 11, 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
IFG2 |= UCA0TXIFG; // preset IFG flag always left on
IE2|=UCA0RXIE; ///today added
}
#define TXSTRING(pnt) (TXdata((pnt), sizeof(pnt)-1)) // cool macro to get string and string len
uartstruct uart; // declare a struct from typedef uartstruct
void TXdata( char* pnt, unsigned int len){
uart.bufTXpnt = pnt;
uart.TXbuflen = len;
uart.bufRXpnt = uart.RXbuffer; // reset it to beginning of ram buffer
IE2 |= UCA0TXIE + UCA0RXIE; // enable USCI_A0 TX & RX interrupt
}
//¦----------------------------- US0TX ISR ---------------------------------------¦
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCIAB0TX(void) // Shared A0/B0 TX IRQ vector
{
if (IFG2 & UCA0TXIFG){ // check for UART TX
if (uart.TXbuflen){ // if not zero
UCA0TXBUF = *uart.bufTXpnt++;
--uart.TXbuflen;
}
else IE2 &= ~UCA0TXIE; // suspend IE if zero
}
else IFG2 &= ~UCA0TXIFG; // clear a false UCB0 trigger
}
//¦----------------------------- US0RX ISR ---------------------------------------¦
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIAB0RX(void) // A0/B0 RX IRQ vector
{
if (IFG2 & UCA0RXIFG){ // check for UART RX
*uart.bufRXpnt++ = UCA0RXBUF; // copy data byte
if (uart.bufRXpnt == uart.RXbuffer+8 && uart.RXbuffer[0]==0xBB) // got 8 bytes in yet? <<<<
uart.RXbuflen=uart.RXbuffer[1];
}
else IFG2 &= ~UCA0RXIFG;
}
//¦----------------------------- Main -------------------------------------------¦
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop the Watch dog
//uart.RXbuflen=8;
setMSP430Pins();
set_UCS();
uart_init();
while(1){
// The following is OK to get the sensors activated and getting the data
TXSTRING("\xAA\x00\x3E\x01\x00"); // Normal Power mode
TXSTRING("\xAA\x00\x3D\x01\x07"); // Send this to the BNO055 to set up the AMG mode
TXSTRING("\xAA\x01\x08\x06");
__bis_SR_register(LPM3_bits + GIE);
}
}