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.

msp430G2x31 SPI eeprom

Other Parts Discussed in Thread: MSP430G2231

Hi there,

I'm trying to develop a interface SPI between a msp430G2231 and a serial SPI eeprom ( in this case a 25LC320).

I have tried all the similar code that is inside this forum, but until now I didn't have any results.

Can anyone help me?

Regards,

Ralph

  • If the available help in the forum didn't help you, I don't know what else could help you, as this topic has been discussed more than a few times.

    However, the database search engine was buggy since the site update a few days ago (and maybe still is). Maybe you should give it another try :)

  • Have you already tried to connect this SPI EEPROM to another chip?

    SPI is fairly easy but I spent two days because I thought I was not getting responses but the chip was wrong connected :)

  • Dear Kazola and Jens, thanks

     Jens, you're correct, the search within database of the TI in different days and/or times gives me different results.

    At this moment I'm making new ones, I hope that I foun something that is missing to me.

    Kazola, I didn´t test yet, this spi eeprom in another micro. I'm seing the data that I send to spi (clck and so) and it seems all rigth.

    I'm making the write as is refer in eeprom datasheet :

    CS low - WREN (command) -CS high;

    CS low - WR (command), 8 bits LSB ADDR, 8 bits MSB ADDR,  8 bit data (I wish to write) - CS high;

    In the read part (I think I migth have a little bug)

    CS low - READ (command),  8 bits LSB ADDR, 8 bits MSB ADDR,  8 bit data (I wish to read) - CS high;

    The read of the 8 bits that I want at the specified addre I do the following:

          USISRL = 0xFF;                                    // send dummy byte to receive data
          USICNT = 8;                                          // init-load counter
          while((USICTL1 & USIIFG) != 0x01); // wait until something receives. This also means that sending is completed
          USICTL1 &= ~USIIFG;                         // Clear USI interrupt flag
          data_read = USISRL;                           // data received from the SPI

    This is done because I have only USI, therefore only one buffer for reading and writing

    I think I'm not missing anything.

    I will double check again everything.

    Regards

    CS

  • Ralph said:
          while((USICTL1 & USIIFG) != 0x01); // wait until something receives. This also means that sending is completed

    I didn't check. Sure that USIIFG is 0x01? Else this will loop forever. Also, if USUIFG isn't in USICFG1 at all :)

    Why not doing

    while (USICTL1 & USIIFG)!=USIIFG);
    or
    while (!(USICTL1&USIIFG));

    ... well, I just checked, and it is okay.

    The write and read sequence seems okay. TH eonly hting that might be a problem is the perhaps required delay between CS low and start of the SPI transfer. Some slaves require some setup time.

    How do you init and handle CS? Maybe the problem is not the transfer itself, but the handshaking/synchronization

  • Is something like:

    void init(void)
    {
        P1SEL &= ~(Mem_CS);                //I/O
        P1DIR |= (Mem_CS);                 // OUTPUT
        P1OUT |= Mem_CS;                   // DISABLE CS
        USICTL0 |= USISWRST;               // Keep peripheral in reset state
        USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE + USISWRST;// Port, SPI master
        USICTL1 |= USIIE;                               // Counter interrupt, flag remains set
        USICKCTL = USISSEL_2 + USICKPL + USIDIV_1;           // SCLK = SMCLK
        USICTL0 &= ~USISWRST;                     // USI released for operation
    }



    the write function, after your suggestion, is:

    void write_spi_func(char val)
    {
        USISRL = val;                      // command/address/data I wish to write in spi
        USICNT = 8;                        // init-load counter
        while(!(USICTL1&USIIFG));           // wait until something receives. This also means that sending is completed
    }
    
    char read_spi_func(void)
    {
        USISRL = 0xFF;                     // command/address/data I wish to write in spi
        USICNT = 8;                        // init-load counter
        while(!(USICTL1&USIIFG));           // wait until something receives. This also means that sending is completed
        return USISRL;
    }
    
    void write_spi_procedure(void)
    {
        P1OUT & =~Mem_CS;                   // Enable CS
        __delay_cycles(5);                    // minimun delay at 1MHz clock
        write_spi_func(WREN);
        __delay_cycles(5);
        P1OUT |= Mem_CS;                    // DISABLE CS
        __delay_cycles(5);
        P1OUT & =~Mem_CS;                   // Enable CS
        __delay_cycles(5);
        write_spi_func(WRITE);
        write_spi_func(ADDR);
        write_spi_func(ADDR >> 8);
        write_spi_func(my_data);            // data I wish to write in the defined ADDRES
        __delay_cycles(5);
        P1OUT |= Mem_CS;                    // DISABLE CS
    }
    
    void read_spi_procedure(void)
    {
        P1OUT & =~Mem_CS;                   // Enable CS
        __delay_cycles(5);
        write_spi_func(READ);
        write_spi_func(ADDR);
        write_spi_func(ADDR >> 8);
        my_data = read_spi_func();
        __delay_cycles(5);
        P1OUT |= Mem_CS;                    // DISABLE CS
    }

    Regards

**Attention** This is a public forum