IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit 313fb7c190db6521786843b66982c5d69bb6b585 created 13 years 1 month ago. By Werner Almesberger, atusb/fw/Makefile (CFLAGS): simplify -I../fw/include to -Iinclude | |
---|---|
1 | /* |
2 | * fw/spi.c - ATmega8 family SPI I/O |
3 | * |
4 | * Written 2011 by Werner Almesberger |
5 | * Copyright 2011 Werner Almesberger |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | */ |
12 | |
13 | |
14 | #include <stdint.h> |
15 | |
16 | #include <avr/io.h> |
17 | |
18 | #include "board.h" |
19 | #include "spi.h" |
20 | |
21 | |
22 | void spi_begin(void) |
23 | { |
24 | CLR(nSS); |
25 | } |
26 | |
27 | |
28 | uint8_t spi_io(uint8_t v) |
29 | { |
30 | // while (!(UCSR1A & 1 << UDRE1)); |
31 | UDR1 = v; |
32 | while (!(UCSR1A & 1 << RXC1)); |
33 | return UDR1; |
34 | } |
35 | |
36 | |
37 | void spi_end(void) |
38 | { |
39 | // while (!(UCSR1A & 1 << TXC1)); |
40 | SET(nSS); |
41 | } |
42 | |
43 | |
44 | void spi_init(void) |
45 | { |
46 | SET(nSS); |
47 | OUT(SCLK); |
48 | OUT(MOSI); |
49 | OUT(nSS); |
50 | IN(MISO); |
51 | |
52 | UBRR1 = 0; /* set bit rate to zero to begin */ |
53 | UCSR1C = 1 << UMSEL11 | 1 << UMSEL10; |
54 | /* set MSPI, MSB first, SPI data mode 0 */ |
55 | UCSR1B = 1 << RXEN1 | 1 << TXEN1; |
56 | /* enable receiver and transmitter */ |
57 | UBRR1 = 0; /* reconfirm the bit rate */ |
58 | } |
59 |