[jallib] r2520 committed - SPI software library

22 views
Skip to first unread message

jal...@googlecode.com

unread,
Mar 15, 2011, 3:24:07 AM3/15/11
to jal...@googlegroups.com
Revision: 2520
Author: mattsc...@hotmail.com
Date: Tue Mar 15 00:23:45 2011
Log: SPI software library
http://code.google.com/p/jallib/source/detail?r=2520

Added:
/trunk/include/peripheral/spi/spi_master_sw.jal

funlw65(Vasi)

unread,
Mar 15, 2011, 3:31:58 AM3/15/11
to jallib
thank you Matt!

On Mar 15, 3:24 am, jal...@googlecode.com wrote:
> Revision: 2520
> Author: mattschin...@hotmail.com

mattschinkel

unread,
Mar 16, 2011, 4:15:10 PM3/16/11
to jallib
Hey Henkvan, I'll try to reply to your SPI comments.

> I do not think that for the sw version master/slave mode has to be
> defined as it is only a setting for the SPI hardware in the PIC's. I
> hoop that I understood your remark correct.
> My aim is a pair pair of SPI_master divers that are can be exenged in
> an application without updating calls.
> This is like the pair for I2C_master .. in JALLIB.

I still think master/slave must be defined in SPI software. SPI always
has one master and many slaves. SPI never has two masters, does it? If
I'm wrong, can you show me some documentation?

The master controls the clock and chip select line, the slave listens
to the clock and chip select line.

If you wish for your slave to do other things while waiting for the
master to send/request data, you may need to use an interrupt + queue/
buffer. A interrupt on change pin would be perfect for SPI software.

> You are right, for the hardware version the mode and speed must be
> set, Master mode can be set in the init procedure

You must also set SPI mode in SPI software. This will define the clock
polarity during idle state, which is important. TWO SPI modes are
alike with SPI software, the other two are not.

> and for Speed, I wish for an extra procedure that can be called after
> Init to change the speed setting.

I agree that you should be able to set mode and speed without using
the init procedure again. William seems to disagree?

Some devices require a lower speed for commands, and a faster speed
for data. Some devices use different modes, and you may be using more
the one device (with different modes) so you need a way to switch
between modes.

SPI software should act the same as SPI hardware as much as possible,
that way it is easy to switch between the two.

Matt.

Henk van Broekhuyzen

unread,
Mar 16, 2011, 5:49:17 PM3/16/11
to jallib
Hello Matt,
Let us talk here about SPI, and not in the RF12 discussion.
I saw your code, and you are right about the mode.
The mode is not only about speed, but also about clock polarity.
About my other remark:
It would be nice if in the labels of the procedures and functions
no “_sw” or “_hw” appears for the ones who are compatible.
I know that changing labels in the lib for the hardware driver
can cause confusion. But still ...
Perhaps this is the solution: Identical routines with old and new
names in
the same module, and old names marked with “outdated, not compatible”.
The compiler will remove unused ones.
Background:
I had SPI working with the hardware, when I the interface-hardware
became
needed for I2C (in a project with Joep Suijs).
So to use Standard I/O pins I not only had to write a
SPI_sw_master.jal
but also change all the code that used the old routines (or have “_hw”
in the
calls in SPI_sw...). In the hw -sw driver pair for I2C, I saw that
there was
no need.

By the way: are you interested in a driver for the 24lc256 SPI-RAM?
If so: mail he...@henkzelf.nl and you get it. I have no time to check
for JALLIB style
as I am very busy with a radio-link using a RFM70. The RF12B did not
pass for
the project with Joep.
-------------------------------------------------------------------

On 15 mrt, 08:24, jal...@googlecode.com wrote:
> Revision: 2520
> Author: mattschin...@hotmail.com

mattschinkel

unread,
Mar 16, 2011, 10:00:44 PM3/16/11
to jallib
> Hello Matt,
> Let us talk here about SPI, and not in the RF12 discussion.

Thanks, I didn't want to change the subject in the other discussion.

> I saw your code, and you are right about the mode.
> The mode is not only about speed, but also about clock polarity.

I'll add "speed" to my software SPI lib, and also an spi exchange
procedure.

I'll read yours over, maybe I don't understand what you required.

> About my other remark:
> It would be nice if in the labels of the procedures and functions
> no “_sw” or “_hw” appears for the ones who are compatible.
> I know that changing labels in the lib for the hardware driver
> can cause confusion. But still ...

"alias" can solve this problem. When including SPI in your main
program, you can just do:
alias spi_master is spi_master_sw

This way, your other files/libs can call "spi_master" instead of
"spi_master_sw" or "spi_master_hw". This makes it easy to change
between the two.

It is important to know that someone may decide to use both
spi_master_hw and spi_master_sw on the same PIC, although there seems
to be no reason to do so from our point of view.

> By the way: are you interested in a driver for the 24lc256 SPI-RAM?

I think we're interested in any new libraries :)

> If so: mail h...@henkzelf.nl and you get it. I have no time to check
> for JALLIB style
> as I am very busy with a radio-link using a RFM70. The RF12B did not
> pass for
> the project with Joep.

Knowing style guide will help you write good software in the future as
well.

Matt.

Henk van Broekhuyzen

unread,
Mar 17, 2011, 6:24:33 AM3/17/11
to jallib
OK, I will tune-up and submit the diver for the RAM-chip when SPI
drivers are stable and my current project is done.

Henk

mattschinkel

unread,
Mar 17, 2011, 7:42:10 AM3/17/11
to jallib
If you wish, you can add your spi_exchange_sw proc to my spi_software
lib, then add your name as a author. However, you must add support for
other SPI modes. If you don't have time, I will create a new proc.

Here is a sample of how I would include SPI hardware within my main
program. See the alias line:

include spi_master_hw -- includes the spi library
-- define spi inputs/outputs
pin_sdi_direction = input -- spi input
pin_sdo_direction = output -- spi output
pin_sck_direction = output -- spi clock
--
spi_init(SPI_MODE_11,SPI_RATE_FOSC_4) -- init spi, choose mode and
speed
alias spi_master is spi_master_hw

And for SPI software, again, see the alias line:

alias spi_master_sw_sdi is pin_sdi
alias spi_master_sw_sdi_direction is pin_sdi_direction
alias spi_master_sw_sdo is pin_sdo
alias spi_master_sw_sdo_direction is pin_sdo_direction
alias spi_master_sw_sck is pin_sck
alias spi_master_sw_sck_direction is pin_sck_direction
-- define spi inputs/outputs
spi_master_sw_sdi_direction = input -- spi input
spi_master_sw_sdo_direction = output -- spi output
spi_master_sw_sck_direction = output -- spi clock
--
include spi_master_sw
spi_init(SPI_MODE_11) -- init spi, choose mode
alias spi_master is spi_master_sw


On Mar 17, 6:24 am, Henk van Broekhuyzen

Henk van Broekhuyzen

unread,
Mar 17, 2011, 1:41:11 PM3/17/11
to jallib
Hi Matt,
Thank for your sample.
I feel no need to have my name added as Autor.
If you are convinced that it works (as I am) , just add it .
Henk
> > > Matt.- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

hubidrei

unread,
Apr 16, 2011, 10:25:54 AM4/16/11
to jallib
Hi,

I am very interested in your work on the RFM70, since I am currently
trying to get them work for my home automation, but I am far away from
a solution. For the master i use a18f2550 on a dwarf board, with Sprut
USB Bootloader. Slaves are 18f23k20. For now I try to translate the
RFM70.h and RFM70init.c files from the HopeRF RFM70 product site, but
this program uses pointers to arrays, so I have a lot todo until I
have a working lib.
> > as I am very busy with a radio-link using aRFM70. The RF12B did not

Henk van Broekhuyzen

unread,
Apr 17, 2011, 7:42:00 PM4/17/11
to jallib
Hi, Hub,
I have code for a 16f876 that should work but it does not jet.
If you mail me on he...@henkzelf.nl , I will replay you that code.
I am as far as this:
Initialisation is done, and I can read the registers back.
I see used current change for the different modes, and see it change
when I change the rate of sending packages, so I assume there is
something transmitted.
But the receiver does not report the arrival of anything.
(and than my old scoop broke down and it cost me 10 days to repair).
I am very pleased if you will look over my code and indicate where I
might be incorrect.
I know that the code should be tuned up to be JALLIB compiant, but...
The structure of the program is like that as for the RF12B what is
ducumented at my site
www.henkzelf.nl (last link on intro-page).

By the way, I am 2 day's out, so do not expect an answer before
wednesday.
Reply all
Reply to author
Forward
0 new messages