I found this info about SPI, read page 24 & 25. selecting the "mode"
is quite simple:

http://ww1.microchip.com/downloads/en/devicedoc/spi.pdf

SPI Mode CKP CKE
0,0 - 0 1
0,1 - 0 0
1,0 - 1 1
1,1 - 1 0

for my SD_CARD lib, I am using spi mode 0,0
SSPSTAT_SMP = 0  -- sample bit, input data sampled at middle of data
output time
SSPSTAT_CKE = 0  -- clock edge select, data transmitted on falling
edge of sck

so, we can just have the user select the CKP & CKE settings themself
and within the example files I will create, all modes should work with
no problem.

There is also another "mode" noted in the 16f877 datasheet:

"SSPM3:SSPM0: Synchronous Serial Port Mode Select bits". This is just
the speed...
0000 = SPI Master mode, clock = FOSC/4
0001 = SPI Master mode, clock = FOSC/16
0010 = SPI Master mode, clock = FOSC/64
0011 = SPI Master mode, clock = TMR2 output/2

the user can select these settings themself as well.

Matt.

On Aug 31, 3:07 pm, William <[email protected]> wrote:
> Matt,
>
> I'm new to JALLIB, but from what I have understood, we should just use
> the 'samples' directory for testing.  Perhaps others will chime in
> with additional suggestions.
>
> SPI is a protocol, not limited to, nor defined by Microchip.  For
> example:http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
>
> andhttp://elm-chan.org/docs/spi_e.html
>
> So, when I make a reference to SPI Master mode 0,0, it has to do with
> the polarity of the clock signal and the phase of the clock signal,
> with respect to the data.  The different chip vendors, such as
> Motorola/Freescale and Microchip, have different naming conventions
> which adds to my confusion.  But basically there are 4 possible
> combinations and there seems to be consistency that the left-most
> number is the polarity and the right-most is the phase.
>
> Since the library itself is so small, perhaps you can just paste your
> proposed changes here and then I can merge them into SVN, would that
> be OK for now?
>
> If the main thing that is bugging you is the _init routine, I can just
> remove it completely for now, and put that code into my samples for
> CAN.
>
> Thank you,
>
> William
>
> On Aug 31, 3:16 pm, mattschinkel <[email protected]> wrote:
>
>
>
> > May I open a new project in the project dir on SVN for this? Where can
> > we store our files so we can both edit them?
> > I would like to edit your lib, make an example file and show you the
> > result so you can edit or give your feedback.
>
> > > I look forward to working with you to make this library better.
>
> > great!
>
> > > And I may be off in the weeds, but the file I checked in, was intended
> > > to be for picmicros that have a built-in SPI controller, and further,
> > > for use in Master mode. So, the register definitions are defined by
> > > the chip, for example 16f819.jal.
>
> > Yes, this should be for only pics with built-in SPI, and only for
> > master mode, later on we can make a seperate spi_master_sw lib
>
> > > Now, if you are considering other flavors of picmicro, which have
> > > built-in SPI hardware, but have different register definitions, then
> > > we need to deal with that somehow.  I'd rather have separate SPI
> > > Master library files, than a single file that is complicated and hard
> > > to understand and maintain.
>
> > I have tested it on 16F877, but I would also like it to work on 18F452
> > as well as others in the future. What chips did you test on?
> > I think we could have only one lib file with many example files for
> > each chip, like there are with other libs/examples. I have an idea for
> > this using ALIAS
>
> > > My thought was that SPI is (potentially) complicated, and that end-
> > > users would need to provide their own 'init' routine. I didn't have
> > > the time or resources to fully test all of the various ways that SPI
> > > can be used in Master mode, so I wrote a 'quick and dirty' 'init'
> > > routine (note the leading underscore in the name).
>
> > The user can define those registers without an init routine, since the
> > user MUST define them, they should go in the example file. I think we
> > can test different master modes and note which ones have been tested
> > within the lib or example file, what do you think? Also, each chip may
> > have different types of "master modes".
>
> > Matt.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to