Interfacing the 25CSM04 EEPROM on the Curiosity Nano Explorer development board using a PIC18F56Q24 Curiosity Nano
This example demonstrates the setup and configuration of the 25CSM04 EEPROM using the PIC18F56Q24 microcontroller. The 25CSM04 is a 4 Mbit Serial Peripheral Interface (SPI) serial EEPROM, designed to provide reliable, high-density non-volatile memory storage. By interfacing the 25CSM04 using the PIC18F56Q24 Curiosity Nano, this example highlights how to efficiently store and retrieve data using SPI communication, making it ideal for applications that require robust data retention and fast access times.
- MPLAB® X IDE 6.20.0 or newer
- MPLAB® XC8 3.00.0 or newer compiler
- MPLAB® Code Configurator (MCC) 5.5.1 or newer
- Microchip PIC18F-Q Series DFP (1.27.449) or newer
- PIC18F56Q24 Curiosity Nano Evaluation Kit
- Curiosity Nano Explorer
- USB type C cable
The userguide for the Curiosity Explorer Nano board provides detailed information about the pin mapping between the Curiosity Explorer board and the PIC18F56Q24 Curiosity Nano board being used in this example.
Based on the diagram above from the Curiosity Explorer users guide, the SPI CS, SPI MOSI, SPI MISO, and SPI SCK lines will be used to communicate with the 25CSM04 SPI EEPROM.
The detailed step by step instructions required to recreate this example are listed below:
Begin by setting up UART to enable data display on the terminal.
The UART configuration should appear as shown below.
- With MCC open, add the UART driver and select UART2 in the dependency selector.
- Ensure that "Redirect Printf to UART" is enabled.
- The UART configuration should appear as shown below.
- No changes are required for UART2PLIB
- Add the SPI driver and select SPI1 as the SPI Host PLIB Selector.
- Set the requested speed to 4000 kHz and ensure that the SPI interrupt is enabled.
- The SPI configuration is also shown in the image below.
- Select the appropriate UART and SPI pins as indicated in the diagram below.
- The MCC configuration for the pins is shown below.
- Click on "Generate" to complete the configuration in MCC.
- Add the
25CSM04.c
and25CSM04.h
driver code to the project. - Modify
main.c
as shown in the screenshot below.
- This code snippet calls writeReadByteTest(0x0000), which performs consecutive read and write operations starting from address 0x0000.
- The code displays the written and read values and verifies whether these values match.
After programming the device, the terminal displays the output indicating whether the tests have passed or failed.
This demonstration shows how to interface the 25CSM04 SPI EEPROM on the Curiosity Nano Explorer board using a PIC18F56Q24 microcontroller. In this example, several tests are performed to validate the functionality of the EEPROM interface. Data is written to a specific memory location, and then read back from the same address to ensure that both the write and read operations are working correctly. The results of these tests are displayed on the terminal, providing clear feedback on the success or failure of each operation.