From 5ed0b37fedcd9fe10eb281d55b5a78ded7b950fe Mon Sep 17 00:00:00 2001 From: Juraj Andrassy Date: Sat, 31 Aug 2019 17:06:32 +0200 Subject: [PATCH] option to deselect other device on SPI (for example network chip) --- Makefile | 7 +++++++ asmfunc.S | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/Makefile b/Makefile index c986e90..f0b092d 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,9 @@ F_CPU = 16000000 # CPU clock frequency [Hz] NOT critical: it just shoul SD_CS_PORT = PORTB # Data Register of the SD CS pin SD_CS_DDR = DDRB # Data Direction Register of the SD CS pin SD_CS_BIT = 4 # Bit of the SD CS pin +#OTHER_CS_PORT = PORTD # Data Register of other SPI device CS pin +#OTHER_CS_DDR = DDRD # Data Direction Register of other SPI device CS pin +#OTHER_CS_BIT = 2 # Bit of other SPI device CS pin USE_LED = 0 # Debug with two (defined in asmfunc.S) USE_UART = 0 # Debug on Serial. 0 ... deactivate or divider of http://wormfood.net/avrbaudcalc.php for baud rate! #------------------------------------------------------------------ @@ -21,7 +24,11 @@ endif TARGET = avr_boot ASRC = asmfunc.S OPTIMIZE = -Os -mcall-prologues -ffunction-sections -fdata-sections +ifdef OTHER_CS_BIT +DEFS = -DBOOT_ADR=$(BOOT_ADR) -DF_CPU=$(F_CPU) -DUSE_LED=$(USE_LED) -DUSE_UART=$(USE_UART) -DSD_CS_PORT=$(SD_CS_PORT) -DSD_CS_DDR=$(SD_CS_DDR) -DSD_CS_BIT=$(SD_CS_BIT) -DOTHER_CS_PORT=$(OTHER_CS_PORT) -DOTHER_CS_DDR=$(OTHER_CS_DDR) -DOTHER_CS_BIT=$(OTHER_CS_BIT) +else DEFS = -DBOOT_ADR=$(BOOT_ADR) -DF_CPU=$(F_CPU) -DUSE_LED=$(USE_LED) -DUSE_UART=$(USE_UART) -DSD_CS_PORT=$(SD_CS_PORT) -DSD_CS_DDR=$(SD_CS_DDR) -DSD_CS_BIT=$(SD_CS_BIT) +endif LIBS = DEBUG = dwarf-2 diff --git a/asmfunc.S b/asmfunc.S index 6c09175..4e8b548 100644 --- a/asmfunc.S +++ b/asmfunc.S @@ -17,6 +17,11 @@ #define DDR_CS _SFR_IO_ADDR(SD_CS_DDR), SD_CS_BIT #define PORT_CS _SFR_IO_ADDR(SD_CS_PORT), SD_CS_BIT +;OTHER DEVICE CS PIN +#ifdef OTHER_CS_BIT +#define DDR_CS1 _SFR_IO_ADDR(OTHER_CS_DDR), OTHER_CS_BIT +#define PORT_CS1 _SFR_IO_ADDR(OTHER_CS_PORT), OTHER_CS_BIT +#endif ;---------------------------------------------------------------------------; .nolist #include @@ -87,6 +92,9 @@ init_spi: sbi DDR_DI ; DI: output sbi DDR_CK ; SCLK: output sbi PORT_DO ; DO: pull-up +#ifdef PORT_CS1 + sbi PORT_CS1 ; CS1: pull-up +#endif ret .endfunc