20081111 40P68 to V4.51

Microchip TCPIP 4.51 setting up for PIC18F4610 on 40P68 board (building on www.nuiure.com)

I will make use of the on hand PICDEM Net board to verify that some of my settings are correct (ie enabling ENC28J60) before moving to the new board.  (PICDEM Net 2 was previously running TCPIP Stack version 4.13

Hardware:

PICKIT 2 installed & connected
PICDEM NET 2 connected to PICKIT 2 & connected to network (with DHCP server available) via J1

Setup software: 

1. Installed Microchip MPLab IDE 8.15

2. Installed Microchip C18 Student Version 3.22

3. Installed Microchip TCPIP Stack 4.51

Following 'Getting Started' in the help files provided with TCPIP 4.51:

4. Ran the Microchip Config Wizard and left the board name as MCHPBoard, set the NIC address per the sticker on the bottom.  Note this updates TCPIPConfig.h and leaves a copy of the original as TCPIPConfig.dist

5. In MPLab IDE: opened C:\Microchip Solutions\TCPIP Demo App\TCPIP Demo App-C18 project and did a Project -> Build All

6. In MPLab IDE: Programmer -> Select Programmer -> PicKit 2

7. In MPLAB IDE: Programmer -> Program

8. Hold Down Button 0 (RB3) on PICDEM Net 2 and power on/off to clear EEPROM settings

9. PICDEM Net 2 should pick up TCPIP address and display it on the LCD..

10 In a browser goto 192.168.1.14/mpfsupload (where 192.. etc matches the LCD displayed IP address) and navigate to C:\Microchip Solutions\TCPIP Demo App and select MPFSImg2.bin and Upload..

Tasks:

Set to use ENC28J60

Set MPLab to use PIC18F4610

Set pin assignments to match our target PIC18F4610

Remove not required modules so we can get it to fit in our target processor


Set to use ENC28J60

In MPLab IDE (assumes C:\Microchip Solutions\TCPIP Demo App\TCPIP Demo App-C18 project is still open)

- Edit C:\Microchip Solutions\TCPIP Demo App\hardwareprofile.h (It shows in the Project files list (Menu VIEW->PROJECT) under header files, double click to edit it)

- Search for and uncomment the 2 x lines with this text (as a comment on the commented lines :)  "Uncomment this line if you wish to use the ENC28J60.. on the PICDEM Net 2.."  (not we actually only need to do it for the Non Hitech C section but its easier to just find both)

- Save and Close hardwareprofile.h

- Do a Build and program the PICDEM Net 2 as earlier, move the Ethernet connector to J2 and start it up.


Set MPLab to use PIC18F4610

In MPLab IDE (assumes C:\Microchip Solutions\TCPIP Demo App\TCPIP Demo App-C18 project is still open)

- Configure -> Select Device: PIC18F4610

- Edit hardwareprofile.h

  • At the top of the file, uncomment the line: "#define YOUR_BOARD"

  • In the '// Set configuration fuses (but only once)' section ( we may come back here to change our config fuses as necessary later..):

  • Note that I also added in PIC18F4682 & PIC18F4685 as we have these on hand as well in case we need more rom..

 Copy and paste this below it as this
 #elif defined(__18F4620) 
   // PICDEM Z board
   #pragma config OSC=HSPLL, WDT=OFF, MCLRE=ON, PBADEN=OFF, LVP=OFF
  #elif defined(__18F4620 ) || defined(__18F4610 ) || defined(__18F4682 ) || defined(__18F4685 )
   // My Board
   #pragma config OSC=HSPLL, WDT=OFF, MCLRE=ON, PBADEN=OFF, LVP=OFF

  • In the '// Clock frequency value' section:

 Copy and paste this below it as this
#elif defined(PICDEMZ)
  #define GetSystemClock()  (16000000ul)      // Hz
  #define GetInstructionClock() (GetSystemClock()/4)
  #define GetPeripheralClock() GetInstructionClock()
#elif defined(YOUR_BOARD)
  #define GetSystemClock()  (40000000ul)      // Hz
  #define GetInstructionClock() (GetSystemClock()/4)
  #define GetPeripheralClock() GetInstructionClock() 


Set pin assignments to match our target PIC18F4610

Pin assignments:

Note1: The default application assumes certain other connections based on the PICDEM Net 2 board:

Temperature sensor on RA3

Potentiometer on RA2

We wont be using these but the default application still assumes they are there.  If we want to use these pins in the future we will have to remove the associated code as well.

PICDEM Net 2 Module   PICDEM Net 2 Connection   Pin CountPlugNProg Module   PlugNProg ConnectionPin Count
4 x TactRB0-344 x TactRB4-74
Analogue Temp SensorRA31   
PotentiometerRA21   
8 x LEDSRJ0-781 4LEDRB0-34
RS232RC6-72   
LCD Data (D0-7)RE0-78JM162B LCD D4-7RD0-34
LCD ERH01JM162B LCD Control - (Pin 3) - ERE21
LCD R/WRH11JM162B LCD Control - (Pin 2) - R/WRE11
LCD RSRH21JM162B LCD Control (Pin 1) - RSRE01
SPI SCKRC31SPI Breakout SPI InRC31
SPI SDIRC41SPI Breakout SPI InRC41
SPI SDORC51SPI Breakout SPI InRC51
ENC28J60 Chip SelectRD31SPI Breakout Select (SPI Out 1)RA41
25LC256 EEPROM Chip SelectRD71SPI Breakout Select (SPI Out 2)RA51
 Total Pins:32 Total Pins:20

In MPLab IDE (assumes C:\Microchip Solutions\TCPIP Demo App\TCPIP Demo App-C18 project is still open)

- Edit hardwareprofile.h

In the '// Hardware mappings' section:

We will copy the PICDEM Net 2 settings as our starting point.  Find '#elif defined(PICDEMNET2) && !defined(HI_TECH_C)' and copy that set of declarations to the '// Define your own board hardware profile here' section.

Now we edit each set of pins to change the mappings per our own board per the pin assignments table above..:

 Change this  to this Note
 // I/O pins
 #define LED0_TRIS   (TRISJbits.TRISJ0)
 #define LED0_IO    (LATJbits.LATJ0)
 #define LED1_TRIS   (TRISJbits.TRISJ1)
 #define LED1_IO    (LATJbits.LATJ1)
 #define LED2_TRIS   (TRISJbits.TRISJ2)
 #define LED2_IO    (LATJbits.LATJ2)
 #define LED3_TRIS   (TRISJbits.TRISJ3)
 #define LED3_IO    (LATJbits.LATJ3)
 #define LED4_TRIS   (TRISJbits.TRISJ4)
 #define LED4_IO    (LATJbits.LATJ4)
 #define LED5_TRIS   (TRISJbits.TRISJ5)
 #define LED5_IO    (LATJbits.LATJ5)
 #define LED6_TRIS   (TRISJbits.TRISJ6)
 #define LED6_IO    (LATJbits.LATJ6)
 #define LED7_TRIS   (TRISJbits.TRISJ7)
 #define LED7_IO    (LATJbits.LATJ7)
 #define LED_GET()   (LATJ)
 #define LED_PUT(a)   (LATJ = (a))
  // I/O pins
 #define LED0_TRIS   (TRISBbits.TRISB0)
 #define LED0_IO    (LATBbits.LATB0)
 #define LED1_TRIS   (TRISBbits.TRISB1)
 #define LED1_IO    (LATBbits.LATB1)
 #define LED2_TRIS   (TRISBbits.TRISB2)
 #define LED2_IO    (LATBbits.LATB2)
 #define LED3_TRIS   (TRISBbits.TRISB3)
 #define LED3_IO    (LATBbits.LATB3)
 #define LED4_TRIS   (TRISBbits.TRISB4)    // No LED4
 #define LED4_IO    (LATBbits.LATB4)
 #define LED5_TRIS   (TRISBbits.TRISB5)    // No LED5
 #define LED5_IO    (LATBbits.LATB5)
 #define LED6_TRIS   (TRISBbits.TRISB6)    // No LED6
 #define LED6_IO    (LATBbits.LATB6)
 #define LED7_TRIS   (TRISBbits.TRISB7)    // No LED7
 #define LED7_IO    (LATBbits.LATB7)
 #define LED_GET()   ((LED3_IO<<3) | (LED2_IO<<2) | (LED1_IO<<1) | LED0_IO)
 #define LED_PUT(a)   do{BYTE vTemp = (a); LED0_IO = vTemp&0x1; LED1_IO = vTemp&0x2; LED2_IO = vTemp&0x4; LED3_IO = vTemp&0x8;} while(0)
 Change all J port assignments to B.. no Leds 4-7 so dummy these (is that what PRODL does?)
 #define BUTTON0_TRIS  (TRISBbits.TRISB3)
 #define BUTTON0_IO   (PORTBbits.RB3)
 #define BUTTON1_TRIS  (TRISBbits.TRISB2)
 #define BUTTON1_IO   (PORTBbits.RB2)
 #define BUTTON2_TRIS  (TRISBbits.TRISB1)
 #define BUTTON2_IO   (PORTBbits.RB1)
 #define BUTTON3_TRIS  (TRISBbits.TRISB0)
 #define BUTTON3_IO   (PORTBbits.RB0)
 #define BUTTON0_TRIS  (TRISDbits.TRISD4)
 #define BUTTON0_IO   (PORTDbits.RD4)
 #define BUTTON1_TRIS  (TRISDbits.TRISD5)
 #define BUTTON1_IO   (PORTDbits.RD5)
 #define BUTTON2_TRIS  (TRISDbits.TRISD6)
 #define BUTTON2_IO   (PORTDbits.RD6)
 #define BUTTON3_TRIS  (TRISDbits.TRISD7)
 #define BUTTON3_IO   (PORTDbits.RD7)
 B0-3 to B7-4 (reversed ordering as well)

  • For the SPI assignments:
    • Checked the aforementioned PICDEMZ definitions and noticed that as the PIC18F6420 (and PIC18F6410 by implication) only have one SPI peripheral.. the definitions are different for some of the control bits..
    • Note '#define ENC_RST_TRIS (TRISDbits.TRISD2) // Not connected by default', I have empirically found it does not need to be assigned
 Change this to thisNote 

 // ENC28J60 I/O pins
 #define ENC_RST_TRIS  (TRISDbits.TRISD2) // Not connected by default
 #define ENC_RST_IO   (LATDbits.LATD2)
 #define ENC_CS_TRIS   (TRISDbits.TRISD3) // Uncomment this line if you wish to use the ENC28J60 on the PICDEM.net 2 board instead of the internal PIC18F97J60 Ethernet module
 #define ENC_CS_IO   (LATDbits.LATD3)
 #define ENC_SCK_TRIS  (TRISCbits.TRISC3)
 #define ENC_SDI_TRIS  (TRISCbits.TRISC4)
 #define ENC_SDO_TRIS  (TRISCbits.TRISC5)
 #define ENC_SPI_IF   (PIR1bits.SSPIF)
 #define ENC_SSPBUF   (SSP1BUF)
 #define ENC_SPISTAT   (SSP1STAT)
 #define ENC_SPISTATbits  (SSP1STATbits)
 #define ENC_SPICON1   (SSP1CON1)
 #define ENC_SPICON1bits  (SSP1CON1bits)
 #define ENC_SPICON2   (SSP1CON2)

 // ENC28J60 I/O pins
 #define ENC_CS_TRIS   (TRISAbits.TRISA4)
 #define ENC_CS_IO   (LATAbits.LATA4)
 #define ENC_SCK_TRIS  (TRISCbits.TRISC3)
 #define ENC_SDI_TRIS  (TRISCbits.TRISC4)
 #define ENC_SDO_TRIS  (TRISCbits.TRISC5)
 #define ENC_SPI_IF   (PIR1bits.SSPIF)
 #define ENC_SSPBUF (SSPBUF)
 #define ENC_SPISTAT (SSPSTAT)
 #define ENC_SPISTATbits (SSPSTATbits)
 #define ENC_SPICON1 (SSPCON1)
 #define ENC_SPICON1bits (SSPCON1

 

// 25LC256 I/O pins
 #define EEPROM_CS_TRIS  (TRISDbits.TRISD7)
 #define EEPROM_CS_IO  (LATDbits.LATD7)
 #define EEPROM_SCK_TRIS  (TRISCbits.TRISC3)
 #define EEPROM_SDI_TRIS  (TRISCbits.TRISC4)
 #define EEPROM_SDO_TRIS  (TRISCbits.TRISC5)
 #define EEPROM_SPI_IF  (PIR1bits.SSPIF)
 #define EEPROM_SSPBUF  (SSPBUF)
 #define EEPROM_SPICON1  (SSP1CON1)
 #define EEPROM_SPICON1bits (SSP1CON1bits)
 #define EEPROM_SPICON2  (SSP1CON2)
 #define EEPROM_SPISTAT  (SSP1STAT)
 #define EEPROM_SPISTATbits (SSP1STATbits)

 

 // 25LC256 I/O pins
#define EEPROM_CS_TRIS (TRISAbits.TRISA5)
#define EEPROM_CS_IO (LATAbits.LATA5)
#define EEPROM_SCK_TRIS (TRISCbits.TRISC3)
#define EEPROM_SDI_TRIS (TRISCbits.TRISC4)
#define EEPROM_SDO_TRIS (TRISCbits.TRISC5)
#define EEPROM_SPI_IF (PIR1bits.SSPIF)
#define EEPROM_SSPBUF (SSPBUF)
#define EEPROM_SPICON1 (SSPCON1)
#define EEPROM_SPICON1bits (SSPCON1bits)
#define EEPROM_SPICON2 (SSPCON2)
#define EEPROM_SPISTAT (SSPSTAT)
#define EEPROM_SPISTATbits (SSPSTATbits)

 

// LCD I/O pins
 #define LCD_DATA_TRIS  (TRISE)
 #define LCD_DATA_IO   (LATE)
 #define LCD_RD_WR_TRIS  (TRISHbits.TRISH1)
 #define LCD_RD_WR_IO  (LATHbits.LATH1)
 #define LCD_RS_TRIS   (TRISHbits.TRISH2)
 #define LCD_RS_IO   (LATHbits.LATH2)
 #define LCD_E_TRIS   (TRISHbits.TRISH0)
 #define LCD_E_IO   (LATHbits.LATH0)

// LCD I/O pins
//#define LCD_DATA_TRIS (TRISD)
//#define LCD_DATA_IO (LATD)
#define LCD_DATA0_TRIS  (TRISDbits.TRISD0)
#define LCD_DATA0_IO  (LATDbits.LATD0)
#define LCD_DATA1_TRIS  (TRISDbits.TRISD1)
#define LCD_DATA1_IO  (LATDbits.LATD1)
#define LCD_DATA2_TRIS  (TRISDbits.TRISD2)
#define LCD_DATA2_IO  (LATDbits.LATD2)
#define LCD_DATA3_TRIS  (TRISDbits.TRISD3)
#define LCD_DATA3_IO  (LATDbits.LATD3)

#define LCD_RD_WR_TRIS (TRISEbits.TRISE1)
#define LCD_RD_WR_IO (LATEbits.LATE1)
#define LCD_RS_TRIS (TRISEbits.TRISE0)
#define LCD_RS_IO (LATEbits.LATE0)
#define LCD_E_TRIS (TRISEbits.TRISE2)
#define LCD_E_IO (LATEbits.LATE2)

 

LCD into 4 bit mode.. edit LCDBlocking.c to turn on 4 bit mode, and also fix the bug..

 From To

 //#define FOUR_BIT_MODE
#define SAMSUNG_S6A0032  // This LCD driver chip has a different means of entering 4-bit mode. 

#define FOUR_BIT_MODE
//#define SAMSUNG_S6A0032  // This LCD driver chip has a different means of entering 4-bit mode.   

LCD_DATA0_IO = Data & 0x10;
LCD_DATA1_IO = Data & 0x20;
LCD_DATA2_IO = Data & 0x40;
LCD_DATA3_IO = Data & 0x80;

  LCD_DATA0_IO = ((Data & 0x10) == 0x10);
  LCD_DATA1_IO = ((Data & 0x20) == 0x20);
  LCD_DATA2_IO = ((Data & 0x40) == 0x40);
  LCD_DATA3_IO = ((Data & 0x80) == 0x80);


Remove not required modules so we can get it to fit in our target processor

Ok, now doing a Project -> Build All and it fails on space, changing back to the PICDEM Net 2 and after another Project -> Build All we can check the space required is 55296, and the poor PIC18F4610 only has room for 32k instructions, heck even the PIC18F4685 only has room for 48k instructions.

So time to remove some modules..

In MPLab IDE, edit tcpipconfig.h:

Overall module in/out settings are in the '//   Application Options' section:

  My bare minimum
 

 //#define STACK_USE_UART     // Application demo using UART for IP address display and stack configuration
//#define STACK_USE_UART2TCP_BRIDGE  // UART to TCP Bridge application example
//#define STACK_USE_IP_GLEANING
//#define STACK_USE_ICMP_SERVER
//#define STACK_USE_ICMP_CLIENT
//#define STACK_USE_HTTP_SERVER   // Old HTTP server
#define STACK_USE_HTTP2_SERVER   // New HTTP server with POST, Cookies, Authentication, etc.
//#define STACK_USE_SSL_SERVER   // SSL server socket support (Requires SW300052)
//#define STACK_USE_SSL_CLIENT   // SSL client socket support (Requires SW300052)
//#define STACK_USE_DHCP_CLIENT
//#define STACK_USE_DHCP_SERVER
//#define STACK_USE_FTP_SERVER
//define STACK_USE_SMTP_CLIENT
//#define STACK_USE_SNMP_SERVER
//#define STACK_USE_TFTP_CLIENT
//#define STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE // HTTP Client example in GenericTCPClient.c
//#define STACK_USE_GENERIC_TCP_SERVER_EXAMPLE // ToUpper server example in GenericTCPServer.c
//#define STACK_USE_TELNET_SERVER   // Telnet server
//#define STACK_USE_ANNOUNCE    // Microchip Embedded Ethernet Device Discoverer server/client
//#define STACK_USE_DNS     // Domain Name Service Client
//#define STACK_USE_NBNS     // NetBIOS Name Service Server
//#define STACK_USE_REBOOT_SERVER   // Module for resetting this PIC remotely.  Primarily useful for a Bootloader.
//#define STACK_USE_SNTP_CLIENT   // Simple Network Time Protocol for obtaining current date/time from Internet
//#define STACK_USE_UDP_PERFORMANCE_TEST // Module for testing UDP TX performance characteristics.  NOTE: Enabling this will cause a huge amount of UDP broadcast packets to flood your network on various ports.  Use care when enabling this on production networks, especially with VPNs (could tunnel broadcast traffic across a limited bandwidth connection).
//#define STACK_USE_TCP_PERFORMANCE_TEST // Module for testing TCP TX performance characteristics
//#define STACK_USE_DYNAMICDNS_CLIENT  // Dynamic DNS client module
//#define STACK_USE_BERKELEY_API   // Berekely Sockets APIs are used

Note that disabling some items breaks dependancies, such as the Email demo needs HTTP2 & SMTP client modules installed, so to get the project to compile we need to change additional settings further on in the '//   Application-Specific Options' section:

 
  

 // Define which HTTP modules to use
 // If not using a specific module, comment it to save resources
 #define HTTP_USE_POST     // Enable POST support
 #define HTTP_USE_COOKIES    // Enable cookie support
 #define HTTP_USE_AUTHENTICATION   // Enable basic authentication support
 
 //#define HTTP_NO_AUTH_WITHOUT_SSL  // Uncomment to require SSL before requesting a password
 #define HTTP_SSL_ONLY_CHAR  (0xFF) // Files beginning with this character will only be served over HTTPS
           // Set to 0x00 to require for all files
           // Set to 0xff to require for no files

 #define STACK_USE_HTTP_APP_RECONFIG  // Use the AppConfig web page in the Demo App (~2.5kb ROM, ~0b RAM)
 #define STACK_USE_HTTP_MD5_DEMO   // Use the MD5 Demo web page (~5kb ROM, ~160b RAM)
 #define STACK_USE_HTTP_EMAIL_DEMO  // Use the e-mail demo web page 

  // Define which HTTP modules to use
 // If not using a specific module, comment it to save resources
 #define HTTP_USE_POST     // Enable POST support
// #define HTTP_USE_COOKIES    // Enable cookie support
 #define HTTP_USE_AUTHENTICATION   // Enable basic authentication support
 
 //#define HTTP_NO_AUTH_WITHOUT_SSL  // Uncomment to require SSL before requesting a password
 #define HTTP_SSL_ONLY_CHAR  (0xFF) // Files beginning with this character will only be served over HTTPS
           // Set to 0x00 to require for all files
           // Set to 0xff to require for no files

 #define STACK_USE_HTTP_APP_RECONFIG  // Use the AppConfig web page in the Demo App (~2.5kb ROM, ~0b RAM)
// #define STACK_USE_HTTP_MD5_DEMO   // Use the MD5 Demo web page (~5kb ROM, ~160b RAM)
// #define STACK_USE_HTTP_EMAIL_DEMO  // Use the e-mail demo web page

 

Since we removed all DHCP modules, we will hardcode the IP addresses under the section: '//   Network Addressing Options':

Note this will require an EEPROM reset of the board (Hold down button 0 whilst powering up for 4 seconds)

 From To

#define MY_DEFAULT_IP_ADDR_BYTE1        (169ul)
#define MY_DEFAULT_IP_ADDR_BYTE2        (254ul)
#define MY_DEFAULT_IP_ADDR_BYTE3        (1ul)
#define MY_DEFAULT_IP_ADDR_BYTE4        (1ul)

#define MY_DEFAULT_MASK_BYTE1           (255ul)
#define MY_DEFAULT_MASK_BYTE2           (255ul)
#define MY_DEFAULT_MASK_BYTE3           (0ul)
#define MY_DEFAULT_MASK_BYTE4           (0ul)

#define MY_DEFAULT_GATE_BYTE1           (169ul)
#define MY_DEFAULT_GATE_BYTE2           (254ul)
#define MY_DEFAULT_GATE_BYTE3           (1ul)
#define MY_DEFAULT_GATE_BYTE4           (1ul)

#define MY_DEFAULT_PRIMARY_DNS_BYTE1 (169ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE2 (254ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE3 (1ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE4 (1ul)

#define MY_DEFAULT_SECONDARY_DNS_BYTE1 (169ul)
#define MY_DEFAULT_SECONDARY_DNS_BYTE2 (254ul)
#define MY_DEFAULT_SECONDARY_DNS_BYTE3 (1ul)
#define MY_DEFAULT_SECONDARY_DNS_BYTE4 (1ul) 

 #define MY_DEFAULT_IP_ADDR_BYTE1        (192ul)
#define MY_DEFAULT_IP_ADDR_BYTE2        (168ul)
#define MY_DEFAULT_IP_ADDR_BYTE3        (1ul)
#define MY_DEFAULT_IP_ADDR_BYTE4        (21ul)

#define MY_DEFAULT_MASK_BYTE1           (255ul)
#define MY_DEFAULT_MASK_BYTE2           (255ul)
#define MY_DEFAULT_MASK_BYTE3           (2550ul)
#define MY_DEFAULT_MASK_BYTE4           (0ul)

#define MY_DEFAULT_GATE_BYTE1           (192ul)
#define MY_DEFAULT_GATE_BYTE2           (168ul)
#define MY_DEFAULT_GATE_BYTE3           (1ul)
#define MY_DEFAULT_GATE_BYTE4           (1ul)

#define MY_DEFAULT_PRIMARY_DNS_BYTE1 (192ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE2 (168ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE3 (1)
#define MY_DEFAULT_PRIMARY_DNS_BYTE4 (1)

#define MY_DEFAULT_SECONDARY_DNS_BYTE1 (192ul)
#define MY_DEFAULT_SECONDARY_DNS_BYTE2 (168ul)
#define MY_DEFAULT_SECONDARY_DNS_BYTE3 (1)
#define MY_DEFAULT_SECONDARY_DNS_BYTE4 (1)