This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

c51:

While trying to interface flash SST25VF512 with AT80c51,
i find difficulty in Byte program mode of writing to flash.

This is the code i used, could somebody who has worked on this please help me out,

void main(void){
        ce = 1;
        SCK = 0;
                TMOD = 0x20;
                TH1 = -3;               // 9600 baud
                SCON = 0x50;
                TR1 = 1;
                TI = 1;

        addr = 0x00000012;

        Rd_ID = Read_ID();
         Byte_Program(addr);

void Byte_Program(unsigned long addr){
        ce = 0;
        E_WRSR();
        WREN();
        Send_Byte(0x02);        // Byte Program CMD
        Send_Byte(((addr & 0xFFFFFF) >> 16)); // sending 3 address bytes
        Send_Byte(((addr & 0xFFFF) >> 8));
        Send_Byte(addr & 0xFF);
        Send_Byte(0x10);           //send data
        SR_byte = Read_Status_Register();
         while((SR_byte &0x01) != 0x00){
         SR_byte = Read_Status_Register();
         }
        ce = 1;
}

void E_WRSR(){
        ce = 0;
        Send_Byte(0x50);        // enable Status Reg
        ce = 1;
        ce = 0;
        Send_Byte(0x01);        // select write to status register
        Send_Byte(0x00);        // mode 0,                      ce = 1;
}
void WREN(){
        ce = 0;
        Send_Byte(0x06);// to Write enable
        ce = 1;
}

unsigned char Get_Byte(){
        unsigned char i=0, in=0, temp=0;
        for(i=0;i<8;i++){
                in = (in << 1);
                temp = SO;
                SCK = 1;
                if (temp == 1){
                        in = in | 0x01;
                }
                SCK = 0;
        }
        return in;
}
void Send_Byte(unsigned char b_out){
        for(i=0;i<8;i++){
                if((b_out & 0x80) == 0x80)
                        si = 1;
                else
                        si = 0;
                        SCK = 1;
                        b_out = (b_out << 1);
                        SCK = 0;
        }
}

Thanks in advance,

Parents
  • You probably do not want to write the status register before every write operation. Yes, there is a write enable bit there, and yes, this sequence will work correctly. However, the status register in these types of flash is non-volatile, implemented with the same flash technology as the rest of the chip. Every time you write the status register, you effectively erase it and reprogram it. After the rated number of cycles on your flash chip, the status register will burn out and the chip will stop working, even if the data sectors are still good.

    The WREN command is sufficient to tell the chip to allow programming. It does not cause the status register to be erased and reprogrammed as does WRSR. Using WRSR is not necessary, and will limit the lifetime of the chip if you frequently write data.

Reply
  • You probably do not want to write the status register before every write operation. Yes, there is a write enable bit there, and yes, this sequence will work correctly. However, the status register in these types of flash is non-volatile, implemented with the same flash technology as the rest of the chip. Every time you write the status register, you effectively erase it and reprogram it. After the rated number of cycles on your flash chip, the status register will burn out and the chip will stop working, even if the data sectors are still good.

    The WREN command is sufficient to tell the chip to allow programming. It does not cause the status register to be erased and reprogrammed as does WRSR. Using WRSR is not necessary, and will limit the lifetime of the chip if you frequently write data.

Children
  • Thanks Dave,
    so you suggest WRSR need not be written IN the write operation is it, fine,
    then how do we set the memory protection bits?
    Without setting them, is there any way to write,

    "After the rated number of cycles on your flash chip, the status register will burn out and the chip will stop working, even if the data sectors are still good."
    Could you please tell this rated number of cycles. Can write operation process be completed within that?

    "Using WRSR is not necessary, and will limit the lifetime of the chip if you frequently write data."
    Is it apart from the 10,000 cycles for the chip as a whole?

    Then how do we get to write data and check also that the program is running fine,

  • Thanks Dave,
    so you suggest WRSR need not be written IN the write operation is it, fine,
    then how do we set the memory protection bits?
    Without setting them, is there any way to write,

    "After the rated number of cycles on your flash chip, the status register will burn out and the chip will stop working, even if the data sectors are still good."
    Could you please tell this rated number of cycles. Can write operation process be completed within that?

    "Using WRSR is not necessary, and will limit the lifetime of the chip if you frequently write data."
    Is it apart from the 10,000 cycles for the chip as a whole?

    Then how do we get to write data and check also that the program is running fine,

    waiting for reply,

  • "Could you please tell this rated number of cycles."

    That'll be in the datasheet

    Note that it is not a precise number below which everything is fine and above which nothing works; the thing wears out gradually.

  • Thanks Neil,
    How do you say the write function code should be,
    After writing the byte, the status reg reads 02, ie finished writing.
    Then should there be some change in the read function code?
    Where do you think is the mistake,

  • "However, the status register in these types of flash is non-volatile, implemented with the same flash technology as the rest of the chip."
    How is that only status reg is non volatile?
    I could nt find this info in datasheet.
    Where do we get such finer details?

  • "How do you say the write function code should be"

    Never mind what I say - what does the Manufacturer say?

    Don't SST provide example code for this?

  • If that had worked, would not have asked you

  • Had followed the manufacturer's code supposedly
    there are fine changes to be done
    thought you got an eye for detail
    SST does provide code, though there are things to be added to it like Enable operation etc..