Using the Arduino Ethernet shield with AMICUS18 (Joint forum project?)


Results 1 to 40 of 63

Threaded View

  1. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612

    Default Re: Using the Arduino Ethernet shield with AMICUS18 (Joint forum project?)

    Hi,
    I don't know what the "best" way to aproach this actually is. I don't think me posting hundreds or thousands of lines of code is going to actually help others that much and I don't think I'll get much out of it either.

    Instead I think I'll post snippets and routines, explaining what they do (or at least intend to do) and why. This way I think it's easier to tag along, one step at the time and, which is important, we can discuss suggestions on improvements and alternative ways of doing the same thing. In the end we will hopefully have a set of routines which can be used to build a working application.

    Before we go on I just have to point out that this is new territory for me too. I don't know much about ethernet, UDP, TCP, sockets, HTTP, HTML etc so this is very much a learning experience for me as well. Please feel free to correct any statements I make in error and please do bring suggestions on how to do things differently and, hopefully, better.


    Right, the Wiznet W5100 ethernet chip (which is used on the Ethernet shield) is controlled by reading and writing to its internal registers. There are quite a few registers and instead of using a bunch of 'magic numbers' (ie the adress of the register in the W5100's memory) I've put together a file (W5100_defs.pbp) containing the name and memory adress for the registers as well as a couple of other constants we might need. Attached to this post is v1.0 of that file (remove .txt extenstion), there might be newer versions in the posts to come.

    I've set up my AMICUS18 board to use the hardware USART at 115200 baud for debugging purposes. Then I set up the TRISB and TRISC registers to match the pinout of the modified Ethernet shield:
    Code:
    ' By default the AMICUS18 board uses the PIC18F25K20, make sure to
    ' set up MCSP or whatever IDE is being used to compile for the
    ' correct device.
     
    DEFINE OSC 64
    DEFINE LOADER_USED 1            ' We're using a bootloader.
    DEFINE HSER_RCSTA 90h           ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h           ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1           ' Clear overflow automatically
    DEFINE HSER_SPBRG 138           ' 115200 Baud @ 64MHz, -0,08%
     
    SPBRGH = 0
    BAUDCON.3 = 1                   ' Enable 16 bit baudrate generator
     
    TRISC = %10010111
    ' RC7: USART RX
    ' RC6: USART TX
    ' RC5: ETHERNET SPI Data out (SDO/MOSI)
    ' RC4: ETHERNET SPI Data in (SDI/MISO)
    ' RC3: ETHERNET SPI clock (SCK) set to INPUT according to datasheet....
    ' RC2: N/U - currently
    ' RC2: N/U - currently
    ' RC1: N/U - currently
     
    TRISB = %11011011
    ' RB7: N/U - currently
    ' RB6: N/U - currently
    ' RB5: ETHERNET Chip select line to W5100
    ' RB4: N/U - currently
    ' RB3: N/U - currently
    ' RB2: ETHERNET Chip select line to SD-Card
    ' RB1: N/U and can not be used with the Ethernet shield
    ' RB0: ETHERNET Interrupt pin from W5100

    Then I pretty much cut'n'pasted the register definition/aliases for the MSSP module from the SPI master example on MELABS web site. However, I had to change the CKE bit from 0 to 1 in order to get reliable communications with the W5100. This feels a bit awkward but since doing that it has been rock solid so it must be right - right?
    Code:
    ' Aliases for the MSSP module status and control bits.
    SSPEN   VAR     SSPCON1.5   ' SSP Enable bit  
    CKP     VAR     SSPCON1.4   ' Clock Polarity Select  
    SMP     VAR     SSPSTAT.7   ' Data input sample phase  
    CKE     VAR     SSPSTAT.6   ' Clock Edge Select bit  
    SSPIF   VAR     PIR1.3      ' SPI interrupt flag
     
    'Set up the MSSP module.
    CKP = 0                     ' Clock idles low  
    CKE = 1                     ' Transmit on active to idle transition.  
    SSPIF = 0                   ' Clear buffer full status  
    SMP = 0                     ' Sample in middle of data 
    SSPEN = 1                   ' Enable SPI pins
    SSPCON1.0 = 1              'Slow down SPI clock to Fosc/16 for now.
    I also had to slow down the SPI clock from the default (Fosc/4) to Fosc/16 in order to get reliable communication. The AMICUS18 defaults to 64MHz so with Fosc/16 the SPI clock is running at 4Mhz which isn't directly slow but well below what the W5100 is capable of (if I read the datasheet correctly that would be ~14Mhz). However, the modification done to the shield and the fact that W5100 is on a separate board from the 18F25K20 may have an impact on the maximum speed achievable. Anyway, I'll leave it at Fosc/16 for now.

    Finally I included the file with all the register definitions for the W5100:
    Code:
    INCLUDE "W5100_defs.pbp"        ' Register definitions and constants for the W5100.
    That's all for this post.

    /Henrik.
    Attached Files Attached Files

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts