ENC28J60 Bootloader

hi guys.

new to the forum but had to join to ask this possibly simple question to someone at least. My goal is to find a bootloader for the arduino (ATMEGA328) and ENC28J60 ethernet controller. I have found numerous ones for the wiznet controller and have used them! but only one uncompiled version exists (here Google Code Archive - Long-term storage for Google Code Project Hosting.) for the ENC28J60 and AVR's. I manged to download it and have downloaded the latest WINAVR and i have compiled a hex file. i have also manged to place the hex file on the arduino using an uno as a ISP running the isp software. i know the isp works as i have flashed the chip before to the arduino bootloader from a stock chip. so does anyone know where to get a compiled hex that works? or could you tell me where i am going wrong? the bootloader does come with a epp file that it asks to you place in the eprom of the chip i have no idea how to do this but i did modify the bootloader to use mac,ip adresses i programmed into it rather than reading from the eprom.

any help would be welcomed

thanks

All you need is the library. The device has it's own internal software and bootloader, and cannot be changed. Google the device on the web, or in this forum, it's a simple device with a few drawbacks- but they are cheap and work well for what they are...

maybe i didnt explain very clearly. i have no issues using the arduino and the ENC28J60 for normal operation. ie you use the standard arduino bootloader and download your compliled sketch files using the usb lead. what i want is a ethernet bootloader like ones for the wiznet chip that allow you to download your sketch via TFTP remotley. i have googled for days and the only one i could find was the uncomplied one i listed in my first post.

Ah.. I'd be impressed to see it, actually- the ENC setup is quite a bit more limited than the Wiznet. I've got an ENC and it's great for simple stuff- though I suppose there isn't anything that couldn't be done. It's SPI as I remember, so maybe finding a bootloader that boots from SPI and set up the module as a transparent "virtual serial"?

From avr-etherboot which device did you choose? Have you changed the configuration (config.h)? If yes, post that file.

yes i did change the config.h file to suit the pin outs for SCK, MOSI,MISO and CS.
this is the config.h file

#ifndef _CONFIG_H_
#define _CONFIG_H_

#include <stdio.h>
#include <avr/eeprom.h>
#include <avr/boot.h>

#define	MYMAC1 0x02
#define	MYMAC2 0x01
#define	MYMAC3 0x02
#define	MYMAC4 0x03
#define	MYMAC5 0x04
#define	MYMAC6 0x99


// BOOTLOADER_FLAVOR selects the version to build (see docs)
// allowed values are:  SMALL, MEDIUM, LARGE

#define BL_VERSION_SMALL  1
#define BL_VERSION_MEDIUM 2
#define BL_VERSION_LARGE  3

// makefile will pass the definition thru the compiler
// #define BOOTLOADER_FLAVOR BL_VERSION_SMALL

#if BOOTLOADER_FLAVOR >= BL_VERSION_MEDIUM
  #define USE_DHCP
  #define DHCP_PARSE_TFTP_PARAMS
#else
  #define FIXED_TFTP_SRV
#endif


#define DEBUG_AV				0
#define DEBUG_ENC_BUFFER_DATA	0
#define DEBUG_FLASH_PROG		0
#define DEBUG_TFTP				0
#define DEBUG_ARP				0

	
//-> enc28j60
#define USE_ENC28J60	1

// set these so that it reflects your hardware
// Net-IO board from Pollin
// #define ENC28J60_CONTROL_DDR	DDRB
// #define ENC28J60_CONTROL_PORT	PORTB

// Board Jan
#define ENC28J60_CONTROL_DDR	DDRD
#define ENC28J60_CONTROL_PORT	PORTD
		
#define ENC28J60_PIN_SCK	13
#define ENC28J60_PIN_MISO	12
#define ENC28J60_PIN_MOSI	11

// Net-IO board from Pollin
//#define ENC28J60_PIN_CS		4

// Board Jan
#define ENC28J60_PIN_CS		10


// -> SPI
#define SPI_PORT	PORTB
#define SPI_DDR		DDRB
#define MISO		ENC28J60_PIN_MISO
#define MOSI		ENC28J60_PIN_MOSI
#define SCK			ENC28J60_PIN_SCK


#if defined (__AVR_ATmega64__) || defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega128__)
	#define MTU_SIZE 1200
#else
	#define MTU_SIZE 600
#endif


/////////////////////////////// HELPERS ////////////////////////////////////////////
//DO NOT CHANGE ANYTHING BELOW!

//convert config ip to long:
#define IP(a0,a1,a2,a3) ((((unsigned long)(a3))<<24)|(((unsigned long)(a2))<<16)|(((unsigned long)(a1))<<8)|(unsigned long)(a0))

/*#define NIC_IP_ADDRESS \
				(((uint32_t)NIC_IP_ADDRESS_0)<<24 | \
				((uint32_t)NIC_IP_ADDRESS_1)<<16 | \
				((uint32_t)NIC_IP_ADDRESS_2)<< 8 | \
				((uint32_t)NIC_IP_ADDRESS_3))

#define NIC_IP_NETMASK \
				(((uint32_t)NIC_IP_NETMASK_0)<<24 | \
				((uint32_t)NIC_IP_NETMASK_1)<<16 | \
				((uint32_t)NIC_IP_NETMASK_2)<< 8 | \
				((uint32_t)NIC_IP_NETMASK_3))


#define NIC_GATEWAY_IP_ADDRESS \
				(((uint32_t)NIC_GATEWAY_IP_ADDRESS_0)<<24 | \
				((uint32_t)NIC_GATEWAY_IP_ADDRESS_1)<<16 | \
				((uint32_t)NIC_GATEWAY_IP_ADDRESS_2)<< 8 | \
				((uint32_t)NIC_GATEWAY_IP_ADDRESS_3))

#define NTP_SERVER_IP_ADDRESS \
				(((uint32_t)NTP_SERVER_IP_ADDRESS_0)<<24 | \
				((uint32_t)NTP_SERVER_IP_ADDRESS_1)<<16 | \
				((uint32_t)NTP_SERVER_IP_ADDRESS_2)<< 8 | \
				((uint32_t)NTP_SERVER_IP_ADDRESS_3))
*/

#define lo8(x) ((x   )&0xFF)
#define hi8(x) (((x)>>8)&0xFF)

// Debugging
#if DEBUG_AV

#include <avr/pgmspace.h>

void sendchar (unsigned char Zeichen) BOOTLOADER_SECTION;
void puthexbyte(uint8_t bt) BOOTLOADER_SECTION;
void putstring (unsigned char *string) BOOTLOADER_SECTION;
void putPGMstring(const char *progmem_s) BOOTLOADER_SECTION;
#define putpgmstring(__s) putPGMstring(PSTR(__s))
#endif

#endif
#define ENC28J60_PIN_SCK	13
#define ENC28J60_PIN_MISO	12
#define ENC28J60_PIN_MOSI	11
#define ENC28J60_PIN_CS		10

These values are wrong. You're not changing Arduino code but AVR code so pin numbers are not the pins numbers Arduino chose for it's boards but pin numbers of the chosen IO port of the ATmega328 controller. The range is from 0 to 7, so this has to read:

#define ENC28J60_PIN_SCK	5
#define ENC28J60_PIN_MISO	4
#define ENC28J60_PIN_MOSI	3
#define ENC28J60_PIN_CS		2

You have to change the values consistently:

#define SPI_PORT	PORTB
#define SPI_DDR		DDRB

must be

#define SPI_PORT	PORTD
#define SPI_DDR		DDRD

thanks for the reply pylon. i have changed the config.h file to reflect what you said recompiled and downloaded and still no joy?? it does say in the documentation for the bootloader that the epp file is required to downloaded to the device's ram. does anyone know how to do this? does anyoone have a complied hex that they know works with the ATMEGA 328 they can send me? its driving me mad. everytime i donwload my compiled hex the chip just sits there with PIN13 High as if its not running anycode??

The epp file has to be stored in the EEPROM of the processor. This can be done using avrdude (-U parameter).

What do you expect the hardware to do at bootup? Pin 13 is used as the clock line so with a standard multimeter this pin will look HIGH when measured. Have you checked with a scope? It should communicate with the ENC28J60 intensively during the first 5 seconds, jumping then to the non-existing application code. Do you have networt traffic on the ethernet interface in this time?

hi pylon. thanks for the reply. i have had a majour learning curve today with avrdude. it wasnt working correctly with my arduino uno as an isp. modified the .conf file so the baud rate has been reduced to match that of the arduino sketch (9600) the -b over-ride parameter would not do anything. anyway i managed to get both the hex and epp files onto my chip and still no life! when i say that pin 13 is high i mean the led is on, when there is traffic you can see it blink ie talking to the ENC28J60. i will post my make.in file that defines the compiler. if this helps

#
# Please note that this file has been generated by make.
# DO NOT EDIT THIS FILE
# If you wish to change the configuration of the bootloader
# please type 'make distclean' and then 'make' on the command line.
#
MCU = atmega32
EMB_FLASHEND = 0x7FFF
EMB_BOOTLOADER_SECTION_START = 0x7C00
EMB_LINKER_SCRIPT = -T ../make.files/eth-avr5.x
F_CPU = 16000000
EMB_BOOTLOADER_FLAVOR = 1
MCU = atmega32

Do you really put that on a ATmega32? In your previous posts you wrote about a ATmega328.

your correct, duh... it looks like this is never going to work. the avr-ethernet only suports atmega32 and a few others not the 328. my mistake and newness to the world of atmega. i assumed and one should never assume that atmega32 refered to any chip in the 32 range ie 328. so my question is where can i find a bootloader for the Atmega328 and ENC28J60? or would there be a way to modify the one written for the atmega32 to run on a atmega328?

or would there be a way to modify the one written for the atmega32 to run on a atmega328?

Sure, the differences are not fundamental but they exist and therefore you have to change some code and configuration in the library. I don't have the hardware (ENC28J60) yet, so I cannot test stuff myself.