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.

SPI Problem with Flash Communication

Hello all,

I am attempting to work with a Flash Memory chip, and have so far only had negative results.  I am attempting to work with the MSP430FR5728 by TI, and the S70FL01GS by Spansion. 

I am trying to perform the Read ID, however all of my attempts have resulted in either FFh or 00h.

I have been using a logic analyzer to see the results, and will post a screenshot below:

For the life of me I am not sure what I am doing wrong.  I have read through the datasheets, and made sure the voltages and configurations matched that of what was needed.  I even made sure that the circuit was wired correctly, as can be seen in the figure below.


I believe that everything is wired correctly for this simple task of Read ID.  Below is also the code I wrote using IAR Embedded Workbench

/***********************************************************
Code Goal:  Write a Byte of data to address of S70FL01GS.
After which, read the same address to prove that the
data byte was properly recorded to the Flash Memory.  

Read ID:  Datasheet says send command and then 3 dummy bytes

Write:  Datasheet states need to Enable Write, send 3 address 
bytes, and requires the READ FLAG STATUS REGISTER command being 
issued with at least one byte output.

Read: send 3 address bytes of where want to read

Program: IAR Embedded Workbench IDE
MCU: MSP430FR5728
SPI: B0 mode selected from device
UCB0SIMO: P1.6
UCB0S0MI: P1.7
UCB0CLK: P2.2
CSn 1: PJ.2
CSn 1: PJ.4

***********************************************************/

#include "string.h"
#include "msp430.h"
#include <stdio.h>

char b1 = 0x01;          // Flash Addr Part 1 for Write
char b2 = 0x02;          // Flash Addr Part 2 for Write
char b3 = 0x01;          // Flash Addr Part 3 for Write

char b4 = 0x01;          // Flash Addr Part 1 for Read
char b5 = 0x02;          // Flash Addr Part 2 for Read
char b6 = 0x01;          // Flash Addr Part 3 for Read

char Q;
char T;

unsigned char RXData =0;
unsigned char TXData;

char Readout[20];

/***************************************************
                     Flash Code
***************************************************/

char FlashByte(char S){       // General FlashByte Transmit
  __delay_cycles(60);
  UCB0TXBUF = S;
  while (!(UCB0IFG & UCTXIFG));
  S = UCB0RXBUF;
  while (!(UCB0IFG & UCRXIFG));
  return S;
}

char FlashComID(char S){       // Read ID command 9Fh
  PJOUT &= ~ BIT4;
  //while (!(UCB0IFG & UCTXIFG));
  UCB0TXBUF = S;                // Send Command
  while (!(UCB0IFG & UCTXIFG));
  while (!(UCB0IFG & UCRXIFG));
  UCB0TXBUF = 0x00;             // Dummy 1
  while (!(UCB0IFG & UCTXIFG));
  Readout[0] = UCB0RXBUF;       // Read 1
  while (!(UCB0IFG & UCRXIFG));
  UCB0TXBUF = 0x00;             // Dummy 2
  while (!(UCB0IFG & UCTXIFG));
  Readout[1] = UCB0RXBUF;       // Read 2
  while (!(UCB0IFG & UCRXIFG));
  UCB0TXBUF = 0x00;             // Dummy 3
  while (!(UCB0IFG & UCTXIFG));
  Readout[2] = UCB0RXBUF;       // Read 3
  while (!(UCB0IFG & UCRXIFG));
  PJOUT |= BIT4;
  return (UCB0RXBUF);
}

/***************************************************
                     Main Code
***************************************************/

int main(void){
  WDTCTL = WDTPW | WDTHOLD;                     // Stop watchdog timer

  PJDIR |= 0x1F;                               
  PJOUT |= 0x1F;
  
  
  // Clock Setup For SPI
  CSCTL0_H = 0xA5;
  CSCTL1 |= DCOFSEL0 + DCOFSEL1;                // Set DCO = 8MHz
  CSCTL2 = SELA_3 + SELS_3 + SELM_3;            // set ACLK = SMCLK = MCLK = DCO
  CSCTL3 = DIVA_1 + DIVS_1 + DIVM_1;            // ACLK = SMCLK = MCLK = 1MHz
  
  // Configure SPI
  P1SEL1 |= BIT6 + BIT7;                        // Set pins for primary purpose
  P2SEL1 |= BIT2;                               // Set pin for primary purpose
  UCB0CTLW0 |= UCSWRST;
  UCB0CTLW0 |= UCCKPH + UCMST + UCSYNC + UCMSB;
  UCB0CTLW0 |= UCSSEL_3;                    // SMCLK = 4MHz
  UCB0BR0 = 0x02;                           // /2
  UCB0BR1 = 0;                              //
  UCB0CTLW0 &= ~UCSWRST;

  
  for(;;){ 
    FlashComID(0x9F);
    __delay_cycles(500);
  }
}

Anyone have any ideas of what I might be doing wrong?  Suggestions?

Thanks!

  • Hello Chris,

    You need to set the pin direction for the SPI lines on th eMSP430. Setting the PxSEL0/1 bits does not automatically set the PxDIR bits. For more information please see section 8.2.5 of the family user guide.

    regards,
    JH
  • I was not aware of that. I will give it a try and see what happens.

    However, I think it is worth mentioning that I tested the MCU on its own, by wiring the SIMO to the SOMI. I sent a few bytes of data out of the device by writing to the TXBUF, and then recorded what was read on the RXBUF. The end result was that if I sent a value of AAh out of the device, I would be able to read AAh into the device.

    Regardless, I am adding your suggestion to my code and will attempt it soon.


    One other thought I had was, could it be I need to reset the Flash Memory? I got them all brand new, and assumed it would not be necessary to do so. Granted I have been wrong before, and would love if it was as simple as that.
  • Jace,

    I tried as you suggested, however the results were not quite what I expected.  I was getting some kind of response... but hardly a consistent one. 

    I even took apart my board and re-wired everything, and then  tested each and every pin, wire, and connection using a Multimeter to be 100% sure that the connections are where they need to be and that there are no loose wires.

    Any other suggestions on what might be causing this?

  • Chris,

    You seem to have the MSP430 SPI setup correctly and are receiving responses. I would check with your SPI flash documentation in order to find out what commands are valid and what valid/error responses the chip is sending. That way you can further debug. I do not see what the commands or registers available for the flash in the datasheet you linked, but I would start there.

    Regards,
    JH

**Attention** This is a public forum