Estoy trabajando con un chip de memoria Flash NOR: S25FL032P fabricado por Spansion. Estoy conectando el NOR Flash sobre SPI con Bit Banging, ya que voy a utilizar el motor SPI dedicado para algún otro periférico.
No puedo leer / escribir los datos en Flash por algún motivo. Adjunto las capturas de pantalla de las hojas de datos y lo que he implementado hasta ahora. Mirando la publicación, puede que parezca que gran parte de los datos encuentran algo que ha ido mal con la implementación, pero esa es la forma en que podría pensar. Cualquier ayuda es muy apreciada.
voidWrite_Enable(void){signedcharcmd=WRITE_ENABLE;inti=0;SPI_CS_H();for(i=0;i<8;i++){_delay_us(100);//MakeSCKLowSPI_SCK_H();//MaketheMOSI(Master-Out-Slave-In)pinhighorlowdependingonbit7ofthedataif(cmd&0x80){SPI_MOSI_H();#ifdefDEBUG_Ouart_print("1");
#endif // DEBUG
}
else
{
SPI_MOSI_L();
#ifdef DEBUG_O
uart_print("0");
#endif // DEBUG
}
_delay_us(100);
//Make SCK High
SPI_SCK_L();
//Left shift the next data to send the next bit
cmd = cmd << 1;
}
SPI_CS_L();
#ifdef DEBUG_O
uart_print(" ");
#endif // DEBUG
}
voidSector_Erase(void){signedcharcmd=SECTOR_ERASE;charaddr[4];inti=0,j=0;addr[0]=0x1E;addr[1]=0x00;addr[2]=0x00;addr[3]=0x00;SPI_CS_H();for(i=0;i<8;i++){_delay_us(100);//MakeSCKLowSPI_SCK_H();//MaketheMOSI(Master-Out-Slave-In)pinhighorlowdependingonbit7ofthedataif(cmd&0x80){SPI_MOSI_H();#ifdefDEBUG_Ouart_print("1");
#endif // DEBUG
}
else
{
SPI_MOSI_L();
#ifdef DEBUG_O
uart_print("0");
#endif // DEBUG
}
_delay_us(100);
//Make SCK High
SPI_SCK_L();
//Left shift the next data to send the next bit
cmd = cmd << 1;
}
#ifdef DEBUG_O
uart_print(" ");
#endif // DEBUG
for( j = 0; j < 3 ; j++)
{
for(i = 0; i < 8; i++)
{
_delay_us(100);
//Make SCK Low
SPI_SCK_H();
//Make the MOSI (Master-Out-Slave-In) pin high or low depending on bit 7 of the data
if(addr[j] & 0x80)
{
SPI_MOSI_H();
#ifdef DEBUG_O
uart_print("1");
#endif // DEBUG
}
else
{
SPI_MOSI_L();
#ifdef DEBUG_O
uart_print("0");
#endif // DEBUG
}
_delay_us(100);
//Make SCK High
SPI_SCK_L();
//Left shift the next data to send the next bit
addr[j] = addr[j] << 1;
}
}
#ifdef DEBUG_O
uart_print(" ");
#endif // DEBUG
SPI_CS_L();
}
voidWrite_Page(void){signedcharcmd=PAGE_PROG;inti=0,j=0;charaddr[4];chardata[4]={0xAA,0x55,0xAA,0x55};//unsignedintaddr=0x1E000000;addr[0]=0x1E;addr[1]=0x00;addr[2]=0x00;addr[3]=0x00;SPI_CS_H();for(i=0;i<8;i++){_delay_us(100);//MakeSCKLowSPI_SCK_H();//MaketheMOSI(Master-Out-Slave-In)pinhighorlowdependingonbit7ofthedataif(cmd&0x80){SPI_MOSI_H();#ifdefDEBUG_Ouart_print("1");
#endif // DEBUG
}
else
{
SPI_MOSI_L();
#ifdef DEBUG_O
uart_print("0");
#endif // DEBUG
}
_delay_us(100);
//Make SCK High
SPI_SCK_L();
//Left shift the next data to send the next bit
cmd = cmd << 1;
}
#ifdef DEBUG_O
uart_print(" ");
#endif // DEBUG
for( j = 0; j < 3 ; j++)
{
for(i = 0; i < 8; i++)
{
_delay_us(100);
//Make SCK Low
SPI_SCK_H();
//Make the MOSI (Master-Out-Slave-In) pin high or low depending on bit 7 of the data
if(addr[j] & 0x80)
{
SPI_MOSI_H();
#ifdef DEBUG_O
uart_print("1");
#endif // DEBUG
}
else
{
SPI_MOSI_L();
#ifdef DEBUG_O
uart_print("0");
#endif // DEBUG
}
_delay_us(100);
//Make SCK High
SPI_SCK_L();
//Left shift the next data to send the next bit
addr[j] = addr[j] << 1;
}
}
#ifdef DEBUG_O
uart_print(" ");
#endif // DEBUG
for( j = 0; j < 4 ; j++)
{
for(i = 0; i < 8; i++)
{
_delay_us(100);
//Make SCK Low
SPI_SCK_H();
//Make the MOSI (Master-Out-Slave-In) pin high or low depending on bit 7 of the data
if(data[j] & 0x80)
{
SPI_MOSI_H();
#ifdef DEBUG_O
uart_print("1");
#endif // DEBUG
}
else
{
SPI_MOSI_L();
#ifdef DEBUG_O
uart_print("0");
#endif // DEBUG
}
_delay_us(100);
//Make SCK High
SPI_SCK_L();
//Left shift the next data to send the next bit
data[j] = data[j] << 1;
}
}
#ifdef DEBUG_O
uart_print(" ");
#endif // DEBUG
SPI_CS_L();
}
voidRead_Page(void){signedcharcmd=READ;inti=0,j=0;charaddr[4];signedcharval[32];signedcharpinState=0;addr[0]=0x1E;addr[1]=0x00;addr[2]=0x00;addr[3]=0x00;SPI_CS_H();for(i=0;i<8;i++){_delay_us(100);//MakeSCKLowSPI_SCK_H();//MaketheMOSI(Master-Out-Slave-In)pinhighorlowdependingonbit7ofthedataif(cmd&0x80){SPI_MOSI_H();#ifdefDEBUG_Ouart_print("1");
#endif // DEBUG
}
else
{
SPI_MOSI_L();
#ifdef DEBUG_O
uart_print("0");
#endif // DEBUG
}
_delay_us(100);
//Make SCK High
SPI_SCK_L();
//Left shift the next data to send the next bit
cmd = cmd << 1;
}
#ifdef DEBUG_O
uart_print(" ");
#endif // DEBUG
for( j = 0; j < 3 ; j++)
{
for(i = 0; i < 8; i++)
{
_delay_us(100);
//Make SCK Low
SPI_SCK_H();
//Make the MOSI (Master-Out-Slave-In) pin high or low depending on bit 7 of the data
if(addr[j] & 0x80)
{
SPI_MOSI_H();
#ifdef DEBUG_O
uart_print("1");
#endif // DEBUG
}
else
{
SPI_MOSI_L();
#ifdef DEBUG_O
uart_print("0");
#endif // DEBUG
}
_delay_us(100);
//Make SCK High
SPI_SCK_L();
//Left shift the next data to send the next bit
addr[j] = addr[j] << 1;
}
}
#ifdef DEBUG_O
uart_print(" ");
#endif // DEBUG
for(i = 0; i < 32; i++)
{
for(j = 0; j < 8 ; j++)
{
_delay_us(100);
//Make SCK Low
SPI_SCK_L();
//Make the MOSI (Master-Out-Slave-In) pin high or low depending on bit 7 of the data
pinState = CHECK_BIT(SPI_PIN, SPI_MISO_BIT);
if( pinState )
{
#ifdef DEBUG_O
uart_print("1");
#endif // DEBUG
}
else
{
#ifdef DEBUG_O
uart_print("0");
#endif // DEBUG
}
_delay_us(100);
//Make SCK High
SPI_SCK_H();
val[i] = (pinState << j)|(val[i]);
}
}
#ifdef DEBUG_O
uart_print(" ");
#endif // DEBUG
SPI_CS_L();
}
El orden en que se llaman es:
Write_Enable();
Sector_Erase();
Read_Page();
Write_Page();
Read_Page();