MSP430G2553 Interrupt Help - Page 1
Forum section: electronics / general

author: aep9690
author_rank: Regular Contributor
timestamp: May 12, 2013, 07:17:02 am
content: 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++ ProblemThe line referenced in the error code is:USCIAB0RX : { * ( .int07 ) } > INT07 type = VECT_INITThis 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 dataunsigned int transmit_data = 0x00; // Initialize receive data// ======================================================================================// FUNCTIONS// ======================================================================================void send_SPI(unsigned int DATA){// This function sends data via SPI to thingsP1OUT &= !BIT5; // Sets pin P1.4 to lowUCB0TXBUF = DATA; // Send address by putting in SPI bufferwhile(UCB0STAT & UCBUSY); // Wait for TX to finish (status byte received)P1OUT |= 0x10; // Sets pin P1.4 to high}// ======================================================================================// MAIN FUNCTION// ======================================================================================int main(void){// SETUPGrace_init(); // Activate Grace-generated configurationP1OUT = BIT5; // Set P1.4 as high// Repeatedly send a signal via SPItransmit_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.

author: andyturk
author_rank: Frequent Contributor
timestamp: May 12, 2013, 09:44:24 pm
content: 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:INT07 : origin = 0xFF8E, length = 0x0002PS. 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.

author: oPossum
author_rank: Super Contributor
timestamp: May 12, 2013, 11:03:17 pm
content: 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.

author: aep9690
author_rank: Regular Contributor
timestamp: May 12, 2013, 11:14:13 pm
content: 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?

author: andyturk
author_rank: Frequent Contributor
timestamp: May 12, 2013, 11:31:33 pm
content: Quote from: aep9690 on May 12, 2013, 11:14:13 pmHuh? UCA0RXIFG is a *flag*, not an interrupt vector. What happens when you run the code?Code:#pragma vector=USCI_A1_VECTOR__interrupt void USCI_A1_ISR() {switch (UCA1IV) {case USCI_UCRXIFG : // receive a character// your code goes herebreak;case USCI_UCTXIFG : // transmit a character// code goes herebreak;}}

author: MONODA
author_rank: Contributor
timestamp: May 13, 2013, 05:16:02 am
content: 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.

author: aep9690
author_rank: Regular Contributor
timestamp: May 13, 2013, 05:49:55 am
content: I am going to try doing it manually.I still have a big question, when I use#pragma vector = USCI_A0_VECTORIt says it is undefined, it says this when I useUSCI_A1_VECTORas well. Do I need to include some other library in order to do this?

author: andyturk
author_rank: Frequent Contributor
timestamp: May 13, 2013, 06:44:31 am
content: Quote from: aep9690 on May 13, 2013, 05:49:55 amWhich "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.

author: aep9690
author_rank: Regular Contributor
timestamp: May 13, 2013, 07:03:08 am
content: 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.

author: MONODA
author_rank: Contributor
timestamp: May 21, 2013, 07:13:38 pm
content: 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!