This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2230 + SPI EEPROM(25C320) + ACCELEROMETER(ADXL362)

Other Parts Discussed in Thread: MSP430G2230, MSP430WARE

Hi everyone. First of all, i am new with msp430 microcontrollers and i have a project that i think it is hard for beginners but i must do it :)

I will take the data from accelerometer and write it to the eeprom. I will use msp430g2230. eeprom and accelerometer both are communicating with SPI. I must sample the data at least 1Hz. 

I just learned about registers and SPI and worked on msp430ware codes about SPI communication a little bit. Where can i start this project? What are your suggestions and do you know any source related to my project?

  • Break your project down into smaller steps. First, make the SPI work. Test it with the EEprom (it is the easier part). Check whether read and write work as intended. Then access the accelerometer (plain access should be no problem now, so you focus on the high-level protocol for setup and data reading).

    Then implement the read timing with a timer.

    Finally fuse all this with the proper glue logic.

    For the individual steps, you might find hints and maybe even demo code in this forum - use the search function. How do you eat an elephant? One bite after the other!

  • Thanks a lot. I will try your suggestions. But I have some questions now and I will have probably later :)

    1- msp430g2230 has 8 pins. 1vcc 1gnd 1sdi 1sdo 1test 1rst 1sclk and 1 left for the slave select. How can i select one of the devices at once with one pin?

    2- is it possible to do it without timer? I can develop it with timer later.

    3- adxl362 has 2 interrupt pins (INT1&INT2). should i use them and if so, how can i manage those interrupts pins with microcontroller pins?

    4- both accelerometer and eeprom need address byte to read or write. How can i know the address which i should start to read or write?

    I hope I dont seem boring or lazy :) I'm lost in datasheets and launch pad user manuel.

  • Halil İbrahim Kayıhan said:
    1- msp430g2230 has 8 pins. 1vcc 1gnd 1sdi 1sdo 1test 1rst 1sclk and 1 left for the slave select. How can i select one of the devices at once with one pin?

    Invert select signal for one of two devices using single NPN or n-fet transistor.

    Halil İbrahim Kayıhan said:
    2- is it possible to do it without timer? I can develop it with timer later.

    Yes. You can use delays in the code.

    Halil İbrahim Kayıhan said:
    3- adxl362 has 2 interrupt pins (INT1&INT2). should i use them and if so, how can i manage those interrupts pins with microcontroller pins?

    As you already said: you are running out of pins. Either use msp430 with more pins or don't use INT signals/services of accelerometer

    Halil İbrahim Kayıhan said:
    4- both accelerometer and eeprom need address byte to read or write. How can i know the address which i should start to read or write?

    By reading accelerometer and eeprom datasheet?

  • I have question: you will read accelerometer, do something with readings and write something to eeprom. Then what? How your msp430 will interact with outside world to tell results of measurements if you have no microcontroller pins to communicate, left?

  • Microcontroller will not tell the results outside world. The data will be retrieved later.

  • I made some codes but i don't understand how interrups working, it may seems wierd. For now, I worked without accelerometer to test the eeprom operations. Where am i doing wrong and right?

    #include <msp430.h>
    
    // 25C320 instructions
    #define READ  0x03
    #define WRITE 0x02
    #define WRDI  0x04
    #define WREN  0x06
    #define RDSR  0x05
    #define WRSR  0x01
    
    // msp430g2230 pins
    #define CS BIT2
    #define SCLK BIT5
    #define SDO BIT6
    #define SDI BIT7
    
    short int write_address = 0x0000;
    short int read_address = 0x0000;
    char data = 0x02;
    char reading;
    char writing;
    
    char write_eeprom( short int write_address, char data )
    {
        P1OUT &= ~CS;
        __delay_cycles(40);
        USISRL = WREN;       // WRITE ENABLE
        USICNT = 8;
        while( !(USIIFG) );  // USIIFG SETS WHEN USICNT BECOMES ZERO MEANING THAT TX COMPLETED(I AM NOT SURE)
        P1OUT |= CS;
        while( !(CS) );
        P1OUT &= ~CS;
        __delay_cycles(40);
            USISRL = WRITE;  // WRITE COMMAND
            USICNT = 8;
        while( !(USIIFG) );
            USICNT |= USI16B;
            USISR = write_address;  // USISRL AND USISRH IS 8BITS, USISR IS 16BITS
            USICNT = 16;
        while( !(USIIFG) );
            USICNT &= ~USI16B;
            USISRL = data;
            USICNT = 8;
        while( !(USIIFG) );
            P1OUT |= CS;
    
        return USISRL;
    }
    char read_eeprom( short int read_address )
    {
        P1OUT &= ~CS;
        __delay_cycles(40);
            USISRL = READ;
            USICNT = 8;
        while( !(USIIFG) );
            USICNT |= USI16B;
            USISR = read_address;
            USICNT = 16;
        while( !(USIIFG) );
            USICNT &= ~USI16B;
    
        return USISRL;
    }
    
    int main(void)
    {
      volatile unsigned int i;
    
      WDTCTL = WDTPW | WDTHOLD;             // Stop watchdog timer
    
      /* Initialization Code */
      P1REN = 0x1B;                         // Terminate unavailable Port1 pins (P1.0/1/3/4) properly
                                            // Config as Input with pull-down enabled
      BCSCTL3 |= LFXT1S_2;                  // Select VLO as low freq clock
      /* End Initialization Code */
    
      P1DIR |= CS | SCLK | SDO;         // Config available P1.x pins as outputs
      P1DIR &= ~SDI;
    
      USICTL0 |= USIPE7 | USIPE6 | USIPE5 | USIMST | USIOE; // Port, SPI master
      USICTL1 |= USIIE;                     // Counter interrupt, flag remains set
      USICKCTL = USIDIV_4 | USISSEL_2;      // /16 SMCLK
      USICTL0 &= ~USISWRST;                 // USI released for operation
    
      //MST_Data = 0x01;                      // Initialize data values
      //SLV_Data = 0x00;                      //
    
      //USISRL = MST_Data;                    // init-load data
      //USICNT = 8;                           // init-load counter
    
      for( i=0; i<4; i++ ){
          writing = write_eeprom( write_address, data );
      }
      for( i=0; i<4; i++ ){
          reading = read_eeprom( read_address );
      }
      __bis_SR_register(GIE);   // Enter LPM0 w/ interrupt
    }
    
    // USI interrupt service routine
    #pragma vector=USI_VECTOR
    __interrupt void universal_serial_interface(void)
    {
        if( USISR == write_address ){
            write_address++;
        }else if( USISR == read_address ){
            read_address++;
        }
    
      __delay_cycles(40);                   // Add time between transmissions to
                                            // make sure slave can process information
    }
    

  • Halil İbrahim Kayıhan said:
    Where am i doing wrong and right?

    To answer such kind of question someone needs to compile your code and debug it with eeprom connected. You have it all. So better you compile and debug, tell what happens as you expect and what's not, ask much more exact questions than "here's my code please check it and tell what's wrong"

  • You are right. At least, could you tell me how is the interrupt operations on my code?

  • Halil İbrahim Kayıhan said:
    You are right. At least, could you tell me how is the interrupt operations on my code?

    So you wrote random code of ISR and ask me to explain how it works? - I am asking because I can't believe you are asking such a question :)

  • Halil İbrahim Kayıhan said:
    could you tell me how is the interrupt operations on my code

    Is this a general question about interrupts, a more specific about interrupts on the MSP430, an USI-module specific question or a question specific for this very code?

    For the first, I’d recommend a basic class about processor design. Second and third are covered by the users guide and the last, well, when you wrote this code, you should know why you wrote it.
    However, if you need additional clarification about interrupt son the MSP430 in general or in the USI module in detail, you’re surely get it here. Just narrow down your question.

  • Thanks. I think I should deal with the interrupts later.

    In my write_eeprom function, USICNT keeps the number of bits which will be transferred and USIIFG is set when USICNT becomes zero. I used this to be sure that transmission of data or address is completed. But, for now this code is not working properly.

    Do you think that the mistake is in the write_eeprom function?

**Attention** This is a public forum