initial version
This commit is contained in:
parent
62a932ecdd
commit
c30bc213c6
5
Changelog.txt
Normal file
5
Changelog.txt
Normal file
@ -0,0 +1,5 @@
|
||||
$Id: Changelog.txt,v 1.1 2008/07/16 05:44:45 rschaten Exp $
|
||||
|
||||
* Release 080716
|
||||
|
||||
- initial release
|
340
License.txt
Normal file
340
License.txt
Normal file
@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
100
Makefile
Normal file
100
Makefile
Normal file
@ -0,0 +1,100 @@
|
||||
# $Id: Makefile,v 1.1 2008/07/16 05:44:45 rschaten Exp $
|
||||
|
||||
# microcontroller settings
|
||||
F_CPU = 1000000UL
|
||||
MCU = atmega8
|
||||
|
||||
# usb programmer:
|
||||
AVRDUDE = avrdude -p $(MCU) -c avrispv2 -P usb -B 10
|
||||
|
||||
COMPILE = avr-gcc -Wall -Os -std=c99 -I../common -I. -mmcu=$(MCU) -DF_CPU=$(F_CPU) -Wa,-ahlms=$(<:.c=.lst) #-DDEBUG_LEVEL=2
|
||||
|
||||
OBJECTS = main.o twislave.o
|
||||
|
||||
TODAY=`date "+%y%m%d"`
|
||||
DIR=`basename \`pwd\``
|
||||
PACKETNAME=$(DIR)_$(TODAY)
|
||||
|
||||
all: usage
|
||||
|
||||
usage:
|
||||
@echo "Usage of this makefile:"
|
||||
@echo "make firmware create firmware"
|
||||
@echo "make program send firmware to the device"
|
||||
@echo "make fuses set fuses of the device"
|
||||
@echo "make docs create documentation"
|
||||
@echo "make tarball packs a tarball for shipping"
|
||||
@echo "make clean tidy the directory"
|
||||
@echo
|
||||
@echo "For further information, consult the documentation in Readme.txt."
|
||||
|
||||
# symbolic targets:
|
||||
firmware: main.hex
|
||||
cp main.hex main_$(TODAY).hex
|
||||
|
||||
.c.o:
|
||||
$(COMPILE) -c $< -o $@
|
||||
|
||||
.c.s:
|
||||
$(COMPILE) -S $< -o $@
|
||||
|
||||
program: firmware
|
||||
$(AVRDUDE) -U flash:w:main.hex
|
||||
|
||||
fuses:
|
||||
$(AVRDUDE) -u -U hfuse:w:0x99:m -U lfuse:w:0xc1:m
|
||||
|
||||
clean:
|
||||
rm -f main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o main.s *.lst main.hex
|
||||
rm -rf htmldoc latexdoc Readme.txt refman.pdf
|
||||
rm -f $(PACKETNAME).tar.gz
|
||||
|
||||
# file targets:
|
||||
main.bin: $(OBJECTS)
|
||||
$(COMPILE) -o main.bin $(OBJECTS)
|
||||
|
||||
main.hex: main.bin
|
||||
rm -f main.hex main.eep.hex
|
||||
avr-objcopy -j .text -j .data -O ihex main.bin main.hex
|
||||
avr-size main.hex
|
||||
|
||||
# doc generation
|
||||
docs: readme pdf
|
||||
@echo "documentation created"
|
||||
|
||||
readme: doxygen
|
||||
echo "This file is auto-generated from the content of <main.c>." > Readme.txt
|
||||
echo "You'll have more fun if you read the HTML-content in htmldoc or the PDF." >> Readme.txt
|
||||
echo >> Readme.txt
|
||||
lynx -dump htmldoc/main.html >> Readme.txt
|
||||
|
||||
pdf: doxygen
|
||||
make -C latexdoc
|
||||
mv latexdoc/refman.pdf .
|
||||
rm -rf latexdoc
|
||||
|
||||
doxygen:
|
||||
doxygen project.doxygen
|
||||
|
||||
circuitpdf:
|
||||
@echo "converting circuits to pdf"
|
||||
for i in circuit/*.ps; do ps2pdf -sPAPERSIZE=a4 $$i $$(echo $$i | sed -e "s/\.ps$$/.pdf/"); done
|
||||
|
||||
tarball: firmware circuitpdf clean docs
|
||||
@echo
|
||||
@echo
|
||||
@echo "I assume you updated the Changelog...? Press Enter to continue..."
|
||||
@read
|
||||
[ -e "main_$(TODAY).hex" ] || exit
|
||||
rm --force $(PACKETNAME).tar.gz; \
|
||||
tar --directory=.. \
|
||||
--exclude=$(DIR)/Makefile \
|
||||
--exclude=CVS \
|
||||
--exclude=*.ps \
|
||||
--exclude=main.hex \
|
||||
--create \
|
||||
--gzip \
|
||||
--verbose \
|
||||
--file ../$(PACKETNAME).tar.gz $(DIR)
|
||||
rm -f main_$(TODAY).hex
|
||||
|
20873
circuit/i2c-ledmatrix-Circuit.ps
Normal file
20873
circuit/i2c-ledmatrix-Circuit.ps
Normal file
File diff suppressed because it is too large
Load Diff
8
circuit/i2c-ledmatrix.cache.bck
Normal file
8
circuit/i2c-ledmatrix.cache.bck
Normal file
@ -0,0 +1,8 @@
|
||||
EESchema-DOCLIB Version 2.0 15/7/2008-18:58:00
|
||||
#
|
||||
$CMP R
|
||||
D Resistance
|
||||
K R DEV
|
||||
$ENDCMP
|
||||
#
|
||||
#End Doc Library
|
101
circuit/i2c-ledmatrix.cache.lib
Normal file
101
circuit/i2c-ledmatrix.cache.lib
Normal file
@ -0,0 +1,101 @@
|
||||
EESchema-LIBRARY Version 15/7/2008-18:58:00
|
||||
#
|
||||
#
|
||||
# GND
|
||||
#
|
||||
DEF ~GND #PWR 0 0 Y Y 1 F P
|
||||
F0 "#PWR" 0 0 30 H I C C
|
||||
F1 "GND" 0 -70 30 H I C C
|
||||
DRAW
|
||||
P 4 0 1 4 -50 0 0 -50 50 0 -50 0 N
|
||||
X GND 1 0 0 0 U 30 30 1 1 W N
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# LED
|
||||
#
|
||||
DEF LED D 0 40 Y N 1 F N
|
||||
F0 "D" 0 100 50 H V C C
|
||||
F1 "LED" 0 -100 50 H V C C
|
||||
DRAW
|
||||
P 3 0 1 0 -50 50 50 0 -50 -50 F
|
||||
P 3 0 1 0 65 -40 110 -80 105 -55 N
|
||||
P 3 0 1 0 80 -25 125 -65 120 -40 N
|
||||
P 2 0 1 0 50 50 50 -50 N
|
||||
X K 2 200 0 150 L 40 40 1 1 P
|
||||
X A 1 -200 0 150 R 40 40 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# MEGA8-P
|
||||
#
|
||||
DEF MEGA8-P IC 0 40 Y Y 1 L N
|
||||
F0 "IC" -700 -1500 50 H V L B
|
||||
F1 "MEGA8-P" -200 1300 50 H V L B
|
||||
F2 "atmel-DIL28-3" 0 150 50 H I C C
|
||||
DRAW
|
||||
P 2 1 0 0 -700 1200 800 1200 N
|
||||
P 2 1 0 0 800 1200 800 -1300 N
|
||||
P 2 1 0 0 800 -1300 -700 -1300 N
|
||||
P 2 1 0 0 -700 -1300 -700 1200 N
|
||||
X PB5(SCK) 19 1000 -1200 200 L 40 40 1 1 B
|
||||
X PB4(MISO) 18 1000 -1100 200 L 40 40 1 1 B
|
||||
X PB3(MOSI/OC2) 17 1000 -1000 200 L 40 40 1 1 B
|
||||
X PB2(SS/OC1B) 16 1000 -900 200 L 40 40 1 1 B
|
||||
X PB1(OC1A) 15 1000 -800 200 L 40 40 1 1 B
|
||||
X PB0(ICP) 14 1000 -700 200 L 40 40 1 1 B
|
||||
X PD7(AIN1) 13 1000 -500 200 L 40 40 1 1 B
|
||||
X PD6(AIN0) 12 1000 -400 200 L 40 40 1 1 B
|
||||
X PD5(T1) 11 1000 -300 200 L 40 40 1 1 B
|
||||
X PD4(XCK/T0) 6 1000 -200 200 L 40 40 1 1 B
|
||||
X PD3(INT1) 5 1000 -100 200 L 40 40 1 1 B
|
||||
X PD2(INT0) 4 1000 0 200 L 40 40 1 1 B
|
||||
X PD1(TXD) 3 1000 100 200 L 40 40 1 1 B
|
||||
X PD0(RXD) 2 1000 200 200 L 40 40 1 1 B
|
||||
X PC5(ADC5/SCL) 28 1000 600 200 L 40 40 1 1 B
|
||||
X PC4(ADC4/SDA) 27 1000 700 200 L 40 40 1 1 B
|
||||
X PC3(ADC3) 26 1000 800 200 L 40 40 1 1 B
|
||||
X PC2(ADC2) 25 1000 900 200 L 40 40 1 1 B
|
||||
X PC1(ADC1) 24 1000 1000 200 L 40 40 1 1 B
|
||||
X PC0(ADC0) 23 1000 1100 200 L 40 40 1 1 B
|
||||
X VCC@1 7 -900 -300 200 R 40 40 1 1 B
|
||||
X GND@1 8 -900 -100 200 R 40 40 1 1 B
|
||||
X PB7(XTAL2/TOSC2) 10 -900 200 200 R 40 40 1 1 B
|
||||
X PB6(XTAL1/TOSC1) 9 -900 400 200 R 40 40 1 1 B
|
||||
X AVCC 20 -900 700 200 R 40 40 1 1 B
|
||||
X AREF 21 -900 800 200 R 40 40 1 1 B
|
||||
X AGND 22 -900 900 200 R 40 40 1 1 B
|
||||
X PC6(/RESET) 1 -900 1100 200 R 40 40 1 1 B I
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# R
|
||||
#
|
||||
DEF R R 0 0 N Y 1 F N
|
||||
F0 "R" 80 0 50 V V C C
|
||||
F1 "R" 0 0 50 V V C C
|
||||
$FPLIST
|
||||
R?
|
||||
SM0603
|
||||
SM0805
|
||||
$ENDFPLIST
|
||||
DRAW
|
||||
S -40 150 40 -150 0 1 8 N
|
||||
X ~ 1 0 250 100 D 60 60 1 1 P
|
||||
X ~ 2 0 -250 100 U 60 60 1 1 P
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
# VCC
|
||||
#
|
||||
DEF VCC #PWR 0 0 Y Y 1 F P
|
||||
F0 "#PWR" 0 100 30 H I C C
|
||||
F1 "VCC" 0 100 30 H V C C
|
||||
DRAW
|
||||
P 3 0 1 4 0 0 0 30 0 30 N
|
||||
C 0 50 20 0 1 4 N
|
||||
X VCC 1 0 0 0 U 20 20 0 0 W N
|
||||
ENDDRAW
|
||||
ENDDEF
|
||||
#
|
||||
#EndLibrary
|
68
circuit/i2c-ledmatrix.pro
Normal file
68
circuit/i2c-ledmatrix.pro
Normal file
@ -0,0 +1,68 @@
|
||||
update=15/7/2008-17:03:19
|
||||
last_client=eeschema
|
||||
[general]
|
||||
version=1
|
||||
RootSch=i2c-ledmatrix.sch
|
||||
BoardNm=i2c-ledmatrix.brd
|
||||
[eeschema]
|
||||
version=1
|
||||
LibDir=
|
||||
NetFmt=1
|
||||
HPGLSpd=20
|
||||
HPGLDm=15
|
||||
HPGLNum=1
|
||||
offX_A4=0
|
||||
offY_A4=0
|
||||
offX_A3=0
|
||||
offY_A3=0
|
||||
offX_A2=0
|
||||
offY_A2=0
|
||||
offX_A1=0
|
||||
offY_A1=0
|
||||
offX_A0=0
|
||||
offY_A0=0
|
||||
offX_A=0
|
||||
offY_A=0
|
||||
offX_B=0
|
||||
offY_B=0
|
||||
offX_C=0
|
||||
offY_C=0
|
||||
offX_D=0
|
||||
offY_D=0
|
||||
offX_E=0
|
||||
offY_E=0
|
||||
RptD_X=0
|
||||
RptD_Y=100
|
||||
RptLab=1
|
||||
SimCmd=
|
||||
UseNetN=0
|
||||
LabSize=60
|
||||
[eeschema/libraries]
|
||||
LibName1=power
|
||||
LibName2=atmel
|
||||
LibName3=device
|
||||
LibName4=conn
|
||||
LibName5=linear
|
||||
LibName6=regul
|
||||
LibName7=74xx
|
||||
LibName8=cmos4000
|
||||
LibName9=adc-dac
|
||||
LibName10=memory
|
||||
LibName11=xilinx
|
||||
LibName12=special
|
||||
LibName13=microcontrollers
|
||||
LibName14=dsp
|
||||
LibName15=microchip
|
||||
LibName16=analog_switches
|
||||
LibName17=motorola
|
||||
LibName18=texas
|
||||
LibName19=intel
|
||||
LibName20=audio
|
||||
LibName21=interface
|
||||
LibName22=digital-audio
|
||||
LibName23=philips
|
||||
LibName24=display
|
||||
LibName25=cypress
|
||||
LibName26=siliconi
|
||||
LibName27=contrib
|
||||
LibName28=valves
|
1680
circuit/i2c-ledmatrix.sch
Normal file
1680
circuit/i2c-ledmatrix.sch
Normal file
File diff suppressed because it is too large
Load Diff
289
main.c
Normal file
289
main.c
Normal file
@ -0,0 +1,289 @@
|
||||
/**
|
||||
* \file main.c
|
||||
* \brief firmware for the i2c-ledmatrix
|
||||
*
|
||||
* this is a really simple piece of code, since the main work is done by the
|
||||
* I2C-library.
|
||||
* \author Ronald Schaten <ronald@schatenseite.de>
|
||||
* \version $Id: main.c,v 1.1 2008/07/16 05:44:45 rschaten Exp $
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation under the terms of the GNU General Public License is hereby
|
||||
* granted. No representations are made about the suitability of this software
|
||||
* for any purpose. It is provided "as is" without express or implied warranty.
|
||||
* See the GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \mainpage I2C LED Matrix
|
||||
*
|
||||
* \section sec_intro Introduction
|
||||
*
|
||||
* This project turns an AVR ATmega8 microcontroller into a LED controller for
|
||||
* a matrix of 8x8 LEDs. The controller is acting as I2C-slave, so you can
|
||||
* control the patterns to display via this bus (also known as TWI, Two Wire
|
||||
* Interface).
|
||||
*
|
||||
* \section sec_purpose Purpose
|
||||
*
|
||||
* For my next project, I need to display number values on
|
||||
* seven-segment-displays. I bought a bunch of 4-digit-displays a while ago,
|
||||
* now I'm going to put them to a use. They are built with four digits in one
|
||||
* case, and 12 pins on the underside. Eight of them are the cathodes of the
|
||||
* segments (seven segments plus dot), four are the anodes. One for each digit.
|
||||
*
|
||||
* You can imagine these modules as a matrix of four times eight LEDs, as can
|
||||
* be seen in the included circuit. I use two of these, so I have a matrix of
|
||||
* eight times eight LEDs.
|
||||
*
|
||||
* The rows and columns of this matrix are connected to the microcontroller, so
|
||||
* it can power them row by row. This has two advantages: at first a maximum of
|
||||
* eight LEDs is powered at a time, so power consumption is lowered. And at
|
||||
* second you need only 16 pins of the controller to address a total of 64
|
||||
* LEDs.
|
||||
*
|
||||
* Driving the LEDs in this way makes them flicker a bit, but the controller is
|
||||
* fast enough to keep the flickering way above the level you would be able to
|
||||
* recognize.
|
||||
*
|
||||
* I could have connected my display modules directly to the main controller of
|
||||
* my next project, but I don't have enough free pins on that. As a further
|
||||
* benefit, multiplexing the LEDs on a second controller makes the main program
|
||||
* easier to write, since I don't have to mind the timing. So the solution is
|
||||
* to use a cheap ATmega8 as LED driver and use the I2C-bus to tell it what to
|
||||
* display.
|
||||
*
|
||||
* \section sec_i2c I2C communication
|
||||
*
|
||||
* The ATmega8 has a built-in hardware I2C-interface, so it doesn't take very
|
||||
* much code to use it. Nevertheless, I used a little library that <strong>Uwe
|
||||
* Grosse-Wortmann (uwegw)</strong> published on <a
|
||||
* href="http://www.roboternetz.de/wissen/index.php/TWI_Slave_mit_avr-gcc">roboternetz.de</a>.
|
||||
* I only reformatted it a bit to make the code resemble my style. It is well
|
||||
* commented, but the comments are in german. Since only one global array, one
|
||||
* init-function and an interrupt service routine are used, it shouldn't be too
|
||||
* hard for english-speaking people to figure out how it is used.
|
||||
*
|
||||
* \subsection sec_usage Usage
|
||||
*
|
||||
* On the other end of the communication, I used the excellent <strong>Procyon
|
||||
* AVRlib written by Pascal Stang</strong>. You can find it <a
|
||||
* href="http://hubbard.engr.scu.edu/embedded/avr/avrlib">here</a>.
|
||||
*
|
||||
* A basic code example would look like this:
|
||||
*
|
||||
* \code
|
||||
* #define I2C_LEDMATRIX 0x10 // address of the device
|
||||
* timerInit(); // initialize timers
|
||||
* timerPause(100); // give everything a little time to settle
|
||||
* i2cInit(); // initialize i2c function library
|
||||
* timerPause(100); // wait a bit more
|
||||
* while (1) { // endless loop
|
||||
* uint8_t buffer[9]; // prepare buffer
|
||||
* // loop until 255
|
||||
* for (uint8_t i = 0; i <= 255; i++) {
|
||||
* // set all bytes of the buffer to value i
|
||||
* memset(buffer, i, sizeof(buffer));
|
||||
* // send the buffer via I2C-bus
|
||||
* i2cMasterSend(I2C_LEDMATRIX, sizeof(buffer), buffer);
|
||||
* timerPause(500); // wait, so you have the time to watch
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* Note: the buffer doesn't contain any numbers that should be displayed on
|
||||
* 7segment-displays. At least not in this example. It only holds bit-patterns.
|
||||
*
|
||||
* \subsection sec_numbers Displaying numbers
|
||||
*
|
||||
* If you solder 7segment displays to the unit and intend to display numbers or
|
||||
* characters on it, you need to define them on the master-side of the bus. I
|
||||
* didn't include the definitions in this library because I want the master to
|
||||
* have the full flexibility of displaying whatever it wants to, even if it are
|
||||
* no numbers.
|
||||
*
|
||||
* However, if you are going to use 7segment displays, definition of the
|
||||
* numbers still depends on how you soldered them to the controller. I don't
|
||||
* know if the pin-outs are commonly standardized.
|
||||
*
|
||||
* To give an example of how you would implement this, here is a fragment of
|
||||
* code that defines hexadecimal numbers for usage on my displays:
|
||||
*
|
||||
* \code
|
||||
* // Names of the segments:
|
||||
* // aaaaa
|
||||
* // f b
|
||||
* // f b
|
||||
* // ggggg
|
||||
* // e c
|
||||
* // e c
|
||||
* // ddddd h
|
||||
* uint8_t characters[16];
|
||||
* // c e g a h f b d
|
||||
* characters[ 0] = (1 << 0) | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) | (1 << 5) | (1 << 6) | (1 << 7); // 0
|
||||
* characters[ 1] = (1 << 0) | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) | (0 << 5) | (1 << 6) | (0 << 7); // 1
|
||||
* characters[ 2] = (0 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) | (0 << 5) | (1 << 6) | (1 << 7); // 2
|
||||
* characters[ 3] = (1 << 0) | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) | (0 << 5) | (1 << 6) | (1 << 7); // 3
|
||||
* characters[ 4] = (1 << 0) | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) | (1 << 5) | (1 << 6) | (0 << 7); // 4
|
||||
* characters[ 5] = (1 << 0) | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) | (1 << 5) | (0 << 6) | (1 << 7); // 5
|
||||
* characters[ 6] = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) | (1 << 5) | (0 << 6) | (1 << 7); // 6
|
||||
* characters[ 7] = (1 << 0) | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) | (0 << 5) | (1 << 6) | (0 << 7); // 7
|
||||
* characters[ 8] = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) | (1 << 5) | (1 << 6) | (1 << 7); // 8
|
||||
* characters[ 9] = (1 << 0) | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) | (1 << 5) | (1 << 6) | (1 << 7); // 9
|
||||
* characters[10] = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) | (1 << 5) | (1 << 6) | (0 << 7); // a
|
||||
* characters[11] = (1 << 0) | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) | (1 << 5) | (0 << 6) | (1 << 7); // b
|
||||
* characters[12] = (0 << 0) | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) | (1 << 5) | (0 << 6) | (1 << 7); // c
|
||||
* characters[13] = (1 << 0) | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) | (0 << 5) | (1 << 6) | (1 << 7); // d
|
||||
* characters[14] = (0 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) | (1 << 5) | (0 << 6) | (1 << 7); // e
|
||||
* characters[15] = (0 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) | (1 << 5) | (0 << 6) | (0 << 7); // f
|
||||
* \endcode
|
||||
*
|
||||
* \section sec_install Building and installing
|
||||
*
|
||||
* The firmware is built and installed on the controller with the included
|
||||
* makefile. You might need to need to customize it to match your individual
|
||||
* environment.
|
||||
*
|
||||
* If you take a brand-new controller you shouldn't have to hassle with the
|
||||
* fuses of the controller. The internal oscillator at 1MHz is enough to keep
|
||||
* the display flicker-free. The settings I used are included in the makefile,
|
||||
* so you can use it to reset controllers you already changed in other
|
||||
* projects.
|
||||
*
|
||||
* Oh, and if you want the slave to use an I2C-address different from 0x10: no
|
||||
* problem. Just change it in the code.
|
||||
*
|
||||
* \section sec_drawbacks Drawbacks
|
||||
*
|
||||
* Till now, the device worked in all situations I tested it in. So far
|
||||
* everything is fine.
|
||||
*
|
||||
* \section sec_files Files in the distribution
|
||||
*
|
||||
* - \e Readme.txt: Documentation, created from the htmldoc-directory.
|
||||
* - \e htmldoc/: Documentation, created from main.c.
|
||||
* - \e refman.pdf: Documentation, created from main.c.
|
||||
* - \e main.c: Source code of the firmware.
|
||||
* - \e main_*.hex: Compiled version of the firmware.
|
||||
* - \e twislave.c: I2C-library.
|
||||
* - \e twislave.h: I2C-library.
|
||||
* - \e project.doxygen: Support for creating the documentation.
|
||||
* - \e License.txt: Public license for all contents of this project.
|
||||
* - \e Changelog.txt: Logfile documenting changes in soft-, firm- and
|
||||
* hardware.
|
||||
*
|
||||
* \section sec_thanks Thanks!
|
||||
*
|
||||
* I'd like to thank the authors of the libraries I used: <strong>Uwe
|
||||
* Grosse-Wortmann (uwegw)</strong> for the I2C-slave and <strong>Pascal
|
||||
* Stang</strong> for the Procyon AVRlib.
|
||||
*
|
||||
* \section sec_license About the license
|
||||
*
|
||||
* My work is licensed under the GNU General Public License (GPL). A copy of
|
||||
* the GPL is included in License.txt.
|
||||
*
|
||||
* <b>(c) 2008 by Ronald Schaten - http://www.schatenseite.de</b>
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <util/delay.h>
|
||||
#include <avr/pgmspace.h> // keeping constants in program memory
|
||||
|
||||
#include "twislave.h"
|
||||
|
||||
/**
|
||||
* initialize hardware
|
||||
*/
|
||||
void init_ports(void){
|
||||
// set DDR for all digit-pins
|
||||
DDRB = 0xff;
|
||||
DDRC |= (1 << PINC0) | (1 << PINC1);
|
||||
// unset PORT for all digit-pins
|
||||
PORTB = 0x00;
|
||||
PORTC &= ~((1 << PINC0) | (1 << PINC1));
|
||||
|
||||
DDRD = 0x00; // segment selector
|
||||
PORTD = 0x00; // segments, has to be 0x00
|
||||
}
|
||||
|
||||
/**
|
||||
* select which digit should be displayed
|
||||
* \param digit number of the digit
|
||||
*/
|
||||
void selectDigit(uint8_t digit) {
|
||||
switch (digit) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
PORTB = (1 << digit);
|
||||
PORTC &= ~((1 << PINC0) | (1 << PINC1));
|
||||
break;
|
||||
case 6:
|
||||
PORTB = 0x00;
|
||||
PORTC &= ~((1 << PINC1));
|
||||
PORTC |= (1 << PINC0);
|
||||
break;
|
||||
case 7:
|
||||
PORTB = 0x00;
|
||||
PORTC &= ~((1 << PINC0));
|
||||
PORTC |= (1 << PINC1);
|
||||
break;
|
||||
default:
|
||||
PORTB = 0x00;
|
||||
PORTC = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set output of the currently selected digit
|
||||
* \param byte bit-pattern to show
|
||||
*/
|
||||
void showByte(uint8_t byte) {
|
||||
DDRD = byte;
|
||||
}
|
||||
|
||||
/**
|
||||
* show a pattern on a certain digit (or row, if you don't use 7segment
|
||||
* displays). the output is cleared before selecting the new digit, so there
|
||||
* won't be 'shadows' on the display.
|
||||
* \param digit number of the digit
|
||||
* \param byte bit-pattern to show
|
||||
*/
|
||||
void showDigitByte(uint8_t digit, uint8_t byte) {
|
||||
showByte(0x00);
|
||||
selectDigit(digit);
|
||||
showByte(byte);
|
||||
}
|
||||
|
||||
/**
|
||||
* main-function. initializes everything and contains the main loop which
|
||||
* controls the actual output. the rxbuffer[] is filled from the I2C-library,
|
||||
* so we just have go through the array and display its values on the
|
||||
* corresponding digit.
|
||||
* \return An integer. Whatever... :-)
|
||||
*/
|
||||
int main(void) {
|
||||
// initialize output ports
|
||||
init_ports();
|
||||
|
||||
// init watchdog
|
||||
wdt_enable(WDTO_15MS); // 15ms watchdog
|
||||
|
||||
// init I2C communication
|
||||
init_twi_slave(0x10);
|
||||
|
||||
while (1) {
|
||||
wdt_reset(); // feed the watchdog
|
||||
for (uint8_t digit = 0; digit <= 7; digit++) {
|
||||
// display all eight digits
|
||||
showDigitByte(digit, rxbuffer[digit]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
1257
project.doxygen
Normal file
1257
project.doxygen
Normal file
File diff suppressed because it is too large
Load Diff
113
twislave.c
Normal file
113
twislave.c
Normal file
@ -0,0 +1,113 @@
|
||||
/**
|
||||
* \file twislave.c
|
||||
* \brief I2C slave library. taken from http://www.roboternetz.de/wissen/index.php/TWI_Slave_mit_avr-gcc
|
||||
* \author Uwe Grosse-Wortmann (uwegw), reformatted by Ronald Schaten <ronald@schatenseite.de>
|
||||
* \version $Id: twislave.c,v 1.1 2008/07/16 05:44:45 rschaten Exp $
|
||||
*
|
||||
* License: GNU GPL v2 (see License.txt)
|
||||
*/
|
||||
|
||||
#include <util/twi.h> // enthaelt z. B. die Bezeichnungen fuer die Statuscodes in TWSR
|
||||
#include <avr/interrupt.h> // dient zur behandlung der Interrupts
|
||||
#include <stdint.h> // definiert den Datentyp uint8_t
|
||||
|
||||
#include "twislave.h"
|
||||
|
||||
// Bei zu alten AVR-GCC-Versionen werden die Interrupts anders genutzt, daher
|
||||
// in diesem Fall mit Fehlermeldung abbrechen
|
||||
#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
|
||||
# error "This library requires AVR-GCC 3.4.5 or later, update to newer AVR-GCC compiler!"
|
||||
#endif
|
||||
|
||||
// Schutz vor unsinnigen Buffergroessen
|
||||
#if (buffer_size > 254)
|
||||
# error Buffer zu gross gewaehlt! Maximal 254 Bytes erlaubt.
|
||||
#endif
|
||||
#if (buffer_size < 2)
|
||||
# error Buffer muss mindestens zwei Byte gross sein!
|
||||
#endif
|
||||
|
||||
volatile uint8_t buffer_adr; //< "Adressregister" fuer den Buffer
|
||||
|
||||
/**
|
||||
* Initalisierung des TWI-Interface. Muss zu Beginn aufgerufen werden, sowie
|
||||
* bei einem Wechsel der Slave Adresse.
|
||||
* \param adr gewuenschte Slave-Adresse
|
||||
*/
|
||||
void init_twi_slave(uint8_t adr) {
|
||||
TWAR = adr; // Adresse setzen
|
||||
TWCR &= ~(1 << TWSTA) | (1 << TWSTO);
|
||||
TWCR |= (1 << TWEA) | (1 << TWEN) | (1 << TWIE);
|
||||
buffer_adr = 0xff;
|
||||
sei();
|
||||
}
|
||||
|
||||
// Je nach Statuscode in TWSR muessen verschiedene Bitmuster in TWCR geschreiben werden (siehe Tabellen im Datenblatt).
|
||||
// Makros fuer die verwendeten Bitmuster:
|
||||
|
||||
// ACK nach empfangenen Daten senden/ ACK nach gesendeten Daten erwarten
|
||||
#define TWCR_ACK TWCR = (1 << TWEN) | (1 << TWIE) | (1 << TWINT) | (1 << TWEA) | (0 << TWSTA) | (0 << TWSTO) | (0 << TWWC);
|
||||
// NACK nach empfangenen Daten senden/ NACK nach gesendeten Daten erwarten
|
||||
#define TWCR_NACK TWCR = (1 << TWEN) | (1 << TWIE) | (1 << TWINT) | (0 << TWEA) | (0 << TWSTA) | (0 << TWSTO) | (0 << TWWC);
|
||||
// switched to the non adressed slave mode...
|
||||
#define TWCR_RESET TWCR = (1 << TWEN) | (1 << TWIE) | (1 << TWINT) | (1 << TWEA) | (0 << TWSTA) | (0 << TWSTO) | (0 << TWWC);
|
||||
|
||||
// Die Bitmuster fuer TWCR_ACK und TWCR_RESET sind gleich. Dies ist kein Fehler und dient nur der Uebersicht!
|
||||
|
||||
|
||||
/**
|
||||
* ISR, die bei einem Ereignis auf dem Bus ausgeloest wird. Im Register TWSR
|
||||
* befindet sich dann ein Statuscode, anhand dessen die Situation festgestellt
|
||||
* werden kann.
|
||||
*/
|
||||
ISR(TWI_vect) {
|
||||
uint8_t data = 0;
|
||||
|
||||
// TWI-Statusregister pruefen und noetige Aktion bestimmen
|
||||
switch (TW_STATUS) {
|
||||
case TW_SR_SLA_ACK: // 0x60 Slave Receiver, wurde adressiert
|
||||
TWCR_ACK; // naechstes Datenbyte empfangen, ACK danach
|
||||
buffer_adr = 0xFF; // Bufferposition ist undefiniert
|
||||
break;
|
||||
case TW_SR_DATA_ACK: // 0x80 Slave Receiver,Daten empfangen
|
||||
data = TWDR; // Empfangene Daten auslesen
|
||||
if (buffer_adr == 0xFF) { // erster Zugriff, Bufferposition setzen
|
||||
// Kontrolle ob gewuenschte Adresse im erlaubten bereich
|
||||
if (data <= buffer_size) {
|
||||
buffer_adr = data; // Bufferposition wie adressiert setzen
|
||||
} else {
|
||||
buffer_adr = 0; // Adresse auf Null setzen. Ist das sinnvoll?
|
||||
}
|
||||
TWCR_ACK; // naechstes Datenbyte empfangen, ACK danach, um naechstes Byte anzufordern
|
||||
} else { // weiterer Zugriff, Daten empfangen
|
||||
rxbuffer[buffer_adr] = data; // Daten in Buffer schreiben
|
||||
buffer_adr++; // Buffer-Adresse weiterzaehlen fuer naechsten Schreibzugriff
|
||||
if (buffer_adr < (buffer_size - 1)) { // im Buffer ist noch Platz fuer mehr als ein Byte
|
||||
TWCR_ACK; // naechstes Datenbyte empfangen, ACK danach, um naechstes Byte anzufordern
|
||||
} else { // es kann nur noch ein Byte kommen, dann ist der Buffer voll
|
||||
TWCR_NACK; // letztes Byte lesen, dann NACK, um vollen Buffer zu signaliseren
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TW_ST_SLA_ACK: // ?!?
|
||||
case TW_ST_DATA_ACK: // 0xB8 Slave Transmitter, weitere Daten wurden angefordert
|
||||
if (buffer_adr == 0xFF) { // zuvor keine Leseadresse angegeben!
|
||||
buffer_adr = 0;
|
||||
}
|
||||
TWDR = txbuffer[buffer_adr]; // Datenbyte senden
|
||||
buffer_adr++; // bufferadresse fuer naechstes Byte weiterzaehlen
|
||||
if (buffer_adr < (buffer_size - 1)) { // im Buffer ist mehr als ein Byte, das gesendet werden kann
|
||||
TWCR_ACK; // naechstes Byte senden, danach ACK erwarten
|
||||
} else {
|
||||
TWCR_NACK; // letztes Byte senden, danach NACK erwarten
|
||||
}
|
||||
break;
|
||||
case TW_ST_DATA_NACK: // 0xC0 Keine Daten mehr gefordert
|
||||
case TW_SR_DATA_NACK: // 0x88
|
||||
case TW_ST_LAST_DATA: // 0xC8 Last data byte in TWDR has been transmitted (TWEA = "0"); ACK has been received
|
||||
case TW_SR_STOP: // 0xA0 STOP empfangen
|
||||
default:
|
||||
TWCR_RESET; // Uebertragung beenden, warten bis zur naechsten Adressierung
|
||||
break;
|
||||
}
|
||||
}
|
72
twislave.h
Normal file
72
twislave.h
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* \file twislave.h
|
||||
* \brief I2C slave library. taken from http://www.roboternetz.de/wissen/index.php/TWI_Slave_mit_avr-gcc
|
||||
*
|
||||
* Betrieb eines AVRs mit Hardware-TWI-Schnittstelle als Slave. Zu Beginn muss
|
||||
* init_twi_slave mit der gewuenschten Slave-Adresse als Parameter aufgerufen
|
||||
* werden. Der Datenaustausch mit dem Master erfolgt ueber die Buffer rxbuffer
|
||||
* und txbuffer, auf die von Master und Slave zugegriffen werden kann. rxbuffer
|
||||
* und txbuffer sind globale Variablen (Array aus uint8_t).
|
||||
* Die Ansteuerung des rxbuffers, in den der Master schreiben kann, erfolgt
|
||||
* aehnlich wie bei einem normalen I2C-EEPROM.
|
||||
* Man sendet zunaechst die Bufferposition, an die man schreiben will, und dann
|
||||
* die Daten. Die Bufferposition wird automatisch hochgezaehlt, sodass man
|
||||
* mehrere Datenbytes hintereinander schreiben kann, ohne jedesmal die
|
||||
* Bufferadresse zu schreiben.
|
||||
* Um den txbuffer vom Master aus zu lesen, uebertraegt man zunaechst in einem
|
||||
* Schreibzugriff die gewuenschte Bufferposition und liest dann nach einem
|
||||
* repeated start die Daten aus. Die Bufferposition wird automatisch
|
||||
* hochgezaehlt, sodass man mehrere Datenbytes hintereinander lesen kann, ohne
|
||||
* jedesmal die Bufferposition zu schreiben.
|
||||
*
|
||||
* Autor: Uwe Grosse-Wortmann (uwegw)
|
||||
* Status: Testphase, keine Garantie fuer ordnungsgemaesse Funktion!
|
||||
* letze Aenderungen:
|
||||
* 23.03.07 Makros fuer TWCR eingefuegt. Abbruch des Sendens, wenn der TXbuffer
|
||||
* komplett gesendet wurde.
|
||||
* 24.03.07 verbotene Buffergroessen abgefangen
|
||||
* 25.03.07 noetige externe Bibliotheken eingebunden
|
||||
*
|
||||
* Abgefangene Fehlbedienung durch den Master:
|
||||
* - Lesen ueber die Grenze des txbuffers hinaus
|
||||
* - Schreiben ueber die Grenzen des rxbuffers hinaus
|
||||
* - Angabe einer ungueltigen Schreib/Lese-Adresse
|
||||
* - Lesezugriff, ohne vorher Leseadresse geschrieben zu haben
|
||||
*
|
||||
* \author Uwe Grosse-Wortmann (uwegw), reformatted by Ronald Schaten <ronald@schatenseite.de>
|
||||
* \version $Id: twislave.h,v 1.1 2008/07/16 05:44:45 rschaten Exp $
|
||||
*
|
||||
* License: GNU GPL v2 (see License.txt)
|
||||
*/
|
||||
|
||||
#ifndef _TWISLAVE_H
|
||||
#define _TWISLAVE_H
|
||||
|
||||
#include <util/twi.h> // enthaelt z. B. die Bezeichnungen fuer die Statuscodes in TWSR
|
||||
#include <avr/interrupt.h> // dient zur behandlung der Interrupts
|
||||
#include <stdint.h> // definiert den Datentyp uint8_t
|
||||
|
||||
|
||||
|
||||
// von Benutzer konfigurierbare Einstellungen
|
||||
#define buffer_size 9 ///< Groesse der Buffer in Byte (2..254)
|
||||
|
||||
// Globale Variablen, die vom Hauptprogramm genutzt werden
|
||||
/**
|
||||
* Der Buffer, in dem die empfangenen Daten gespeichert werden. Der Slave
|
||||
* funktioniert aehnlich wie ein normales Speicher-IC [I2C-EEPROM], man sendet
|
||||
* die Adresse, an die man schreiben will, dann die Daten, die interne
|
||||
* Speicher-Adresse wird dabei automatisch hochgezaehlt.
|
||||
*/
|
||||
volatile uint8_t rxbuffer[buffer_size];
|
||||
|
||||
/**
|
||||
* Der Sendebuffer, der vom Master ausgelesen werden kann.
|
||||
*/
|
||||
volatile uint8_t txbuffer[buffer_size];
|
||||
|
||||
|
||||
// Funktionen, die vom Hauptprogramm aufgerufen werden koennen
|
||||
void init_twi_slave(uint8_t adr);
|
||||
|
||||
#endif //#ifdef _TWISLAVE_H
|
Loading…
Reference in New Issue
Block a user