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,
a brief look makes me guess that you are running too fast 1) what is your CPU clock 2) is your CPU a 12-clocker 6-clocker ... ? 3) what is the max IIC baudrate for the SST25VF512
Erik
If it is able to read , then i believe speed mismatch is not the problem,
what could be the problem,
"If it is able to read , then i believe speed mismatch is not the problem"
Read what? Do you mean that your code reads the flash OK?
This does not necessarily mean that your timing is correct for writing!
Your timing could be marginal; ie, "only just close enough" for reading and that could make it "only just over the limit" for writing - hence reading could work, and writing not!
So what do i do in this case, please tell me
View all questions in Keil forum