SPI Sending Stings

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

SPI Sending Stings

Post by Jay Dee »

Hi,
I wish to communicate with an SPI device but it requires me to clock the data into the register as a string with a length of 192 bits. (16 x 12 bit values).
The standard SPI component (for the DAC eblock) only allows the sending of characters, 8 bit integer.
I should say at this point I've not bought the chip yet so do not know for sure if the device would accept the whole 192 bit string chopped up into 8 bit blocks. Even if it did it would be a clunky process, which I would like to avoid. ;-)
So heres the question,
Can the SPI_send_char macro be changed to allow the sending of Strings approaching 200 bits? I am a total C novice (or less) and I'm sure there are more parameter that effect this that are obvious to me, but does this just need the variable declaration be changed from a char to a string? and then the system will simple clock out the whole string until the spi buffer is empty or is the spi buffer size restricted ?

MACRO as follows

//GetSPI_Send_CharCode
#ifdef MX_MIAC_SYSTEM
#if (%a != MX_MIAC_MM_MIAC_BASE)

unsigned int ModID = ((%b << 5) + %a) << 9;

MIAC_CAN_TX[0] = Char;
MIAC_Module_WR(ModID, 354, 1,1,0);
MIAC_Module_GetAck(ModID + 32, 354, 20);
#endif
#else
#ifndef MX_SPI
#error "Chip does not have SPI capability"
#endif

//send the Char
sspbuf = Char;

//wait until sspbuf is empty
while ((sspstat & 0x01) == 0);
#endif

Any help or pointers appreciated. Remember my C is...eeerr, limited!
Cheers all.
J.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: SPI Sending Stings

Post by Benj »

Hello,

The SPI buffer is a single byte and as such cannot be used to store a string. You can however pass a string to the buffer a byte at a time. 192 bits divided by 8 is 24 bytes so you could create a string of 24 bytes and then populate with the data as required before sending the data to the SPI peripheral.

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: SPI Sending Stings

Post by Dan81 »

Hello John

I should say at this point I've not bought the chip yet

Can you tell us which component you want to use ?

Daniel

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: SPI Sending Stings

Post by Jay Dee »

Texas TLC5941 - 16Ch LED driver.
http://www.ti.com/product/tlc5941
Have a potential project that would use a reasonable number of LED and I'd like to be able to have PWM brightness control of each one. I know this can be done many different ways but benefits to me of the TLC5941 are, minimum component count, flexible outputs with decent sink current (80mA max) and Automotive Qualified which is great. I also like that this PWM driver unit has its own internal oscillator and apart from needing big strings of bits, looks pretty easy to run. ( he said optimistically!).
Since they are only about £3 from Farnell I'll get one on order.
Oh yeah is also in a leaded Surface mount package, not BGA or QFN.

When I get back to UK I'll try to find some time next week to have a play with the route Ben Suggested.

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: SPI Sending Stings

Post by Jay Dee »

Hi,
I've written a short bit of flowcode to sequentially send the data out in blocks of 8 bits, this should clock into the device quite nicely.
However, whilst going through the datasheet in detail, checking the exact sequence of events needed, I realized that the TLC5941 chip also needs a reference clock signal (To drive the pwm output stage).
And this is another bit where my experience runs out. :-)

To provide a clock signal to another device do I.
> Get the ECIO (18F4455) to output a reference clock somehow, Given that the ECIO board uses both of the 18F4455's OSC pins.
> Create a clock signal by using the CCP output (flowcode PWM module), set to 50% and I think it will drive up to 6Mhz with the ECIO 40P
> Use an external clock to generate a ref clock.

I've had a look though the 16F4455 spec sheet and got a bit lost with that it can do and what I could then set within the flowcode environment.

anyone overcome this sort of thing?
J. :?

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: SPI Sending Stings

Post by Dan81 »

Hello J

Can you test this file, I don't have any TLC .


Daniel
Attachments
TLC5341.fcf
not tested !
(8.5 KiB) Downloaded 248 times

JAW
Posts: 30
Joined: Tue Jun 16, 2009 2:25 pm
Been thanked: 4 times
Contact:

Re: SPI Sending Stings

Post by JAW »

Hi Jay Dee,

I've found an application note:-

http://www.ti.com/lit/an/slva267a/slva267a.pdf

Hope this helps !!

Regards

JAW

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: SPI Sending Stings

Post by Jay Dee »

Thanks for replies,
@ JAW. Cool, the app note helps confirm some of what I'd trawled from the data sheet and interesting, that their example uses a clock pulse (for the GS) from the Texas micro, looking at the spec sheet for the micro, it has a function of its CCP/timer port that allows it to output the micros main clock specifically for perriferal ICs. I can't see any specific similar function in the 18F4455 but the PICs CCP should still be able to get a few MHz out at a 50% PWM, I'll try to have a test and check with the logic analyser.

@Dan. Chip has arrived, 28 pins at 0.65mm pitch (tiny!), as such I'm waiting for a breakout board that i can hot air the part too. http://shop.dataip.co.uk/products.html?prodid=79
So Im a couple of days away before I can actually test in hardware but will run your file as soon as i can. It was good to read through your flowcode, sections of it are similar to what i have done so far, which was good. :-) I see you have 'manually' created a 4096 length clock pulse train by toggling an output. I'll have further play once I have some hardware working on the bench.

Cheers, J.

Post Reply