diff --git a/ports/bdk-atxx4-mstp/Makefile b/ports/bdk-atxx4-mstp/Makefile index 5e3d49d7..4fc7122a 100644 --- a/ports/bdk-atxx4-mstp/Makefile +++ b/ports/bdk-atxx4-mstp/Makefile @@ -80,6 +80,7 @@ HALSRC = main.c \ adc.c \ input.c \ serial.c \ + spi-master.c \ rs485.c \ mstimer-init.c \ led.c \ @@ -181,12 +182,15 @@ ifeq (${SEEPROM},128) DEFINES += -DSEEPROM_PAGE_SIZE=64 DEFINES += -DSEEPROM_WORD_ADDRESS_16BIT=1 endif +ifeq (${BDK_VERSION},2) +DEFINES += -DBDK_VERSION=2 +endif ifeq (${BDK_VERSION},3) DEFINES += -DBDK_VERSION=3 endif - -#ifdef - +ifeq (${BDK_VERSION},4) +DEFINES += -DBDK_VERSION=4 +endif OPTIMIZE_FLAGS = -mcall-prologues OPTIMIZE_FLAGS += -finline-functions-called-once @@ -281,7 +285,7 @@ AVRDUDE_FLAGS += -P $(AVRDUDE_PORT) AVRDUDE_FLAGS += -B 8 # Fuse high byte (0=enable,1=disable): -# 0x93 = 1 0 0 1 0 0 1 1 +# 0x93 = 1 0 0 1 0 0 1 1 - v3,v4 board # 0x17 = 0 0 0 1 0 0 1 1 - v1,v2 board # 0x17 = 0 0 0 1 0 1 1 1 - default # ^ ^ ^ ^ ^ \+/ ^ @@ -295,7 +299,7 @@ AVRDUDE_FLAGS += -B 8 # +-------------------- OCDEN (Enable OCD) # # Fuse low byte (0=enable,1=disable): -# 0xD7 = 1 1 0 1 0 1 1 1 - v3 board +# 0xD7 = 1 1 0 1 0 1 1 1 - v3,v4 board # 0xE6 = 1 1 1 0 0 1 1 0 - v1,v2 board # 0x62 = 0 1 1 0 0 0 1 0 - default # ^ ^ \+/ \--+--/ diff --git a/ports/bdk-atxx4-mstp/spi-master.c b/ports/bdk-atxx4-mstp/spi-master.c new file mode 100644 index 00000000..ec4931e8 --- /dev/null +++ b/ports/bdk-atxx4-mstp/spi-master.c @@ -0,0 +1,64 @@ +/************************************************************************** +* +* Copyright (C) 2009 Steve Karg +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#include +#include +#include +#include "hardware.h" +#include "spi-master.h" + +void spi_master_init(void) +{ + /* SS, MOSI, MISO, SCK */ + DDRB=(1< +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*********************************************************************/ +#ifndef SPI_MASTER_H +#define SPI_MASTER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + uint8_t spi_master_transfer( + uint8_t txdata); + + void spi_master_init( + void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif diff --git a/ports/bdk-atxx4-mstp/test.c b/ports/bdk-atxx4-mstp/test.c index 34bac742..a517618c 100644 --- a/ports/bdk-atxx4-mstp/test.c +++ b/ports/bdk-atxx4-mstp/test.c @@ -16,6 +16,7 @@ #include "rs485.h" #include "bacnet/datalink/dlmstp.h" #include "seeprom.h" +#include "spi-master.h" #include "nvdata.h" /* me */ #include "test.h" @@ -47,6 +48,7 @@ void test_init(void) #else BIT_SET(DDRB, DDB0); #endif + spi_master_init(); } /** @@ -194,6 +196,10 @@ void test_task(void) "\r\nMax:%u", (unsigned)dlmstp_max_master()); serial_bytes_send((uint8_t *)Send_Buffer, strlen(Send_Buffer)); break; + case 's': + data_register = spi_master_transfer(0xBA); + snprintf(Send_Buffer, sizeof(Send_Buffer), "\r\nSPI:%02Xh", data_register); + break; default: break; }