The PICDEM.NET 2 has a stand-alone Ethernet controller, ENC28J60 but the project is not going to use that stand-alone Ethernet controller. The project will use the Ethernet driver for the PIC18F97J60, which is the ETH97J60. It is interesting to note that the PICDEM.NET 2 has two Integrated Connector Modules (ICMs), one for the PIC18F97J60 and one for the ENC28J60. For this project I will be only using the first one. The source code for the TCP/IP Stack Demo Application is used as well.

The source code for TCP/IP Stack Demo Application is a very large library with a lot of files for the demonstration purpose of different capabilities of the Microchip TCP/IP Stack. My first challenge is to identify which codes are necessary and include them in the MPLAB compiler project. The challenge in compiling the demo program is that a lot of the functions are found undefined and the source code that holds the code for the functions needed to be found and included in the compiling project.

It is also important that the “Preprocessor macro definitions” in the “mcc18” tab of the “Project Properties” must include the definition “CFG_INCLUDE_PICDN2_ETH97”. This helps the compiler to select the correct hardware profile and TCPIP configuration in both the “HardwareProfile.h” and “TCPIPConfig.h”. In this particular demo code, these two header files will have a variety of different hardware profiles and TCPIP configurations which will be stored in different files in the “Configs” folder.

For now, the TCPIP config that needs to be altered is in the file named “TCPIP ETH97.h”. To decrease the size of the code, only “#define STACK_USE_ICMP_SERVER” and “#define STACK_USE_HTTP2_SERVER” is uncommented in the “Application Options” section.  And also, “#define STACK_USE_HTTP_APP_RECONFIG”, “#define STACK_USE_HTTP_MD5_DEMO” and “#define STACK_USE_HTTP_EMAIL_DEMO” in the “HTTP2 Server options” section is commented to further reduce the size of the code. The MAC address, IP address, subnet mask and other network configurations are changed in the “Network Addressing Options” section in the same file.

By referring to page 6 of Microchip’s “AN833 The Microchip TCP/IP Stack”, a table of Microchip TCPI/IP Stack Modules and their respective file requirements are shown. But, the actual files included in my projects are a lot more than it is stated in the table. It should be noted that there is no “MAC.c” file but it is replaced by the file “ETH97J60.c”.

Finally, the compiler can successfully build the project and program it onto the board. But, the Ethernet port LEDs are not lit up. So, I modified the code to simply just making the Ethernet layer to work, which is just a simple function, StackInit(). The Ethernet port lit up fine, so I went looking into the main code structure in “MainDemo.c” since I am guessing that the main code is looping infinitely somewhere before StackInit(). In the end, the problem is found in the InitAppConfig() function in the “MainDemo.c” file. There is a part just before the break command which causes the code to never exit from the while loop. I commented the part of that code since I will not be using it in my project. As a result, the Ethernet port LEDs lit up and the HTTP server can be accessed from the computer. Unfortunately, I am not sure of what is causing the code to loop infinitely within the part of the code I commented.

My supervisor brought me two MMC cards and asked me to test whether the PIC18 can format these two MMC cards or not. By reusing the code that I used to format the SD cards last week, I made a few minor changes to the code and test it out with the MMC cards. Unfortunately, both of the MMC cards were not able to be formatted with the PIC18. It turns out that one of the MMC card was not readable by the computer. I tried to run a little bit of testing on the MMC cards and found that both cards are returning 0xFD instead of data start token (0xFE) after the PIC18 sent the READ_MULTI_BLOCK command. I stopped my experimenting on the MMC cards and started to study the HTTP server with SD card.

The demo I am able to run successfully uses MPFS storage on EEPROM, SPI FLASH or the internal program memory. But, the objective of the project is to store bit streams on SD card instead. However, I was able to find a demo provided by Microchip which uses Microchip’s Memory Disk Drive (MDD) file system interface library to use SD cards as storage. Unfortunately, the code provided does not support the PIC18F97J60. But after looking through the codes a bit, the main code actually have sections of code provided for the PIC18. I also found that the part which the PIC18 is not supported is in the “HardwareProfile.h” file because the pins are defined for PIC24 only. I then modified the “HardwareProfile.h” by referring to the hardware profiles of my previous SD card project and TCP/IP project.

The “TCPIPConfig.h” also appears to have a problem. There are two lines of code used to define where the web pages are stored. The problem appears at the definition of “WW” and “” as MDD_ROOT_DIR_PATH caused an error saying that the string is too long. It appears that the compiler did not recognize the second quotation mark (“) as the closing quotation mark of the string and caused the compiler to recognize the rest of the code as the string. This problem possibly came from the fact that to display a quotation mark in a string, ” is used. The compiler probably recognized the second quotation mark as a string character instead of the closing quotation mark. I changed the “” to ” for the mean time, hoping it will work later on.

The next problem faced is that the source code uses malloc() and free() functions. These two functions are not included with C18 library. I replaced all the malloc() with SRAMalloc() and free() with SRAMfree(). SRAMalloc() and SRAMfree() are defined in the simple dynamic memory allocation module given by Microchip, “salloc.c”, which is used in the previous SD card project. Also, there is the same problem in the “MainDemo.c” file for this demo code and the same part of the code needs to be commented out. Otherwise, the Ethernet port LEDs will not lit up. Finally, the compiler successfully built the project and programmed it into the PICDEM.NET 2. The HTTP server can be accessed from the computer. There is a different webpage displayed when an SD card is inserted when compared with the webpage when an SD card is not inserted.

After that, I inserted the SD card into the computer but the SD card was not detected by the computer. I tested the card by formatting, writing and reading with the PIC18. The card worked flawlessly. But still, the card was not able to be detected by the computer. After some searching in Google, I put the Lock switch on the micro SD adapter just a little bit lower than it was, then the card was finally able to be detected by the computer.

So far, I was only able to verify that the code integrates both SD card and the TCP/IP stack. There are a lot of things to be verified and understood before I can modify the code to upload a bit stream to the SD card.


Michael · 2013-11-21 at 18:58

Hi. I’m trying to connect pic18f67j60 to the sd card . There must be stored the web page. I took the project from MDD File System-SD Card for pic18 and added more files from the Demo app mdd. But I’m having problems with http2_mdd.h. It always throws a syntax error. Have you had such problems?

Week3: PIC18 Schematic (cont’d) and Using a Raspberry Pi for SPI Testing | AESTE · 2013-07-20 at 23:08

[…] our project: writing the firmware for the PIC18. My colleague, Jia Xien, has been busy working on SD cards and establishing the TCP/IP stack on the PIC18, but I will be trying to configure the device as an […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.