+ Post New Thread
Results 1 to 13 of 13
  1. #1
    Member level 2
    Points: 1,511, Level: 8
    Achievements:
    7 years registered

    Join Date
    Feb 2013
    Posts
    53
    Helped
    0 / 0
    Points
    1,511
    Level
    8

    SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Hello,

    I am working with a PIC24FJ128GB110 with a SPI Flash Memory (SST25VF016B-75-4I-S2AF) and i need to detect when the memory do not response any data when the microcontroller read it.

    I did one test, i remove the memory and always the micro detects a zero '0', so is the same as read 0!! I did is not reliable to me because i never will detect if my memory is wrong or something like that.


    I hope you can hep me with this trouble....
    Thanks!

  2. #2
    Super Moderator
    Points: 81,845, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,616
    Helped
    3762 / 3762
    Points
    81,845
    Level
    69

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Hi,

    what about using a 10kOhms pullup at the data line?

    In general: Don´t let inputs floating.


    Klaus



  3. #3
    Member level 2
    Points: 1,511, Level: 8
    Achievements:
    7 years registered

    Join Date
    Feb 2013
    Posts
    53
    Helped
    0 / 0
    Points
    1,511
    Level
    8

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Quote Originally Posted by KlausST View Post
    Hi,

    what about using a 10kOhms pullup at the data line?

    In general: Don´t let inputs floating.


    Klaus

    Hello Klaus, the hardware is configured as you said.

    The problem is that i need to detect once i read the memory that i did not receive any data from it. Maybe, reading any register, flag or something as this.



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 265,300, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,354
    Helped
    14107 / 14107
    Points
    265,300
    Level
    100

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    How do you expect a "data read detection" to work? Doesn't sound like a well considered question.

    To check existence and health of the SPI flash, you may want to read it's ID or status registers. To verify the consistency of previously written data, use a checksum or CRC.



    •   AltAdvertisement

        
       

  5. #5
    Member level 2
    Points: 1,511, Level: 8
    Achievements:
    7 years registered

    Join Date
    Feb 2013
    Posts
    53
    Helped
    0 / 0
    Points
    1,511
    Level
    8

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Quote Originally Posted by FvM View Post
    How do you expect a "data read detection" to work? Doesn't sound like a well considered question.

    To check existence and health of the SPI flash, you may want to read it's ID or status registers. To verify the consistency of previously written data, use a checksum or CRC.


    I am sorry not to be specific. I mean: How i can detect if the memory really is sending me a data, that is to say, i need to detect that the memory send me something, whatever it sends.



  6. #6
    Super Moderator
    Points: 81,845, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,616
    Helped
    3762 / 3762
    Points
    81,845
    Level
    69

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Hi,

    I did one test, i remove the memory and always the micro detects a zero '0',
    If u used a pullup, how can it detect a "0"?

    Klaus



    •   AltAdvertisement

        
       

  7. #7
    Member level 2
    Points: 1,511, Level: 8
    Achievements:
    7 years registered

    Join Date
    Feb 2013
    Posts
    53
    Helped
    0 / 0
    Points
    1,511
    Level
    8

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Quote Originally Posted by KlausST View Post
    Hi,


    If u used a pullup, how can it detect a "0"?

    Klaus
    I'm not taking the voltage level, i just have reading the SI from the micro, is to say, the value that the reading method return me back is '0'



  8. #8
    Super Moderator
    Points: 81,845, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,616
    Helped
    3762 / 3762
    Points
    81,845
    Level
    69

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Hi,

    I still don't understand...with the pullup installed it should ( or must) read back a "1" when you remove the memory, but not "0".

    Klaus



  9. #9
    Member level 2
    Points: 1,511, Level: 8
    Achievements:
    7 years registered

    Join Date
    Feb 2013
    Posts
    53
    Helped
    0 / 0
    Points
    1,511
    Level
    8

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Quote Originally Posted by KlausST View Post
    Hi,

    I still don't understand...with the pullup installed it should ( or must) read back a "1" when you remove the memory, but not "0".

    Klaus
    This is the method used to read the memory:
    Code:
    BYTE FlashRead(DWORD dwAddress)
    {
        volatile BYTE Dummy;
        BYTE vSPIONSave, vData;
        WORD SPICON1Save;
    
        //if( vData == 0x00 || wLength == 0x00 )
        //    return;
    
        // Save SPI state (clock speed)
        SPICON1Save = SPIFLASH_SPICON1;
        vSPIONSave = SPI_ON_BIT;
    
        // Configure SPI
        SPI_ON_BIT = 0;
        SPIFLASH_SPICON1 = PROPER_SPICON1;
        SPI_ON_BIT = 1;
    
        // Activate chip select
        SPIFLASH_CS_IO = 0;
        ClearSPIDoneFlag();
    
        // Send READ opcode
        SPIFLASH_SSPBUF = READ;
        WaitForDataByte();
        Dummy = SPIFLASH_SSPBUF;
    
        // Send address
        SPIFLASH_SSPBUF = ((BYTE*)&dwAddress)[2];
        WaitForDataByte();
        Dummy = SPIFLASH_SSPBUF;
    
        SPIFLASH_SSPBUF = ((BYTE*)&dwAddress)[1];
        WaitForDataByte();
        Dummy = SPIFLASH_SSPBUF;
    
        SPIFLASH_SSPBUF = ((BYTE*)&dwAddress)[0];
        WaitForDataByte();
        Dummy = SPIFLASH_SSPBUF;    
        // Read data
    //    while(wLength--)
    //    {
            SPIFLASH_SSPBUF = 0;
            WaitForDataByte();       
            vData = SPIFLASH_SSPBUF;        
    //    }
        //*vData++ = 0x00;
        // Deactivate chip select
        SPIFLASH_CS_IO = 1;
    
        // Restore SPI state
        SPI_ON_BIT = 0;
        SPIFLASH_SPICON1 = SPICON1Save;
        SPI_ON_BIT = vSPIONSave;
        
        return vData;
    }
    
    
    static inline __attribute__((__always_inline__)) void WaitForDataByte( void ){
            while ((SPIFLASH_SPITBF == 1) || (SPIFLASH_SPIRBF == 0));
    
    }
    I attached my schematicClick image for larger version. 

Name:	Captura.PNG 
Views:	7 
Size:	22.6 KB 
ID:	123138



  10. #10
    Administrator
    Points: 69,512, Level: 64
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    9,832
    Helped
    2360 / 2360
    Points
    69,512
    Level
    64
    Blog Entries
    4

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Quote Originally Posted by Rikr09 View Post
    I'm not taking the voltage level, i just have reading the SI from the micro, is to say, the value that the reading method return me back is '0'
    I would suggest posting, using CODE or SYNTAX tags, your code related to configuring, reading and writing of the SPI interface in question.

    As FvM indicated, reading the STATUS register would be one of the most straight forward methods of verifying the SPI to device viability.

    By default, after powerup, the STATUS register should return a value of 0x1C.


    BigDog

    - - - Updated - - -

    Update:

    Posting the SPI Read routine is a start, however the routine used to configure and initialize the SPI interface is of greater interest, without proper configuration and initialization the SPI Read and Write routines are a bit irrelevant.
    The Edge... there is no honest way to explain it, because the only people who really know where it is are the ones who have gone over.
    -- Hunter S. Thompson



  11. #11
    Member level 2
    Points: 1,511, Level: 8
    Achievements:
    7 years registered

    Join Date
    Feb 2013
    Posts
    53
    Helped
    0 / 0
    Points
    1,511
    Level
    8

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Quote Originally Posted by bigdogguru View Post
    I would suggest posting, using CODE or SYNTAX tags, your code related to configuring, reading and writing of the SPI interface in question.

    As FvM indicated, reading the STATUS register would be one of the most straight forward methods of verifying the SPI to device viability.

    By default, after powerup, the STATUS register should return a value of 0x1C.


    BigDog

    - - - Updated - - -

    Update:

    Posting the SPI Read routine is a start, however the routine used to configure and initialize the SPI interface is of greater interest, without proper configuration and initialization the SPI Read and Write routines are a bit irrelevant.


    Thanks Big Dog... I complete the coding:

    Code:
    void SPIFlashInit2(void){
        BYTE i;
        volatile BYTE Dummy;
        BYTE vSPIONSave;
        WORD SPICON1Save;
    
        // Save SPI state (clock speed)
        SPICON1Save = SPIFLASH_SPICON1;
    
        vSPIONSave = SPI_ON_BIT;
    
        // Configure SPI
        SPI_ON_BIT = 0;
        SPIFLASH_SPICON1 = PROPER_SPICON1;
        ClearSPIDoneFlag();
        SPIFLASH_SPICON2 = 0;
        SPIFLASH_SPISTAT = 0;    // clear SPI
        SPI_ON_BIT = 1;
    
    
        // Read Device ID code to determine supported device capabilities/instructions
        {
            // Activate chip select
    	SPIFLASH_CS_IO = 0;
    	ClearSPIDoneFlag();
    //        _SPI1BRG=1; //
    	// Send instruction
    	SPIFLASH_SSPBUF = RDID;
    	WaitForDataByte();
    	Dummy = SPIFLASH_SSPBUF;
    
    	// Send 3 byte address (0x000000), discard Manufacture ID, get Device ID
    	for( i=0;i<5;i++ ){
                SPIFLASH_SSPBUF = 0x00;
    	    WaitForDataByte();
    	    Dummy = SPIFLASH_SSPBUF;
    	}
    	// Deactivate chip select
    	SPIFLASH_CS_IO = 1;
    
    	// Decode Device Capabilities Flags from Device ID
    	Device2.v = 0x00;
    
    	switch(Dummy){
                case 0x41:  //SST25LF016B
                            Device2.bits.bWriteWordStream = 1;
                            break;
                case 0x43:	// SST25LF020(A)	(2 Mbit)	0xAF, 14us, AAI Byte
                case 0x48:	// SST25VF512(A)	(512 Kbit)	0xAF, 14us, AAI Byte
                case 0x49:	// SST25VF010A		(1 Mbit)	0xAF, 14us, AAI Byte
    			Device2.bits.bWriteByteStream = 1;
    			break;
                case 0x4B:	// SST25VF064C		(64 Mbit)	0x02, 1.5ms/256 byte page, no AAI
    			Device2.bits.bPageProgram = 1;
    			break;
                case 0x8E:	// SST25VF080B		(8 Mbit)	0xAD,  7us, AAI Word
    			Device2.bits.bWriteWordStream = 1;
                            break;
    	}
        }
    
        // Clear any pre-existing AAI write mode
        // This may occur if the PIC is reset during a write, but the Flash is
        // not tied to the same hardware reset.
        _SendCmd(WRDI);
    
        // Execute Enable-Write-Status-Register (EWSR) instruction
        _SendCmd(EWSR);
    
        // Clear Write-Protect on all memory locations
        SPIFLASH_CS_IO = 0;
        SPIFLASH_SSPBUF = WRSR;
        WaitForDataByte();
        Dummy = SPIFLASH_SSPBUF;
        SPIFLASH_SSPBUF = 0x00; // Clear all block protect bits
        WaitForDataByte();
        Dummy = SPIFLASH_SSPBUF;
        SPIFLASH_CS_IO = 1;
    
        // Restore SPI state
        SPI_ON_BIT = 0;
        SPIFLASH_SPICON1 = SPICON1Save;
        SPI_ON_BIT = vSPIONSave;
    
    }
    The writin code i di not attached because i remove the Memory in order to detect that no data will be received.



    •   AltAdvertisement

        
       

  12. #12
    Administrator
    Points: 69,512, Level: 64
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    bigdogguru's Avatar
    Join Date
    Mar 2010
    Location
    Southwest, USA
    Posts
    9,832
    Helped
    2360 / 2360
    Points
    69,512
    Level
    64
    Blog Entries
    4

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Thanks for posting the initialization code.

    It appears you are utilizing the SPI1 interface, is this correct?

    What is the actual value of PROPER_SPICON1, which is being loaded into SPIxCON1?


    BigDog
    The Edge... there is no honest way to explain it, because the only people who really know where it is are the ones who have gone over.
    -- Hunter S. Thompson



  13. #13
    Member level 2
    Points: 1,511, Level: 8
    Achievements:
    7 years registered

    Join Date
    Feb 2013
    Posts
    53
    Helped
    0 / 0
    Points
    1,511
    Level
    8

    Re: SPI Flash SST25VF016B-75-4I-S2AF NO Data read detection

    Quote Originally Posted by bigdogguru View Post
    Thanks for posting the initialization code.

    It appears you are utilizing the SPI1 interface, is this correct?

    What is the actual value of PROPER_SPICON1, which is being loaded into SPIxCON1?


    BigDog
    Hello BigDog,

    I am using the SPI2 interface, the PIC has PPS pins.

    The value of PROPER_SPICON1 is
    Code:
    #define PROPER_SPICON1  0x013B
    On SPIxCON1, wich is SPI2CON1 is loaded de the value of PROPER_SPI1CON1. This can be seen on:

    Code:
    #define SPIFLASH_SPICON1	(SPI2CON1)
    Thanks for your attention....



--[[ ]]--