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.

Problem MSP430G2553+25LC1024(SPI EEPROM)

Other Parts Discussed in Thread: MSP430G2553

Hai,

     Iam trying to interface  serial EEPROM 25LC1024 with msp430G2553

Firstly I write data in my EEPROM IC with  PIC16f877a(this is used because of  confirmation)

then write a code for reading the known location but it return  wrong data sometimes 0x03 sometimes 0xFF ,FEetc

Here P1.6 is used for CS

Please guide me

below is my code

#include <msp430g2553.h>

unsigned int received_ch;
unsigned int address=0x01;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

P1OUT |= BIT6;//cs
P1DIR |= BIT6;
P1REN|=BIT6;
P1SEL = BIT1 | BIT2 | BIT4;
P1SEL2 = BIT1 | BIT2 | BIT4;

UCA0CTL1 = UCSWRST;
UCA0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x02; // /2
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
P1OUT|=BIT6;
P1OUT &= (~BIT6); // Select Device
UCA0TXBUF =0x03; //Read enable of EEPROM IC 25LC1024//http://ww1.microchip.com/downloads/en/devicedoc/22064a.pdf
_delay_cycles(10000);
////24 bit address
while (!(IFG2 & UCA0TXIFG)); //24 bit address
UCA0TXBUF =0x00;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF =0x00;
while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF =address;
// while (!(IFG2 & UCA0RXIFG)); // USCI_A0 RX Received?
received_ch = UCA0RXBUF; // Store received data
P1OUT |= (BIT6); // Unselect Device
while(1);//debugg
}

  • You have a sequence problem in your code.

    When you finally write “address” to TXBUF, this means that the previous 0x00 has just started sending (moved from TXBUF to output register, which caused TXIFG to be set).

    And at this moment, RXIFG is already set because you already received something all the time while sending. What you read from RXBUF is what was received while sending the second last 0x00.
    So after writing address to TXBUF, you need to write another dummy byte during which you will receive the answer to the read request.
    Then you have to read and discard the byte form RXBUF that you received during the last 0x00, then wait for the next and again discard it (as it is what you received while sending the address. Then the next one is your answer.

    The combination of synchronous bi-directional transfer and double-buffering might be confusing at first. Draw yourself a timing diagram and it will become obvious.

**Attention** This is a public forum