Hey William, thanks for this SPI lib. I have tested your spi lib with
an SD card and it works great.

I would like to edit it and get it ready for the jallib releases. SPI
is required for the SD_Card lib I am working on.

I feel it is important to get a SPI lib finnished. There are also many
other uses for SPI. Would you like to assist with this, or should I
just modify your lib?


Just a few things.....

1.

I think the user should define the following values within there own
file:
SSPSTAT_SMP, SSPSTAT_CKE, SSPCON_CKP


eg:

include spi_master_hw   -- spi library

pin_sdo_direction = output
pin_sck_direction = output
pin_sdi_direction = input

-- These could be aliased to make more sense
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
SSPCON_CKP = 1   -- idle state for clock is high level


2.

You have an init procedure:

-- SPI Master mode 0,0 example.
-- Note: check your datasheet -- TRIS settings, any SPI errata?
procedure _spi_init_mode00() is
   var byte v
   SSPCON = 0
   v = SSPSTAT & 0x3F
   SSPSTAT = v
   v = v | 0x40 -- CKE = 1
   SSPSTAT = v
   v = SSPCON
   v = v | 2 -- CKP=0, Master mode, OSC/64
   SSPCON = v
   SSPCON_SSPEN = 1
end procedure

Is there a need for all of this?
your init procedure could just be this:

procedure spi_hw_init_master() is
  SSPCON_SSPM = 1  -- spi master mode, clock = Fosc/16
  SSPCON_SSPEN = 1 -- enables serial port and configures sck, sdo, sdi
and ss as source of the serial port pins
  -- Am I missing anything??
end procedure

What is mode 0,0 ? What other modes are there?


also, CKP does not make sense to me,

You show CKP=0 -- Master mode, OSC/64

Datasheet shows:

CKP: Clock Polarity Select bit
In SPI mode:
1 = Idle state for clock is a high level
0 = Idle state for clock is a low level



Thanks,
Matt.


On Aug 24, 10:09 am, William <[email protected]> wrote:
> For your consideration:
>
> -- Title: SPI Master  (spi_master_hw.jal)
> -- Author: William Welch Copyright (c) 2009, all rights reserved.
> -- Compiler: uncertain. FIXME
> --
> -- This file is part of jallib (http://jallib.googlecode.com)
> -- Released under the ZLIB license (http://www.opensource.org/licenses/
> zlib-license.html)
> --
> -- Description: SPI Master hardware control.
> -- Routines for sending and receiving through the SPI in master mode
> --
> -- TODO: only tested in Master mode 00
> --
>
> -- SPI is full-duplex, so we exchange master and slave data byte
> function spi_master_hw_exchange (byte in m_data) return byte is
>    var byte stat
>    SSPBUF = m_data
>
>    stat = SSPCON & 0x80
>    if ( stat != 0 ) then
>       -- FIXME how to report error???
>       return 0xFF
>    end if
>
>    while ( SSPSTAT_BF == 0 ) loop end loop
>
>    -- return slave data
>    return SSPBUF
> end function
>
> -- half-duplex convenience function. send data to slave, discard reply
> procedure spi_master_hw'put(byte in data) is
>    var byte dummy
>    dummy = spi_master_hw_exchange(data)
> end procedure
>
> -- half-duplex convenience function. send 0xFF, get slave data
> function spi_master_hw'get() return byte is
>    var byte data
>    data = spi_master_hw_exchange(0xFF)
>    return data
> end function
>
> -- SPI Master mode 0,0 example.
> -- Note: check your datasheet -- TRIS settings, any SPI errata?
> procedure _spi_init_mode00() is
>    var byte v
>    SSPCON = 0
>    v = SSPSTAT & 0x3F
>    SSPSTAT = v
>    v = v | 0x40 -- CKE = 1
>    SSPSTAT = v
>    v = SSPCON
>    v = v | 2 -- CKP=0, Master mode, OSC/64
>    SSPCON = v
>    SSPCON_SSPEN = 1
> end procedure
>
> Thank you,
>
> William
--~--~---------~--~----~------------~-------~--~----~
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