Author Topic: MSP430G2553 Interrupt Help  (Read 8367 times)

0 Members and 1 Guest are viewing this topic.

Offline aep9690Topic starter

  • Regular Contributor
  • *
  • Posts: 67
  • Country: us
MSP430G2553 Interrupt Help
« on: May 12, 2013, 07:17:02 am »
I am trying to write some code to send and receive data from a 4 wire SPI bus on a TI launchpad.  I am able to send data easily enough, however I am having problems with the receiving.  I want to write an interrupt that will place the data from the receiving buffer into a variable when the interrupt flag is asserted.  I used code composers GRACE tool to setup to peripheral interface.  I attached the pictures of the SPI interface setup.  The problem I am having is that code composer won't build my code.  I am getting the following error:

program will not fit into available memory.  placement with alignment fails for section "USCIAB0RX" size 0x4 .  Available memory ranges:   lnk_msp430g2553.cmd   line 84   /BATT_MANAGE_V1.0   C/C++ Problem

The line referenced in the error code is:
USCIAB0RX    : { * ( .int07 ) } > INT07 type = VECT_INIT

This is my code:

    /*
     * PIN ASSIGNMENTS:
     * P1.4 = CS0 (Active low)
     * P1.5 = CLK
     * P1.6 = MISO
     * P1.7 = MOSI
     *
     * SYSTEM CONFIG:
     * 1MHz internal clock and subsystem clock
     * SPI bus on the USB0 Register
     * SPI receiver interrupt
     * Watchdog timer is off
     */

// ======================================================================================
// LIBRARIES
// ======================================================================================
#include <msp430g2553.h> //Standard MSP430 library
#include <ti/mcu/msp430/Grace.h> // Code generated by GRACE for system setup

// ======================================================================================
// VARIABLES
// ======================================================================================
    unsigned int receive_data = 0x00;  // Initialize transmit data
    unsigned int transmit_data = 0x00; // Initialize receive data

// ======================================================================================
// FUNCTIONS
// ======================================================================================
void send_SPI(unsigned int DATA){
   // This function sends data via SPI to things
   P1OUT &= !BIT5; // Sets pin P1.4 to low
   UCB0TXBUF = DATA; // Send address by putting in SPI buffer
   while(UCB0STAT & UCBUSY); // Wait for TX to finish (status byte received)
   P1OUT |= 0x10; // Sets pin P1.4 to high
}

// ======================================================================================
// MAIN FUNCTION
// ======================================================================================
int main(void)
{
   // SETUP
    Grace_init();        // Activate Grace-generated configuration
    P1OUT = BIT5;        // Set P1.4 as high

    // Repeatedly send a signal via SPI
    transmit_data = 0xFC;
    while(1){
       send_SPI(transmit_data);
       _delay_cycles(1000); //Delay for 1 ms
    }

}

// ======================================================================================
// INTERRUPT
// ======================================================================================
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCIB0RX_ISR (void){
   // UCB0RXIFG is the interrupt register for the B0 received buffer.
    receive_data = UCB0RXBUF;
}


To me this means that the program will not fit into the memory that is available in the chip.  However it has 14KB and this is the entire program so I don't think that is the problem.  I am still really new at microcontrollers so any help will be appreciated.
« Last Edit: May 12, 2013, 09:35:57 pm by aep9690 »
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: MSP430G2553 Interrupt Help
« Reply #1 on: May 12, 2013, 09:44:24 pm »
The problem isn't with your C code, it's with the linker file (lnk_msp430g2553.cmd). Line 84 is telling the linker to put your interrupt handler in a 4-byte memory segment called INT07. That's the only place the linker can put that symbol, and chances are that INT07 segment has never been defined in the linker file. The definition is probably there already, but it might be commented out.

Here's an example from a MSP430 project I'm working on (but using a f5528, so the actual vectors might not be the same as yours):

Code: [Select]
    INT07                   : origin = 0xFF8E, length = 0x0002

PS. It seems strange that your USCIAB0RX section is 4 bytes long. Maybe it's supposed to contain both the RX vector and a TX vector? If the RX vector appears at the lower memory address you'll be OK, but if not, you may want to define a dummy TX vector too just to be sure.
« Last Edit: May 12, 2013, 09:48:05 pm by andyturk »
 

Offline oPossum

  • Super Contributor
  • ***
  • Posts: 1417
  • Country: us
  • Very dangerous - may attack at any time
Re: MSP430G2553 Interrupt Help
« Reply #2 on: May 12, 2013, 11:03:17 pm »
That error occurs when there are 2 or more handlers for one ISR. Make sure GRACE is not providing ISR stubs.

I don't use GRACE because the MSP430 peripherals are easy to use and it seems GRACE causes more problems than is solves.
 

Offline aep9690Topic starter

  • Regular Contributor
  • *
  • Posts: 67
  • Country: us
Re: MSP430G2553 Interrupt Help
« Reply #3 on: May 12, 2013, 11:14:13 pm »
It isn't giving me any errors now so I think I might have fixed it.  But I would still like to post it here in case all I did was change it so it wouldn't give me an error.  This is the new interrupt code, everything else is the same.

#pragma vector = UCA0RXIFG
__interrupt void USCI_A0_ISR (void){
   receive_data = UCA0RXBUF; // UCA0RXIFG is the interrupt register for the A0 received buffer.
    IFG2 &= BIT0; // Clear the interrupt flag on the receive buffer of A0
}

From what I understand about microcontrollers, I am triggering the interrupt when the receiving buffer interrupt flag goes high.  When this happens the USCI_A0_ISR interrupt executes, when this happens I load the byte from the receiving buffer into receive data and then clear the interrupt flag.  Is this correct?
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: MSP430G2553 Interrupt Help
« Reply #4 on: May 12, 2013, 11:31:33 pm »
It isn't giving me any errors now so I think I might have fixed it.  But I would still like to post it here in case all I did was change it so it wouldn't give me an error.  This is the new interrupt code, everything else is the same.

#pragma vector = UCA0RXIFG
__interrupt void USCI_A0_ISR (void){
   receive_data = UCA0RXBUF; // UCA0RXIFG is the interrupt register for the A0 received buffer.
    IFG2 &= BIT0; // Clear the interrupt flag on the receive buffer of A0
}

From what I understand about microcontrollers, I am triggering the interrupt when the receiving buffer interrupt flag goes high.  When this happens the USCI_A0_ISR interrupt executes, when this happens I load the byte from the receiving buffer into receive data and then clear the interrupt flag.  Is this correct?
Huh? UCA0RXIFG is a *flag*, not an interrupt vector. What happens when you run the code?


Code: [Select]
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR() {
  switch (UCA1IV)  {
  case USCI_UCRXIFG : // receive a character
    // your code goes here
    break;

  case USCI_UCTXIFG : // transmit a character
    // code goes here
    break;
 }
}
 

Offline MONODA

  • Contributor
  • Posts: 22
Re: MSP430G2553 Interrupt Help
« Reply #5 on: May 13, 2013, 05:16:02 am »
andyturk is right, that is odd.

I would also suggest against using GRACE. It is definitely worthwhile to configure the peripherals manually. It doesn't take much more work than using GRACE does and it eliminates the added complexity (places where things can go wrong) that GRACE adds.

Also, looking at example code should help a lot. If you haven't already, download the MSP430ware package, it has a lot of example code.
 

Offline aep9690Topic starter

  • Regular Contributor
  • *
  • Posts: 67
  • Country: us
Re: MSP430G2553 Interrupt Help
« Reply #6 on: May 13, 2013, 05:49:55 am »
I am going to try doing it manually.

I still have a big question, when I use

#pragma vector = USCI_A0_VECTOR

It says it is undefined, it says this when I use USCI_A1_VECTOR as well.  Do I need to include some other library in order to do this?
 

Offline andyturk

  • Frequent Contributor
  • **
  • Posts: 895
  • Country: us
Re: MSP430G2553 Interrupt Help
« Reply #7 on: May 13, 2013, 06:44:31 am »
I am going to try doing it manually.

I still have a big question, when I use

#pragma vector = USCI_A0_VECTOR

It says it is undefined, it says this when I use USCI_A1_VECTOR as well.  Do I need to include some other library in order to do this?
Which "it" is complaining? I'll guess and say it's probably the compiler. Are you including the right header files for your mcu? Look in the /ti/ccsv5/ccs_base/msp430/include for any file with g2553 in the name. There should be a couple of linker files (.cmd) and a .h for the compiler. Assuming your build is set up correctly, those files tell the compiler which resources it can use.

It could be you're using code which was written for a different chip with different peripherals. E.g., the ISR skeleton I posted earlier is for a UART on a f5528. Your g2553 doesn't have the same peripherals or interrupt vectors, so you'll have to tweak the code a little before it'll work.
 

Offline aep9690Topic starter

  • Regular Contributor
  • *
  • Posts: 67
  • Country: us
Re: MSP430G2553 Interrupt Help
« Reply #8 on: May 13, 2013, 07:03:08 am »
Thank you very much, including the other header files did the trick.

Thanks everyone for bearing with me, I'm still very new at embedded systems.
 

Offline MONODA

  • Contributor
  • Posts: 22
Re: MSP430G2553 Interrupt Help
« Reply #9 on: May 21, 2013, 07:13:38 pm »
If you open up the header file hyou should see a list of the interrupt vectors at the very bottom. Check that file when the compiler complains about something being undefined -- you might have spelt it wrong.

Good luck!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf