Skip to content

Commit

Permalink
adding spi01 example.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelch67 committed Apr 8, 2014
1 parent 378efab commit 90c69e3
Show file tree
Hide file tree
Showing 7 changed files with 542 additions and 43 deletions.
24 changes: 23 additions & 1 deletion spi01/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ clean :
rm -f *.elf
rm -f *.list
rm -f *.img
rm -f *.bc
rm -f *.opt.s
rm -f *.norm.s
rm -f blinker01.s.*
rm -f blinker02.s.*
rm -f dumphex

novectors.o : novectors.s
$(ARMGNU)-as novectors.s -o novectors.o

spi01.o : spi01.c
spi01.o : spi01.c blinker.h
$(ARMGNU)-gcc $(COPS) -c spi01.c -o spi01.o

spi01.elf : memmap novectors.o spi01.o
Expand All @@ -30,3 +36,19 @@ spi01.hex : spi01.elf
$(ARMGNU)-objcopy spi01.elf -O ihex spi01.hex


dumphex : dumphex.c
gcc -o dumphex dumphex.c

blinker.h : blinker02.s
gcc -o dumphex dumphex.c
avra -fI blinker02.s
./dumphex blinker02.s.hex


blinker01.s.hex : blinker01.s
avra -fI blinker01.s

blinker02.s.hex : blinker02.s
avra -fI blinker02.s


58 changes: 57 additions & 1 deletion spi01/README
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,60 @@ these programs.
See the top level README for information on how to connect the raspi
uart to your host computer.

This is a work in progress, learning how to use the spi master.
This example is using the raspberry pi as an AVR ISP.

The AVR board used initially is the Sparkfun pro micro 8Mhz/3.3v

http://www.sparkfun.com/products/10999

From an AVR document the chips with this serial isp are either byte
mode or page mode. This chip atmega32u4 is page mode so you load a
temporary buffer with 64 instructions, then send one command to program
that buffer into a page of flash.

The serial protocol is quite trivial so writing code to use it or modify
this program is simple.

At this time the code only supports one page/buffer, 64 instructions.

At this time not worrying about exact timing, it works with count to
N loops.

Raspberry pi interesting pins

//GPIO7 SPI0_CE1_N P1-26
//GPIO8 SPI0_CE0_N P1-24
//GPIO9 SPI0_MISO P1-21
//GPIO10 SPI0_MOSI P1-19
//GPIO11 SPI0_SCLK P1-23
//alt function 0 for all of the above

//P1 1 +3V3
//P1 25 GND
//p1 26 GPIO_CE1

Pro micro to raspi

(GND) P1-25 GND
(RST) P1-26 CE1_N
(VCC) P1-1 +3V3
(15) SCK JP6-9 P1-23 SCLK
(14) MISO JP6-10 P1-21 MISO
(16) MOSI JP6-11 P1-19 MOSI

The ATmega32U4 breakout board has a cluster of 6 pins (an AVR ISP header)
with all 6 labelled, you connect the raspberry pi signals (right side
of table above) to those six pins, nothing else. That breakout board
does not have an led at least not in the same place so you would have
to add one or use a scope or meter to see the I/O pin toggle after
programming.

The AVR doesnt use the chip select for communication, so I support CS0
but didnt wire it. The AVR is strange in that way, it does need the
chip held in reset so I abused CS1 (CE1_N) and mucked with its
non-asserted state as if it were a gpio pin to assert and deassert reset
on the AVR. Normal spi stuff derived from this example should use CE0_N
(CS0).

The avr samples use the avra assembler apt-get install avra

27 changes: 27 additions & 0 deletions spi01/blinker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

const unsigned short rom[0x80]=
{
0xC000, //00000000
0xE000, //00000001
0xBD04, //00000002
0xE005, //00000003
0xBD05, //00000004
0xE001, //00000005
0xB904, //00000006
0xE010, //00000007
0xE041, //00000008
0xEF20, //00000009
0xB516, //0000000A
0x3010, //0000000B
0xF7E9, //0000000C
0xB516, //0000000D
0x3010, //0000000E
0xF3E9, //0000000F
0x9523, //00000010
0x3020, //00000011
0xF7B9, //00000012
0x2704, //00000013
0xB905, //00000014
0xCFF3, //00000015
};

34 changes: 34 additions & 0 deletions spi01/blinker01.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.device ATmega168
.equ DDRB = 0x04
.equ PORTB = 0x05

.org 0x0000
rjmp RESET

RESET:
ldi R16,0x01
out DDRB,R16

ldi R18,0x00
ldi R17,0x00
ldi R20,0x01
Loop:

ldi R19,0xE8
aloop:
inc R17
cpi R17,0x00
brne aloop

inc R18
cpi R18,0x00
brne aloop

inc R19
cpi R19,0x00
brne aloop

eor R16,R20
out PORTB, R16
rjmp Loop

53 changes: 53 additions & 0 deletions spi01/blinker02.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

.device ATmega168

.equ DDRB = 0x04
.equ PORTB = 0x05
.equ TCCR0A = 0x24
.equ TCCR0B = 0x25
.equ TCNT0 = 0x26

;.equ CLKPR = 0x61

.org 0x0000
rjmp RESET

RESET:

; ldi r16,0x80
; ldi r17,0x00
; sts CLKPR,r16
; sts CLKPR,r17


ldi R16,0x00
out TCCR0A,R16
ldi R16,0x05
out TCCR0B,R16

ldi R16,0x01
out DDRB,R16

ldi R17,0x00
ldi R20,0x01
Loop:


ldi R18,0xF0 ;; change this to change the blink rate
aloop:
in R17,TCNT0
cpi R17,0x00
brne aloop

bloop:
in R17,TCNT0
cpi R17,0x00
breq bloop

inc R18
cpi R18,0x00
brne aloop

eor R16,R20
out PORTB, R16
rjmp Loop
Loading

0 comments on commit 90c69e3

Please sign in to comment.