Author Topic: ENC242J600 Interfacing  (Read 1732 times)

Tostikoning

  • Newbie
  • *
  • Posts: 9
    • View Profile
ENC242J600 Interfacing
« on: September 11, 2012, 02:36:26 AM »
Hello!

I am trying to interface the ENC242J600 on the SBC66EC R1 but I cant seem to read any address or write one for that matter. I looked at the schematic and I came to the conclusion that the ENC242 is in PSP mode 5, is this correct? I wrote a UART function to debug, this is my debug code:

Code: [Select]
#include "uart.c"

void main()
{
     UART_Init();
     
     delay_ms(5000);
     
             ANSD = 0;
             ANSF = 0;
             ANSB = 0;
             
             TRISE = 0;
             TRISB = 0;
             TRISD = 0;
             TRISF = 0;
             
             PORTF = 0;
             PORTB = 0x0000;
             PORTE = 0x0000;
             PORTD = 0x0000;
             
             
             UART_SendString("** ANS **", 1);
             UART_SendString("ANSD", 1);
             UART_Hex(ANSD);
             UART_SendString("ANSF", 1);
             UART_Hex(ANSD);
             UART_SendString("ANSB", 1);
             UART_Hex(ANSD);
             
             UART_SendString(" ", 1);
             UART_SendString("** TRIS **", 1);
             UART_SendString("TRISE", 1);
             UART_Hex(TRISE);
             UART_SendString("TRISB", 1);
             UART_Hex(TRISB);
             UART_SendString("TRISD", 1);
             UART_Hex(TRISD);
             UART_SendString("TRISF", 1);
             UART_Hex(TRISF);
             
             UART_SendString(" ", 1);
             UART_SendString("** PORT **", 1);
             UART_SendString("PORTE", 1);
             UART_Hex(PORTE);
             UART_SendString("PORTB", 1);
             UART_Hex(PORTB);
             UART_SendString("PORTD", 1);
             UART_Hex(PORTD);
             UART_SendString("PORTF", 1);
             UART_Hex(PORTF);

             
             PORTE = 0x7E1A;      // ECON2L address
             
             UART_SendString(" ", 1);
             UART_SendString("** Address **", 1);
             UART_SendString("PORTE = ", 1);
             UART_Hex(PORTE);
             
             // AL
             UART_SendString(" ", 1);
             UART_SendString("** AL **", 1);
             
             if(PORTBbits.RB15 == 1)
                               UART_SendString("AL = 1", 1);
             else
                               UART_SendString("AL = 0", 1);
             
             PORTBbits.RB15 = 1;
             delay_us(10);
             
             if(PORTBbits.RB15 == 1)
                               UART_SendString("AL = 1", 1);
             else
                               UART_SendString("AL = 0", 1);

             
             PORTBbits.RB15 = 0;
             delay_us(10);
             
             if(PORTBbits.RB15 == 1)
                               UART_SendString("AL = 1", 1);
             else
                               UART_SendString("AL = 0", 1);

             //READ
             UART_SendString(" ", 1);
             UART_SendString("** Read **", 1);
             UART_SendString("TRISE = ", 1);
             UART_Hex(TRISE);
             TRISE = 0xFFFF;
             UART_SendString("TRISE = ", 1);
             UART_Hex(TRISE);
             
             if(PORTDbits.RD5 == 1)
                               UART_SendString("RD = 1", 1);
             else
                               UART_SendString("RD = 0", 1);

             PORTDbits.RD5 = 1;
             delay_us(10);

             if(PORTDbits.RD5 == 1)
                               UART_SendString("RD = 1", 1);
             else
                               UART_SendString("RD = 0", 1);

             delay_us(10);
             UART_SendString("* Input on PORTE = ",1);
             UART_Hex(PORTE);

             PORTDbits.RD5 = 0;
             delay_us(10);
             
             if(PORTDbits.RD5 == 1)
                               UART_SendString("RD = 1", 1);
             else
                               UART_SendString("RD = 0", 1);

     while(1);

}

And this is the UART output:

Code: [Select]
** ANS **
ANSD0x0000
ANSF0x0000
ANSB0x0000
 
** TRIS **
TRISE0x0000
TRISB0x0000
TRISD0x0000
TRISF0x0000
 
** PORT **
PORTE0x0000
PORTB0x0000
PORTD0x0000
PORTF0x0000
 
** Address **
PORTE = 0x001A
 
** AL **
AL = 0
AL = 1
AL = 0
 
** Read **
TRISE = 0x0000
TRISE = 0x00FF
RD = 0
RD = 1
* Input on PORTE = 0x0000
RD = 0

I don't see what I am doing wrong. I read the datasheet and did everything according to it.

Many thanks!

netcruze

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: ENC242J600 Interfacing
« Reply #1 on: September 12, 2012, 12:25:10 AM »
Interfacing to the ENC242J600 chip is very complicated. It can not be done with PSP mode, and is done via "bit banging". The reason is that the PSP peripheral on the PIC24FJ256GB206 chip used on the SBC66EC is not compatible with the parallel port on the ENC chip. I have already contacted Microchip about this, and confirmed it.

All interfacing is already done in the Microchip TCP/IP stack. You can download our "Netcruzer Webserver" that already has all this code working. The SBC66 board you would have received also already has a working webserver on it. Please dowload the Webserver project, and see in the code how the interfacing is done. Also note that you can damage your board by configuring it wrong! For example, setting PIC ports pins to outputs that are connected to output ports of the ENC chip can cause the chips to blow! You will have two outputs driving against each other! I would highly recommend you use the webserver project as your starting point, and modify if for your needs.

Documentation, and links to download the webserver project (full source code) is here:
http://www.netcruzer.com/nz/doc/proj_webserver


Tostikoning

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: ENC242J600 Interfacing
« Reply #2 on: September 12, 2012, 07:08:00 AM »
I had problems with uploading the webserver project because i have a different programmer. But I have found the problem. You need to use the LATx registers to bit bang the outputs. I have the chip working now! Thanks a lot!