Sanguino and Ethernet Shield

Hi!

I'm trying to connect the Ethernet Shield (W5100) to a Sanguino.

It was working with an Arduino. I disconnected the ethernet shield and wired pins 3,3V,GND,13,12,11,10 from the shield to the Arduino to be sure that no other pins are used. It worked.

I took the datasheets and the Sanguino : 13,12,11,10 are of course SCK, MISO, MOSI and SS of the ATmega168. SCK, MISO, MOSI and SS are the Atmega 644 pins 8,7,6,5 (or from the IDE 7,6,5,4). I connected the Ethernet shield pins to the Sanguino pins as just said and I took the 3,3V from an empty Arduino (connected to USB). I grounded everything together.

But... no success.

Could somebody help me? Nobody wrote about it on internet and since an Ethernet library is supplied with the Sanguino...

:) tep

SS is defined in spi.h as PB2 (Arduino D10). You need to either modify the file (define SS as PB4) or change the connection to pin 3 (PB2) of atmega644.

Thank you, I will try that :)

Not much success so far... I first tried to change physically the pin, without success, then tried to modify spi.h :

//-----------------------------------------------------------------------------
//AVR Mega168 SPI HAL
#define BIT0                                          0x01
#define BIT1                                          0x02
#define BIT2                                          0x04
#define BIT3                                          0x08
#define BIT4                                          0x10
#define BIT5                                          0x20
#define BIT6                                          0x40
#define BIT7                                          0x80

#define SPI0_SS_BIT                                    BIT2
#define SPI0_SS_DDR                                    DDRB
#define SPI0_SS_PORT                              PORTB

#define SPI0_SCLK_BIT                              BIT5
#define SPI0_SCLK_DDR                              DDRB
#define SPI0_SCLK_PORT                              PORTB

#define      SPI0_MOSI_BIT                              BIT3
#define SPI0_MOSI_DDR                              DDRB
#define SPI0_MOSI_PORT                              PORTB

#define      SPI0_MISO_BIT                              BIT4
#define SPI0_MISO_DDR                              DDRB
#define SPI0_MISO_PORT                              PORTB


#define SPI0_WaitForReceive()                        
#define SPI0_RxData()                               (SPDR)

#define SPI0_TxData(Data)                        (SPDR = Data)
#define SPI0_WaitForSend()                        while( (SPSR & 0x80)==0x00 )

#define SPI0_SendByte(Data)                        SPI0_TxData(Data);SPI0_WaitForSend()
#define SPI0_RecvBute()                              SPI0_RxData()

// PB4(MISO), PB3(MOSI), PB5(SCK), PB2(/SS)         // CS=1, waiting for SPI start // SPI mode 0, 4MHz

#define SPI0_Init()                                    DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT;\
                                                            PORTB |= SPI0_SS_BIT; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\
                                                            SPCR  = 0x50  
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//IInChip SPI HAL
#define IINCHIP_SpiInit                              SPI0_Init
#define IINCHIP_SpiSendData                        SPI0_SendByte      
#define IINCHIP_SpiRecvData                        SPI0_RxData


#define IINCHIP_CS_BIT                              BIT2
#define IINCHIP_CS_DDR                              DDRB
#define IINCHIP_CS_PORT                              PORTB

#define IINCHIP_CSInit()                              (IINCHIP_CS_DDR |= IINCHIP_CS_BIT)
#define IINCHIP_CSon()                              (IINCHIP_CS_PORT |= IINCHIP_CS_BIT)
#define IINCHIP_CSoff()                              (IINCHIP_CS_PORT &= ~IINCHIP_CS_BIT)
//-----------------------------------------------------------------------------

First part to:

#define SPI0_SS_BIT                                    BIT4
#define SPI0_SS_DDR                                    DDRB
#define SPI0_SS_PORT                              PORTB

#define SPI0_SCLK_BIT                              BIT7
#define SPI0_SCLK_DDR                              DDRB
#define SPI0_SCLK_PORT                              PORTB

#define      SPI0_MOSI_BIT                              BIT5
#define SPI0_MOSI_DDR                              DDRB
#define SPI0_MOSI_PORT                              PORTB

#define      SPI0_MISO_BIT                              BIT6
#define SPI0_MISO_DDR                              DDRB
#define SPI0_MISO_PORT                              PORTB

But it seems I missed something :(

I did not do this myself, so I am not talking from experience here. But, I see 2 things: 1. There is another set of ifdefs further down:

#define IINCHIP_CS_BIT                              BIT2
#define IINCHIP_CS_DDR                              DDRB
#define IINCHIP_CS_PORT                              PORTB

This is equivalent to SS (I did not look in the code to see how different CS and SS are here, but sometimes, in SPI they are used interchangeably).

  1. Just wire your ethernet shield's CS/SS pin to ground, thus enabling it continuously (not long term, just for debugging). See if you can talk with the shield.

I now tried this out, without effect either :-/

You left out the reset line.

You may want to tie it to a digital pin, instead of the Sanguino's RST: see my posting here.

Ran

I left it out just because it's a self-made Sanguino and I have to put a proper RESET header. But I did reset the Sanguino and the shield with the reset buttons synchronously. So that should not be the issue... (It worked also like this with the Arduino instead of Sanguino)

Any luck in getting this to work? I'm running into the same issue.

I think I got it working. I changed the IINCHIP_CS_BIT from BIT2 to BIT4 to match the SS.

Did it really work? I already did this without success. Could you please post the whole file?

Yep, it is working exactly like the Arduino now. Here’s a link to the entire lib: http://www.justinz.net/downloads/Ethernet.zip.

I set pins 13,12,11,10 from the shield to 8,7,6,5 on the 644.

I could just test it out now, and no success. I think I should test the hardware out again ;)