Closed GoogleCodeExporter closed 9 years ago
I proposed (in July 2009) a hardware abstraction that solves this (and many
other)
board pinout issues. It's in issue #59.
http://code.google.com/p/arduino/issues/detail?id=59
Rather than loading spi.h with more #ifdefs and continuing to use raw hardware
registers, it allows nearly all of spi.h to be replaced with the standard I/O
functions using the CORE_xxx defined symbols for the user's board. This will
work
for ALL future AVR-based boards with SPI, regardless of how the pins are
assigned.
ps: the digitalWrite()'s can optimize into a single instruction if the code in
issue
#140 is added.
#include "wiring.h"
//-----------------------------------------------------------------------------
//AVR SPI HAL
#define SPI0_WaitForReceive()
#define SPI0_RxData() (SPDR)
#define SPI0_TxData(Data) (SPDR = Data)
#define SPI0_WaitForSend() while( (SPSR & 0x80)==0x00 )
#define SPI0_SendByte(Data) SPI0_TxData(Data);SPI0_WaitForSend()
#define SPI0_RecvBute() SPI0_RxData()
#define SPI0_Init() pinMode(CORE_SS0_PIN, OUTPUT); \
pinMode(CORE_SCLK0_PIN, OUTPUT); \
pinMode(CORE_MOSI0_PIN, OUTPUT); \
digitalWrite(CORE_SS0_PIN, HIGH); \
digitalWrite(CORE_SCLK0_PIN, LOW); \
digitalWrite(CORE_MOSI0_PIN, LOW); \
SPCR = 0x50
//-----------------------------------------------------------------------------
//IInChip SPI HAL
#define IINCHIP_SpiInit SPI0_Init
#define IINCHIP_SpiSendData SPI0_SendByte
#define IINCHIP_SpiRecvData SPI0_RxData
#define IINCHIP_CSInit() pinMode(CORE_SS0_PIN, OUTPUT)
#define IINCHIP_CSon() digitalWrite(CORE_SS0_PIN, HIGH)
#define IINCHIP_CSoff() digitalWrite(CORE_SS0_PIN, LOW)
//-----------------------------------------------------------------------------
Original comment by paul.sto...@gmail.com
on 11 Mar 2010 at 3:16
Attachments:
I believe this is handled by the new SPI and Ethernet libraries, although in a
different way.
Original comment by dmel...@gmail.com
on 26 Oct 2010 at 12:58
Original issue reported on code.google.com by
nelson.r...@gmail.com
on 10 Feb 2010 at 3:51Attachments: