internal serial flash on BF512F

Hi,

While initializing the internal serial flash, I'm trying to read the status register from the internal serial flash on the BF512F. So far I'm getting back b#00000000 instead of the default b#00011100. Could anyone let me know if I'm missing anything? Here's my code. Thanks, Steve.

#include <cdefBF51x_base.h>
#include "config.h"
#include "serial_flash.h"
#define SPI_FREQUENCY     10000000     // 100kHz
#define SERIAL_FLASH_RDSR     0x05
#define SERIAL_FLASH_JEDEC     0x9F
#define DELAY                    30000
unsigned int status_register;

static void Wait_For_SPIF(void)
{
     int n;
     for(n=0; n<DELAY; n++) {
          asm("nop;");
     }
     while(1) {
        unsigned short iTest = *pSPI_STAT;
          if( iTest & SPIF ) {
               break;
          } else {
               asm("nop;");
          }
     }
}

void serial_flash_initialize () {
     // Table 9-5 says PORTH_FER[8] has to be set and PORTHIO_DIR[8] has
     // to be clear
     * pPORTH_FER |= 1 << 8;
     // setup SPI0
     //
     * pSPI0_BAUD = FCY / SPI_FREQUENCY / 2;
     * pSPI0_FLG  |= FLS4;
     * pSPI0_CTL = 0x5001;     // enable, master, mode 0, msb, 8-bit,
     // start transfer with write of TDBR
     // lets try to read the status register of the serial flash
     * pSPI0_TDBR = SERIAL_FLASH_RDSR;
     Wait_For_SPIF();
     unsigned int dummy_read = * pSPI0_RDBR;
     Wait_For_SPIF();
     * pSPI_TDBR = 0;     // dummy write
     Wait_For_SPIF();
     status_register = * pSPI0_RDBR;
}
  • Also, I found something that I think might be interesting while trying to figure out this serial flash problem. In the ss25wf040.c file, there's the following code in the PollToggleBit() function:

    status_register = ReadStatusRegister();
    if( (status_register & WEL) ) {
         ErrorCode = NO_ERR;
         break;
    }

    Why is the code checking the WEL bit? Shouldn't it be checking the BUSY bit?

    Thanks,

    Steve.

  • 0
    •  Analog Employees 
    on Oct 4, 2011 7:51 AM

    You need to program the FER and MUX registers for SPI as well. You should be reusing the flash programmer code itself on that:

    /* PG12 - SPI0_SCK PG13 - SPI0_MISO PG14 - SPI0_MOSI */

    *pPORTG_FER |= (PG12 | PG13 | PG14);

    /* set PG12, PG13, and PG14 */

    *pPORTG_MUX &= 0x3fff;

    /* set for 1st function (00) */

    *pPORTH_FER &= ~(PH8);

    *pPORTHIO_DIR |= PH8;

    *pPORTHIO_SET = PH8;

    for(i=0; i<DELAY; i++)

    {asm("nop;"); }

    /* chip enable for internal SPI */

    *pPORTHIO_CLEAR = PH8;

    Additionally, the flash datasheet says that CE# must remain low for the duration of any command sequence, so you should just clear this signal from beginning as as flag.

     

    On the 2nd question, I haven't gone through the flash datasheet in depth. But it says that 1. The Write-Enable (WREN) instruction must be executed prior to Byte-Program. 2. 'Write Enable Latch (WEL)' is reset on 'Byte-Program instruction completion'.

    Regards

    Prasanth.

  • 0
    •  Analog Employees 
    on Oct 7, 2011 12:19 AM

     

     

    Prasanth Rajagopal wrote:

    You need to program the FER and MUX registers for SPI as well. You should be reusing the flash programmer code itself on that:

    /* PG12 - SPI0_SCK PG13 - SPI0_MISO PG14 - SPI0_MOSI */

    *pPORTG_FER |= (PG12 | PG13 | PG14);

    /* set PG12, PG13, and PG14 */

    *pPORTG_MUX &= 0x3fff;

    /* set for 1st function (00) */

    SPI0 when working with internal serial flash doesn't need the pins as we have dedicated pads for flash.

  • 0
    •  Analog Employees 
    on Oct 11, 2011 4:32 AM

    That's correct, sorry I mixed up there.

    Regards

    Prasanth.

  • 0
    •  Analog Employees 
    on Aug 2, 2018 4:14 PM
    This question has been assumed as answered either offline via email or with a multi-part answer. This question has now been closed out. If you have an inquiry related to this topic please post a new question in the applicable product forum.

    Thank you,
    EZ Admin