View previous topic :: View next topic |
Author |
Message |
YUM
Joined: 27 May 2004 Posts: 12 Location: Austria
|
SPI Master - Writing other than 8 Bit data? |
Posted: Wed Oct 01, 2008 1:27 am |
|
|
Good Morning
Simple question:
Is there a way to use the CCS compiler (3.227, PIC16F73 as master SPI) function spi_write to send out a number of bits other than 8 or do i have to write an own code?
thank you for reading and answering |
|
![](templates/subSilver/images/spacer.gif) |
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Wed Oct 01, 2008 2:31 am |
|
|
YUM;
How many bits of data do you want to send? I ask this because there are Nokia LCDs which require 9 bit SPI data. See this post for details http://www.ccsinfo.com/forum/viewtopic.php?t=28192&highlight=9bit
If you need to send out a different number of bits software SPI may be a better option. CCS has built-in routines for this.
Rohit |
|
![](templates/subSilver/images/spacer.gif) |
YUM
Joined: 27 May 2004 Posts: 12 Location: Austria
|
|
Posted: Wed Oct 01, 2008 2:40 am |
|
|
Hello,
i have to send any number less than 8 bit (precoding for eeproms (93C46, 93C56 etc....).
what exactly do you mean by ccs-software-builtin-routines? ... i know about the driver-files "9356.C" etc ... but that's where my question comes from.
is there something like
SPI_WRITE_BITS(DATA , NUMBER OF BITS) |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Oct 01, 2008 3:31 am |
|
|
If you intend to use hardware SPI, there's no way to get other bit counts than multiples of 8. That's no problem with any SPI device, cause they are required to work with multiples of 8 by specification.
93C46 and similar aren't SPI devices (although they may be operated by SPI hardware in some cases).
CCS software SPI function are designed to be compatible to hardware SPI and thus also don't support different bit counts. But using your own software (bit bang) serial protocol as in the 93C46.C driver achieves a speed similar to software SPI. Why you don't use it? |
|
![](templates/subSilver/images/spacer.gif) |
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Wed Oct 01, 2008 4:15 am |
|
|
FvM,
I didn't know about the necessity of software SPI to have the number of bits as multiples of 8. Thanks!
Rohit |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Oct 01, 2008 7:13 am |
|
|
It is worth clarifying a few things here:
First, you can use the hardware SPI, with chips like the 93C46. The 'key', is in the data sheet, where it says that the CLK, and DI pins, become 'don't care' pins after the required opcode, address and data bits are received. It is perfectly OK to send extra clocks. Most chips requiring odd clock counts allow this. The supplied routines, don't take advantage of this.
Second, the inbuilt CCS software SPI routines, _do_ support bit counts other than 8 bit multiples. These are generated, if you use the #USE_SPI setup, and the SPI_XFER command syntax, rather than the old SPI setups, and select pins that are not the hardware pins, _or_ select the hardware pins, and a bit count, that is not an 8bit multiple.
Third, though this is available, reliability seems poor. The software routines used in the 93C46 code, are easy to modify to other bit counts, and work quite well...
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Thu Oct 02, 2008 1:49 am |
|
|
Ttelmah,
You're absolutely right. Software SPI (spi_xfer) does indeed allow you to generate different bit counts. I just tried it out myself. Wrote some simple code (which tested for bit count = 5, bit count = 8, and bit count = 13 in the same code, naturally with multiple #use spi statements) and threw a PICKit2 Logic Analyzer on the pins. The signals changed correctly. As for the reliability issue, can't really comment on that.
Anyway, I guess the lesson learned here is that there is no substitute for trying things out yourself. :-)
Rohit |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Oct 02, 2008 2:34 am |
|
|
Yes. On the 'reliability', the problems seem to come if you implement multiple SPI streams. This gave distinctly 'non working' code, a couple of compiler versions ago. Haven't tried it on the latest releases, so hopefully it may be fixed now....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|