Page 1 of 1

MODM7AE70 - SPI EEPROM

Posted: Wed Nov 26, 2025 5:39 pm
by BryanJS
I am trying to read and write to an EEPROM 25LC1024. I have successfully done this on other netburner V1 products but not V3, so I am basing this off successful code.

I am not able to read or write and I am clearly doing something basic wrong. Any help advice or examples would be appreciated.

My current code is below and I am using CS1 for the EEPROM.



// Initialize SPI
void SPI_Services::Initialize()
{
// Define the IO
CS_FLASH.function(PINP2_30_SPI0_NPCS2); // Chip Select 2
CS_EEPROM.function(PINP2_40_SPI0_NPCS1); // Chip Select 1
CS_AOUT.function(PINP2_26_SPI0_NPCS3); // Chip Select 3


SPI_CLK.function(PINP2_25_SPI0_SPCK); // CLOCK
SPI_DIN .function(PINP2_27_SPI0_MISO); // SPI MISO
SPI_DOUT.function(PINP2_28_SPI0_MOSI); // SPI MOSI

CS_FLASH = 1;
CS_EEPROM = 1;
CS_AOUT = 1;



iprintf("SPI Initialized. \r\n");
}


// EEPROM OPERATIONS
// Write a block to the EEPROM
void SPI_Services::EEPROM_WriteBlock(int iPage, uint8_t * pData, int iLength)
{
EEPROM_Initialize();


iprintf("Write Block. \r\n");

int iTxLength = iLength + 4; // The data plus command bytes
uint16_t Address = iPage * 256; // Pages in 256 bytes/block
uint8_t TxBuffer[iTxLength];

uint8_t Buffer[1];
Buffer[0] = SPI_WREN;
uint8_t iState = QSPIStart(Buffer, NULL,1 , &SPI_SEM);
SPI_SEM.Pend(0); // Wait for QSPI to complete



if(!CheckStatus(iState, " EEPROM Write Enabled")) return ;


// Set the command and address
TxBuffer[0] = SPI_WRITE;
TxBuffer[1] = (Address >> 16);
TxBuffer[2] = (Address >> 8);
TxBuffer[3] = (Address);

// Copy the data to the tx buffer
int iTxPosition = 4 ;
for(int i = 0 ; i < iLength ; i++)
{
TxBuffer[iTxPosition++] = i; //pData;
}


iState = QSPIStart(TxBuffer, NULL, iTxLength , &SPI_SEM);
SPI_SEM.Pend(0); // Wait for QSPI to complete

if(!CheckStatus(iState, " EEPROM Write Block")) return ;

iprintf("Write Block Ended. \r\n");

}



// Read a Block from the EEPROM
void SPI_Services::EEPROM_ReadBlock(int iPage, uint8_t * pData , int iLength)
{

EEPROM_Initialize();

int iMsgLength = iLength + 4;
int iAddress = iPage * 256; // Pages in 256 blocks

uint8_t Rx_Buffer[iMsgLength];
uint8_t Tx_Buffer[4];

memset( (void *)Rx_Buffer, 0, iMsgLength ); // Clear the Rx buffer

// Set the command bytes
Tx_Buffer[0] = SPI_READ;
Tx_Buffer[1] = (iAddress >> 16);
Tx_Buffer[2] = (iAddress >> 8);
Tx_Buffer[3] = (iAddress);


uint8_t iState = QSPIStart( Tx_Buffer, Rx_Buffer, iMsgLength , &SPI_SEM); // Output the data
SPI_SEM.Pend(0); // Wait for QSPI to complete


CheckStatus(iState, "EEPROM Read Block");

int iPointer = 4; // Rx_Buffer Pointer

for(int i = 0 ; i < iLength ; i++)
{
iprintf(" Data : %d. " , Rx_Buffer[iPointer] );
pData = Rx_Buffer[iPointer++];


}
iprintf("Read Block Ended. \r\n");
}


bool SPI_Services::EEPROM_Initialize()
{
uint8_t iState = QSPIInit( 2000000, 0x08, 0x1, 0x1, 0x0, 0x0, TRUE, 0x0, 0x0 );
return CheckStatus(iState, "EEPROM Initialization ");
}


// Helper functions
// Check the SPI status
bool SPI_Services::CheckStatus(uint8_t iState, char * msg)
{
bool blnOK = iState == 0;
if(!blnOK)
{
iprintf(msg);
iprintf(" SPI Error : %d. \r\n" , iState);
}
else
{
iprintf(msg);
iprintf(" SPI OK : %d. \r\n" , iState);
}
return blnOK;
}

Re: MODM7AE70 - SPI EEPROM

Posted: Fri Nov 28, 2025 11:09 pm
by TomNB
Have you looked at the PicKitI2C example for comparison? It reads/writes an EEPROM. The example docs are here:

https://www.netburner.com/NBDocs/Develo ... m_e70.html

Might be good to compare the two and see if there are any significant differences, especially if you had been using an older hardware platform.

Re: MODM7AE70 - SPI EEPROM

Posted: Mon Dec 01, 2025 1:35 pm
by BryanJS
Hi Tom,

Thanks, but the demo is I2C and I have having issues with SPI. The message format looks the same as SPI

Re: MODM7AE70 - SPI EEPROM

Posted: Tue Dec 02, 2025 12:58 pm
by pbreed
CS_FLASH.function(PINP2_30_SPI0_NPCS2); // Chip Select 2
CS_EEPROM.function(PINP2_40_SPI0_NPCS1); // Chip Select 1
CS_AOUT.function(PINP2_26_SPI0_NPCS3); // Chip Select 3

The above all tells the hardware that the SPI hardware is managing the pin.

Below puts the pin back in GPIO mode....
CS_FLASH = 1;
CS_EEPROM = 1;
CS_AOUT = 1;

So your half in half out... do you want to manually run the CS, or want the SPI system to run it?
Choose one and delete the other three entries in your init function.

Re: MODM7AE70 - SPI EEPROM

Posted: Fri Dec 05, 2025 2:34 pm
by TomNB
Sorry for the I2C reference, I mis-typed. There is a pic kit for spi too: C:\nburn\examples\PlatformSpecific\SPI\PicKitSerialSPIDemoBd. I think it might just be a small spi than you are using.

Demonstrates the use of 7 Microchip SPI Peripherals:
- 25LC020A 2K SPI Bus Serial EEPROM
- TC77-5.0 Thermal Sensor with SPI Interface
- MCP3201 2.7V 12-Bit A/D Converter with SPI Serial Interface
- MCP4822 12-Bit DAC with Internal VREF and SPI Interface
- MCP41010 Single/Dual Digital Potentiometer with SPI Interface
- MCP6S92 Single-Ended, Rail-to-Rail I/O, Low-Gain PGA
- MCP23S08 8-Bit I/O Expander with Serial Interface

Here are the docs: https://www.netburner.com/NBDocs/Develo ... mo_bd.html

Re: MODM7AE70 - SPI EEPROM

Posted: Sun Dec 07, 2025 9:11 am
by BryanJS
Hi Tom,

Thank you for your reference, it was a great help and I was able to get it working.

Much appreciated
Bryan