Running 2 serial devices from an Arduino? CAN chip and TLC5940

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

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.

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

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?

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

Oh and the MCP CAN chip also uses D13 :slight_smile: sorry

Rich

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?

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

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 :slight_smile:

Rich

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:

#define SPICS 10

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

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

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).

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

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.

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

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

Where in SPI.h or any other header included from there is SPICS defined? I cannot find it.

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

No, it doesn't.

Did you set the pin as an output in setup()?

pinMode(5, OUTPUT);
digitalWrite(5, HIGH); // disable first

Edit: changed to code tags to remove smiley display and added initial HIGH.

PERFECT!!

Thanks so much for the help, just what i needed

Rich

Well, it seems that it works on BIT_BANG, but it doesnt upate the LED's, fast enough

How can i run Both the MCP and TLC chips from the SPI bus, the CS and B;ank pins are now separate,

Do i need to add some clock timing between the devices?

Cheers
Rich

I don't know the TLC chip very detailed but from the timing diagram in the datasheet I'd suppose that the chip doesn't have an SS/CS (Slave Select/Chip Select) input pin.

If you must have faster TLC output, give the chip a separate ATmega which you may connect by I2C to the master.

Well, it seems that it works on BIT_BANG, but it doesnt upate the LED's, fast enough

What speed do you need then? How fast is it now with BIT_BANG?