jung6717 / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

small temporary fix for spi.h #203

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
we are aware that many users found that by changing some defines in spi.h
the Ethernet shield became fully compatible with the arduino mega (apart
from some pins having to be manually redirected), but as the current
settings prevent the development of a new shield for the mega we are in a
chicken, egg dilemma has boards don't get developed for they would be
incompatible with the current standard files, so i suggest we at least fix
the library to be compatible with the current boards until a better
approach to various kinds of boards can be found, in the attachments i send
a file that has worked for me with no apparent problems over various boards
(tried the shield with the Duemilanove, Pro Mini and the mega)

Original issue reported on code.google.com by nelson.r...@gmail.com on 10 Feb 2010 at 3:51

Attachments:

GoogleCodeExporter commented 8 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:

GoogleCodeExporter commented 8 years ago
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