Quantcast
Channel: Wireless Connectivity
Viewing all articles
Browse latest Browse all 116964

Forum Post: cc2540 interrupt routine crashes.

$
0
0

Hi,

maybe soemeone has any ideas about why, my interrupt routine crashes every time the interrupt is started. took the code from a sample, but had to adjust  some variables to mine so its suitable to me. here is the code i use.

// Size of allocated UART RX/TX buffer (just an example)
#define SIZE_OF_UART_RX_BUFFER   50
#define SIZE_OF_UART_TX_BUFFER   SIZE_OF_UART_RX_BUFFER

// Test definitions
#define UART_TST_MODE_RX
//#define UART_TST_MODE_TX


/********************* VARIABLES *********************/

// Buffer+index for UART RX/TX.
static uint8 __xdata uartRxBuffer[SIZE_OF_UART_RX_BUFFER];
static uint8 __xdata uartTxBuffer[SIZE_OF_UART_TX_BUFFER] = UART_TEST_DATA;

static uint16 __xdata uartTxIndexR;             // Zeiger für der auf das zu sendende zeigt
static uint16 __xdata uartTxIndexW;             // Zeiger der das zu sendende in den Buffer schreibt
static uint16 __xdata uartRxIndexR;             // Zeiger der den empfangenen Buffer liest
static uint16 __xdata uartRxIndexW;             // Zeiger der das zu lesende in den Buffer schreibt.

// Variable for UART packet monitoring.
//static uint8 __xdata uartPktReceived = 1;

// Prototype for local functions.
void uart1StartRxForIsr(void);
void uart1StartTxForIsr(void);


/********************* Transfer UART data *********************/

/********************* LOCAL FUNCTIONS *********************/

/***********************************************************************************
*           UART1_TX_ISR

* Ringbuffer mit 2Zeigern R und W
1teil.  R:    Lesezeiger der aus dem Buffer liest
2teil.  W:    Schreibzeiger der in den Buffer schreibt.
*/

#pragma vector = UTX1_VECTOR
__interrupt void UART1_TX_ISR(void)
{
    // Clear UART1 TX Interrupt Flag (IRCON2.UTX0IF = 0).
    UTX1IF = 0;

    uartTxIndexR++;
    if (uartTxIndexR == SIZE_OF_UART_TX_BUFFER)
    {
      uartTxIndexR = 0;
    }
   
    // If no UART byte left to transmit, stop this UART TX session
    if (uartTxIndexR != uartTxIndexW)
    {
      // Send next UART byte.
      U1DBUF = uartTxBuffer[uartTxIndexR];
    }
}

/***********************************************************************************
*           UART1_RX_ISR
*
*       Function which completes the UART receive session. */

#pragma vector = URX1_VECTOR
__interrupt void UART1_RX_ISR(void)
{
    // Clear UART1 RX Interrupt Flag (TCON.URX0IF = 0).

    URX1IF = 0;
    
lcd_data ('i');  // only for testing if the interrupt is set

//
////    //Receive Char into Buffer
////    uartRxBuffer[uartRxIndexW] = U1DBUF;
////    
////    uartRxIndexW++;                               //Buffer hochzählen
////    
////    if (uartRxIndexW == SIZE_OF_UART_RX_BUFFER);   //Zeiger/Buffer Ende erreicht?
////    {
////      uartRxIndexW =0;
////    }

}

/**************************** Boolean RX available? *******************************/
bool RXavailable ()
{
  if (uartRxIndexW != uartRxIndexR)
    return true;
      else
        return false;
}

/**************************** RX Read *************************************/
char RXread ()
{
  char RXchar;
  RXchar = uartRxBuffer[uartRxIndexR];
  uartRxIndexR++;
    
   if (uartRxIndexR == SIZE_OF_UART_RX_BUFFER);
    {
      uartRxIndexR =0;
    }
    return RXchar;
}

regards, 

Odin


Viewing all articles
Browse latest Browse all 116964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>