Pages: [1] 2   Go Down
Author Topic: Running 2 serial devices from an Arduino? CAN chip and TLC5940  (Read 1216 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Has anyone run 2 Serial devices from an UNO?

I have the MCP CAN chip running on the SPI bus, and i need to add the TLC5940 LED driver chip which also runs on SPI

Now i know i can move the TLC to run in BIT BANG mode, but i still need to move the BLANK pin that the TLC uses as the CAN chip requires this too,

I am not competent enough to modify libraries so i was wondering if anyone can help me do this?

Many thanks

Rich
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4682
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

An SPI bus is capable of serving multiple devices, only one wire has to be private for every device: the SS line. So use a separate SS pin for every device and you won't get any problem, just keep the SS HIGH while the device is not in use.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah i see,

The issue i have, is that D10 on the UNO board is being used as a CS pin from the SPI library on the CAN chip, whereas d10 is being used as a BLANK signal on the TLC chip, would this not interfere with eachother?

The TLC doesnt seem to require an SS signal?? or am i being silly?

Thanks for the advice

Rich
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4682
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The TLC5940 is not an SPI device (to my knowledge). The change to other pins should be relatively easy. Can you provide a link to the library you wanna use?

For the TLC5940 you have to provide the PWM clock signal (GSCLK). This has to be on a PWM pin. Which pins (other than the SPI bus pins) do you still have available?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is the link to the library,

http://code.google.com/p/tlc5940arduino/

The MCP CAN chip uses

D2
D10
D11
D12

for the SPI interface

We have changed the operation of the TLC to BIT_BANG as mentioned in the TLC_config file so as it wont slow down the SPI bus for the CAN Chip,

So What i want to do is move the BLANK pin function to D5 which is PWM capable,

I am a relatively novice code writer and i ended up lost and confused when it got to library level changes,

I really appreciate this help

Rich
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh and the MCP CAN chip also uses D13 smiley sorry

Rich
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4682
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I took a look at the library code of the TLC5940, changing the BLANK, GSCLK and XLAT pins seems very hard because of the very special PWM setup they need. This probably means it's easier to change the SS of the MCP chip. Which library do you use for that chip?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is the issue that I found,
I very much appreciate your efforts on this , as a breakthrough would mean very much.

The MCP library is the one from the Seeduino wiki site.
I will post a link tomorrow morning,

It looks like it uses the standard SPIN library supplied with the Arduino IDE,
Which is why I thought it would be easier to chance the TLC library,

I really appreciate your help so far,

Rich
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HI, thanks for all of your help,

The link to the CAN library is below, but i dont think the link works very well,

http://www.seeedstudio.com/wiki/CAN-BUS_Shield


I can post the library code into here if that helps,

Do you have an email address i can send the .txt file to you to help speed things up?

I hope we are able to conquor this smiley

Rich
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4682
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you using this shield or just the library?

The shield has a solder bridge to select between pin 10 and pin 9 for SS. Unfortunately both pins are used by the TLC5940 and because they are PWM pins but pin 9 isn't directly set by the hardware but controlled by the timer1 interrupt. This mean you can either select pin 9 using the solder bridge or solder that point with a wire to any other free digital pin. The first way means you have to change the MCP library as described later AND modify the TLC5940 library to use another pin in the interrupt handler. The second solution doesn't have an implication on the TLC5940 library, but you have to solder a wire to the solder bridge.

The change to the MCP library is easy, in mcp_can_dfs.h change to following line:

Code:
#define SPICS 10

Just replace the 10 with the pin number you connected the SS to.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Right,

I am not using that shield, i am using the Sparkfun /SKpang shield with the library i sent the link too,

So all i have to do is solder a wire from the CS pin on the CAN shield to say D5 instead, and change

#define SPICS 10
to
#define SPICS 5

The TLC library can remain the same?

Thanks

Rich
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4682
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The TLC library can remain the same?

Yes, as long as you don't use the SPI there but the bit bang interface with other pins (not 11, 12 and 13, so you have to change at least the default setting for XERR when you changed to bit bang mode).
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well what i have done as a test, is to use just the MCP wired to the Arduino, using its standard pins on the SPI except the CS pin which as you instructed, i changed that line in the code to pin 5, then i have wired the CS pin from the MCP to D5 on the Arduino and ran some code that i know works,

It doesnt seem to function with this change made,

Maybe i need to change that pin elsewhere in the Code?

sorry for all of the questions

Thansk so much for the assistance

Rich
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4682
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Maybe i need to change that pin elsewhere in the Code?

No, I checked the code and I cannot find any other location where the SS is set otherwise.

You took exactly the same code which ran with CS at pin 10? Are you absolutely sure that the compiler used the version you changed? My test in such cases is to insert a syntax error in the changed file, compile again and remove that error again if the compiler reported the error. If the compiler does not complain about the error, it uses another version of the library somewhere else.

The pin is changed in the code with digitalWrite() so incompatibilities shouldn't occur.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes i changed the code and the compliler brings up an error so it is deffinitely using that header file,

Im wondering if it is something to to with the fact that the hearer files include the SPI library,

And in the SPI library it defines the SS pin back through the Base Arduino Pin setup library as pin 10

Whcih makes me thing that it uses part of the SPI and Arduino.H library to carry out all of the CS functions?

I am soo confused lol

Rich
Logged

Pages: [1] 2   Go Up
Jump to: