Root/atusb/fw2/spi.c

Source at commit ec21e4ba4756379934fc24635438040f66d2ab7c created 9 years 3 months ago.
By Werner Almesberger, atusb/fw2: support device -> host side of the ATUSB EP0 protocol
1#include <stdint.h>
2
3#include <avr/io.h>
4
5#include "io.h"
6#include "spi.h"
7
8
9void spi_begin(void)
10{
11    CLR(nSS);
12}
13
14
15uint8_t spi_io(uint8_t v)
16{
17// while (!(UCSR1A & 1 << UDRE1));
18        UDR1 = v;
19        while (!(UCSR1A & 1 << RXC1));
20        return UDR1;
21}
22
23
24void spi_end(void)
25{
26// while (!(UCSR1A & 1 << TXC1));
27    SET(nSS);
28}
29
30
31void spi_init(void)
32{
33    OUT(SCLK);
34    OUT(MOSI);
35    OUT(nSS);
36    IN(MISO);
37
38    UBRR1 = 0; /* set bit rate to zero to begin */
39    UCSR1C = 1 << UMSEL11 | 1 << UMSEL10;
40            /* set MSPI, MSB first, SPI data mode 0 */
41    UCSR1B = 1 << RXEN1 | 1 << TXEN1;
42            /* enable receiver and transmitter */
43    UBRR1 = 0; /* reconfirm the bit rate */
44}
45

Archive Download this file



interactive