Change lib nRF24L01 to Davide Geroni
This commit is contained in:
43
Rmodule/spi/spi.c
Normal file
43
Rmodule/spi/spi.c
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
spi lib 0x01
|
||||
|
||||
copyright (c) Davide Gironi, 2012
|
||||
|
||||
Released under GPLv3.
|
||||
Please refer to LICENSE file for licensing information.
|
||||
*/
|
||||
|
||||
#include "spi.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
|
||||
/*
|
||||
* spi initialize
|
||||
*/
|
||||
void spi_init() {
|
||||
SPI_DDR &= ~((1<<SPI_MOSI) | (1<<SPI_MISO) | (1<<SPI_SS) | (1<<SPI_SCK)); //input
|
||||
SPI_DDR |= ((1<<SPI_MOSI) | (1<<SPI_SS) | (1<<SPI_SCK)); //output
|
||||
|
||||
SPCR = ((1<<SPE)| // SPI Enable
|
||||
(0<<SPIE)| // SPI Interupt Enable
|
||||
(0<<DORD)| // Data Order (0:MSB first / 1:LSB first)
|
||||
(1<<MSTR)| // Master/Slave select
|
||||
(0<<SPR1)|(1<<SPR0)| // SPI Clock Rate
|
||||
(0<<CPOL)| // Clock Polarity (0:SCK low / 1:SCK hi when idle)
|
||||
(0<<CPHA)); // Clock Phase (0:leading / 1:trailing edge sampling)
|
||||
|
||||
SPSR = (1<<SPI2X); // Double SPI Speed Bit
|
||||
}
|
||||
|
||||
/*
|
||||
* spi write one byte and read it back
|
||||
*/
|
||||
uint8_t spi_writereadbyte(uint8_t data) {
|
||||
SPDR = data;
|
||||
while((SPSR & (1<<SPIF)) == 0);
|
||||
return SPDR;
|
||||
}
|
||||
|
||||
|
31
Rmodule/spi/spi.h
Normal file
31
Rmodule/spi/spi.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
spi lib 0x01
|
||||
|
||||
copyright (c) Davide Gironi, 2012
|
||||
|
||||
References:
|
||||
- This library is based upon SPI avr lib by Stefan Engelke
|
||||
http://www.tinkerer.eu/AVRLib/SPI
|
||||
|
||||
Released under GPLv3.
|
||||
Please refer to LICENSE file for licensing information.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SPI_H_
|
||||
#define _SPI_H_
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
//spi ports
|
||||
#define SPI_DDR DDRB
|
||||
#define SPI_PORT PORTB
|
||||
#define SPI_MISO PB4
|
||||
#define SPI_MOSI PB3
|
||||
#define SPI_SCK PB5
|
||||
#define SPI_SS PB2
|
||||
|
||||
extern void spi_init();
|
||||
extern uint8_t spi_writereadbyte(uint8_t data);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user