Using TLC5940 Library with ethernet shield on Arduino

I’ve decided, for costs reason, to use an arduino nano instead of a mega for my final version of the project I’m working on. The arduino nano is based on ATMega328 chip which does not provide enough PWM output for the 3 RGB led I need. That’s why i decided to use a TLC5940, which provides 16PWM output for a cost of 3 PWM and 2 digital outputs on the Arduino board. Unfortunately, the library uses the SPI interface. TLC5940’s implementation of the SPI bus does not allow more devices on the bus than him and the master, and my project involves an internet chip, which uses the SPI interface too. I did’nt found on google any clear explainations on the subject, so i decided to go deeper.

The library provides a mode to avoid the use of the SPI : it is the bitbang mode. You have to edit the tlc_config.h in your tlc library folder and change the DATA_TRANSFER_MODE line :

#define DATA_TRANSFER_MODE    TLC_BITBANG

You then have to tell which pin to use : that’s the harder part. The library uses the pin at a very low lever : you have to specify pin, port and ddr of the pin you are aiming. I spent time on google to find which pin/port/ddr coresponds to which pin. I started reading the ATMega1280 datasheet, but in fact, it was obviously on the arduino mega schematic. For example, to use pin 48 and 49, change the tlc_config.h file to this :

/** SIN (TLC pin 26) */
#define SIN_PIN        PL0
#define SIN_PORT       PORTL
#define SIN_DDR        DDRL
/** SCLK (TLC pin 25) */
#define SCLK_PIN       PL1
#define SCLK_PORT      PORTL
#define SCLK_DDR       DDRL

The ddr, port and pin are defined in the schematic : but here is a list to avoid the pain of reading the schematic. It’s for the arduino mega, you’ll have to get the value for others Arduinos on thair respective schematics.

  • 53 : PB0 (which corresponds to PIN = PB0, PORT = PORTL, DDR = DDRL)
  • 52 : PB1
  • 51 : PB2
  • 50 : PB3
  • 49 : PL0
  • 48 : PL1
  • 47 : PL2
  • 46 : PL3
  • 45 : PL4
  • 44 : PL5
  • 43 : PL6
  • 42 : PL7
  • 41 : PG0
  • 40 : PG1
  • 39 : PG2
  • 38 : PD7
  • 37 : PC0
  • 36 : PC1
  • 35 : PC2
  • 34 : PC3
  • 33 : PC4
  • 32 : PC5
  • 31 : PC6
  • 30 : PC7
  • 29 : PA7
  • 28 : PA6
  • 27 : PA5
  • 26 : PA4
  • 25 : PA3
  • 24 : PA2
  • 23 : PA1
  • 22 : PA0

 


Cet article a été publié dans Arduino avec les mots-clefs , , , , . Bookmarker le permalien. Laisser un commentaire ou faire un trackback : URL de trackback.

4 Commentaires

  1. Michael
    Publié le 31 juillet 2011 à 10 h 18 min | Permalien

    Hi Simon,

    thanks for this explanation. Did you just change the SIN and SCLK pins? I’m trying to avoid that the TLC5940 uses Arduino pin 10 but can’t get around it.

    Thanks
    Michael

    • Simon
      Publié le 31 juillet 2011 à 12 h 15 min | Permalien

      Hi,
      I think that the tlc_config.h file and the library more generally does allow to change only SIN and SCLK pin. If you have motivation (lots of) you could try to tweak the whole library into using another pin : according to http://www.arduino.cc/playground/Learning/TLC5940, it only need a digital pin. Maybe that the pin 10 is used for « Slave Selection » like if it was working with SPI : you may want to try putting the tlc pin to the ground instead of pin 10, but it’s just a wild guess so it should not work. Eventually, I’m afraid i don’t have an answer to your question.

    • Stephan
      Publié le 8 octobre 2012 à 21 h 21 min | Permalien

      did you found a solution for your problem? i have the same here, but with an arduino-ethernet-board and tried to move from pin10 to another pin without success.
      best regards, Stephan

  2. Dominic
    Publié le 5 septembre 2012 à 19 h 58 min | Permalien

    how is the ethernet shield connected.

    did you changed the ethernet library?

Laisser un commentaire

Votre e-mail ne sera jamais publié ni communiqué. Les champs obligatoires sont indiqués par *

*
*

Vous pouvez utiliser ces balises et attributs HTML <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>