Author |
Message |
makiyoung
Joined: Jun 19, 2017 Posts: 1 Location: USA
|
Posted: Mon Jun 19, 2017 2:25 am Post subject:
Arduino TLC5940 and 74HC595 Subject description: Arduino TLC5940 and 74HC595 |
 |
|
I need to expand Arduino Uno output. After some search I have identified 74HC595 to extend my Digital output and TLC5940 for analog output.
This two setups share some pins, I've seen in this thread that other people use them together but I'm not sure how to connect them to my Arduino. Can you give me a hint?
Libraries are also compatible?
Then how to test 74hc595? |
|
Back to top
|
|
 |
Grumble

Joined: Nov 23, 2015 Posts: 1310 Location: Netherlands
Audio files: 30
|
Posted: Mon Jun 19, 2017 2:52 am Post subject:
|
 |
|
TLC5940 is a 16-Channel LED Driver, so I'm not sure how you would use this to expand the analog out of the Arduino Uno (which doesn't have an analog out by the way...)
First I have to mention that I'm not using the Arduino IDE but I program my Arduino's using C++ and the program I use is Atmel Studio 7 and I don't know about lib's.
Ok, have said that: The mentioned ic's both use SPI, that is, they use MOSI, MISO, CLK and a chip select line.
The Chip Select line (active low) may be any digital output line you choose.
The use is like this:
make the CS of the chip you wish to use low,
transfer the data to the chip using SPI,
make the CS of the chip you wish to use high again.
Thats it.
in more detail:
#define cs_74HC595_low PORTB &= ~(1<<PB2); //CS ¯|_
#define cs_74HC595_high PORTB |= (1<<PB2); //CS _|¯
// set I/O pins in INIT
DDRB |=(1<<DDB2)|(1<<DDB3)|(1<<DDB5);//outputs
// PB5 (SCK) = Out
// PB3 (MOSI) = Out
// PB2 (SS) = Out
// SPI-Init
SPCR = (1<<SPE) // SPI enable
|(1<<MSTR) //master mode
|(1<<CPOL) //setup rising
|(0<<CPHA) //sample falling
|(1<<SPR0); //fosc/16
cs_74HC595_high
void data_to_74HC595 (uint8_t to_parallel_data)
{
cs_74HC595_low;
SPDR =to_parallel_data;
while ( !(SPSR & (1<<SPIF))) {}; // ready?
cs_74HC595_high;
}
now every time you need to write data to the 595 you do: data_to_74HC595 (your data); |
|
Back to top
|
|
 |
Grumble

Joined: Nov 23, 2015 Posts: 1310 Location: Netherlands
Audio files: 30
|
Posted: Mon Jun 19, 2017 3:03 am Post subject:
|
 |
|
testing can be done:
while (true)
{
for (uint8_t n=0;n<255;n++)
{
data_to_74HC595 (n);
_delay_ms(1);
}
}
connect the outputs one by one to an amplifier and you will hear 1khz, 500hz, 250hz, 125hz, etc. listening at ouput D0-D7 from the 595 (carefull! the outputs go to +5 volt!) |
|
Back to top
|
|
 |
|