Go Down

Topic: ENC28J60 Bootloader (Read 1 time) previous topic - next topic

schilvers

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
Code: [Select]
#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



pylon

Code: [Select]
#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:

Code: [Select]
#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:

Code: [Select]
#define SPI_PORT PORTB
#define SPI_DDR DDRB


must be

Code: [Select]
#define SPI_PORT PORTD
#define SPI_DDR DDRD


schilvers

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??

pylon

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?

schilvers

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
Code: [Select]
#
# 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

Go Up