AnsweredAssumed Answered

internal serial flash on BF512F

Question asked by 2sb18 on Sep 7, 2011
Latest reply on Oct 11, 2011 by PrasanthR

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;
}

Outcomes