This is the definitive guide to have this three components connected and working together.
Arduino Duemilanove
Ethernet Shield
TLC5940
There is 3 steps to have this configuration working :
Modification of the wiring between the Duemilanove and the Ethernet shield.
Modification of the Ethernet shield library (spi.h)
Modification of the TLC5940 library (tlc_config.h)
Wiring :
TLC5940 to Duemilanove
BLANK -> PB2 (D10)
XLAT -> PB1 (D9)
SIN -> PD7 (D7)
XERR -> PD6 (D6)
SCLK -> PD4 (D4)
GSCLK -> PD3 (D3)
Ethernet shield to Duemilanove
D10 -> D8
This is easy to do , bend the pin D10 of the Ethernet shield so it doesn't connect to the duemilanove.
Connect the D10 of the ethernet shield to the D8 Ethernet shield so you can still plug and unplug the Ethernet shield
Change in SPI.h :
old
PORTB |= SPI0_SS_BIT | BIT0 ; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\
#define IINCHIP_CS_BIT BIT0
new
PORTB |= SPI0_SS_BIT | BIT2 ; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\
#define IINCHIP_CS_BIT BIT0
Change in tlc_config.h
old
#define DATA_TRANSFER_MODE TLC_SPI
new
#define DATA_TRANSFER_MODE TLC_BITBANG
With these modification, you can use the 3 components together with their respective library.
I made a pcb with this configuration for a project and it is working fine, I can change the parameter of the TLC via a web browser
If somebody can tell me how to upload photo it will be nice.
It was missing the XERR , if you want to use it
in tlc_config.h :
old :
#define XERR_ENABLED 0
#if XERR_ENABLED
/** XERR (TLC pin 16) */
#define XERR_PIN DEFAULT_XERR_PIN
#define XERR_PORT DEFAULT_XERR_PORT
#define XERR_DDR DEFAULT_XERR_DDR
#define XERR_PINS DEFAULT_XERR_PINS
#endif
new :
#define XERR_ENABLED 1
#if XERR_ENABLED
/** XERR (TLC pin 7) */
#define XERR_PIN PD6
#define XERR_PORT PORTD
#define XERR_DDR DDRD
#define XERR_PINS PIND
#endif
system
December 14, 2009, 12:10am
3
Thank you for your help on this issue, I am looking to do the same thing. Where is the SPI.h file located? I'm on a mac system and cant for the life of me located this file for editing. Thanks!
Hello,
On windows it is there : \arduino\hardware\libraries\Ethernet\utility
system
January 2, 2010, 10:52am
5
I have done all the steps required, but it is not working for me. I get an error when I try to compile the code.
I could not find the exact strings you told to replace, I started out with this in my spi.h:
- #define SPI0_SS_BIT BIT2
PORTB |= SPI0_SS_BIT; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\
#define IINCHIP_CS_BIT BIT2
Could that be the problem?
I think I made a small mistake in my copy / paste before .
This is the original code :
//-----------------------------------------------------------------------------
//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)
//-----------------------------------------------------------------------------
This is the new code
//-----------------------------------------------------------------------------
//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 BIT0
#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 | BIT2 ; 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 BIT0
#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)
//-----------------------------------------------------------------------------
Just replace your spi.h with the new code
Sorry for the bad code from the previous post.
system
January 3, 2010, 5:43pm
7
Thanks! It's working for me now.
I needed it for a university project, I designed everything thinking that this would be possible. This post saved my life
I was looking at my project and tried to use the version 21 of Arduino to compile it.
I have it compiling but without these modifications for the ethernet and tlc5940 library
As the SPI files has changed, I cannot find where to make my previous modification.
If somebody as an idea, let me know meanwhile I will continue to look how to do it.
system
October 11, 2010, 2:21pm
9
Hi toffe82
just realized that I've started a second topic although you already asked the same question here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1286641287
Actually, I though that you're going to be the one that solves the problem I've been using your modifications for spi.h in Arduino 0018 without any problems. I hope that someone has a hint?
mjb
I find the solution but I can't test everything because I have too much change on my project with the new arduino0021
I have the Ethernet working.
If somebody can check the whole thing it would be nice.
First : the TLC5940 stay the same as in version with arduino0017.
second : 2 changes , one in w5100.H and the other one in pins_arduino.h
w5100.H, in the folder \arduino-0021\libraries\Ethernet\utility
old code :
private:
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
inline static void initSS() { DDRB |= _BV(4); };
inline static void setSS() { PORTB &= ~_BV(4); };
inline static void resetSS() { PORTB |= _BV(4); };
#else
inline static void initSS() { DDRB |= _BV(2); };
inline static void setSS() { PORTB &= ~_BV(2); };
inline static void resetSS() { PORTB |= _BV(2); };
#endif
new code :
private:
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
inline static void initSS() { DDRB |= _BV(4); };
inline static void setSS() { PORTB &= ~_BV(4); };
inline static void resetSS() { PORTB |= _BV(4); };
#else
inline static void initSS() { DDRB |= _BV(0); };
inline static void setSS() { PORTB &= ~_BV(0); };
inline static void resetSS() { PORTB |= _BV(0); };
#endif
pins_arduino.h in the folder \arduino-0021\hardware\arduino\cores\arduino
old code
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const static uint8_t SS = 53;
const static uint8_t MOSI = 51;
const static uint8_t MISO = 50;
const static uint8_t SCK = 52;
#else
const static uint8_t SS = 10;
const static uint8_t MOSI = 11;
const static uint8_t MISO = 12;
const static uint8_t SCK = 13;
#endif
new code
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const static uint8_t SS = 53;
const static uint8_t MOSI = 51;
const static uint8_t MISO = 50;
const static uint8_t SCK = 52;
#else
const static uint8_t SS = 8;
const static uint8_t MOSI = 11;
const static uint8_t MISO = 12;
const static uint8_t SCK = 13;
#endif
There must be a better way but I don't see.
the problem there is that we touch 2 standard library so if you want to reuse them in another project, you have to put
them back to the original.
system
January 6, 2011, 7:14pm
11
Sorry for the delay...
I just made the changes as you described, using Arduino 022. Works like a charm! Thanks toffe82.
At the moment I'm fine with changing standard libraries for my project - but I agree, it would be nice to have a non-invasive solution to this in the future!
mjb