Feature/add spi master test example for bdk (#1027)
This commit is contained in:
@@ -80,6 +80,7 @@ HALSRC = main.c \
|
|||||||
adc.c \
|
adc.c \
|
||||||
input.c \
|
input.c \
|
||||||
serial.c \
|
serial.c \
|
||||||
|
spi-master.c \
|
||||||
rs485.c \
|
rs485.c \
|
||||||
mstimer-init.c \
|
mstimer-init.c \
|
||||||
led.c \
|
led.c \
|
||||||
@@ -181,12 +182,15 @@ ifeq (${SEEPROM},128)
|
|||||||
DEFINES += -DSEEPROM_PAGE_SIZE=64
|
DEFINES += -DSEEPROM_PAGE_SIZE=64
|
||||||
DEFINES += -DSEEPROM_WORD_ADDRESS_16BIT=1
|
DEFINES += -DSEEPROM_WORD_ADDRESS_16BIT=1
|
||||||
endif
|
endif
|
||||||
|
ifeq (${BDK_VERSION},2)
|
||||||
|
DEFINES += -DBDK_VERSION=2
|
||||||
|
endif
|
||||||
ifeq (${BDK_VERSION},3)
|
ifeq (${BDK_VERSION},3)
|
||||||
DEFINES += -DBDK_VERSION=3
|
DEFINES += -DBDK_VERSION=3
|
||||||
endif
|
endif
|
||||||
|
ifeq (${BDK_VERSION},4)
|
||||||
#ifdef
|
DEFINES += -DBDK_VERSION=4
|
||||||
|
endif
|
||||||
|
|
||||||
OPTIMIZE_FLAGS = -mcall-prologues
|
OPTIMIZE_FLAGS = -mcall-prologues
|
||||||
OPTIMIZE_FLAGS += -finline-functions-called-once
|
OPTIMIZE_FLAGS += -finline-functions-called-once
|
||||||
@@ -281,7 +285,7 @@ AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
|
|||||||
AVRDUDE_FLAGS += -B 8
|
AVRDUDE_FLAGS += -B 8
|
||||||
|
|
||||||
# Fuse high byte (0=enable,1=disable):
|
# 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 0 1 1 - v1,v2 board
|
||||||
# 0x17 = 0 0 0 1 0 1 1 1 - default
|
# 0x17 = 0 0 0 1 0 1 1 1 - default
|
||||||
# ^ ^ ^ ^ ^ \+/ ^
|
# ^ ^ ^ ^ ^ \+/ ^
|
||||||
@@ -295,7 +299,7 @@ AVRDUDE_FLAGS += -B 8
|
|||||||
# +-------------------- OCDEN (Enable OCD)
|
# +-------------------- OCDEN (Enable OCD)
|
||||||
#
|
#
|
||||||
# Fuse low byte (0=enable,1=disable):
|
# 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
|
# 0xE6 = 1 1 1 0 0 1 1 0 - v1,v2 board
|
||||||
# 0x62 = 0 1 1 0 0 0 1 0 - default
|
# 0x62 = 0 1 1 0 0 0 1 0 - default
|
||||||
# ^ ^ \+/ \--+--/
|
# ^ ^ \+/ \--+--/
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* 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 <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "hardware.h"
|
||||||
|
#include "spi-master.h"
|
||||||
|
|
||||||
|
void spi_master_init(void)
|
||||||
|
{
|
||||||
|
/* SS, MOSI, MISO, SCK */
|
||||||
|
DDRB=(1<<PINB4)|(1<<PINB5)|(0<<PINB6)|(1<<PINB7);
|
||||||
|
/* Enable SPI, Master, Clk/128 */
|
||||||
|
SPCR=(1<<SPR0)|(1<<SPR1)|(1<<MSTR)|(0<<DORD)|(1<<SPE)|(0<<SPIE);
|
||||||
|
power_spi_enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t spi_master_transfer(
|
||||||
|
uint8_t txdata)
|
||||||
|
{
|
||||||
|
/* Send SPI data */
|
||||||
|
SPDR = txdata;
|
||||||
|
/* Wait for transmission complete */
|
||||||
|
while(!(SPSR & (1<<SPIF))) {
|
||||||
|
/* do nothing */
|
||||||
|
}
|
||||||
|
|
||||||
|
return SPDR;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TEST_SPI_MASTER
|
||||||
|
uint8_t Data_Register;
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
spi_master_init();
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
/* loopback test */
|
||||||
|
Data_Register = spi_master_transfer(0xBA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* 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 <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
uint8_t spi_master_transfer(
|
||||||
|
uint8_t txdata);
|
||||||
|
|
||||||
|
void spi_master_init(
|
||||||
|
void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
#endif
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "rs485.h"
|
#include "rs485.h"
|
||||||
#include "bacnet/datalink/dlmstp.h"
|
#include "bacnet/datalink/dlmstp.h"
|
||||||
#include "seeprom.h"
|
#include "seeprom.h"
|
||||||
|
#include "spi-master.h"
|
||||||
#include "nvdata.h"
|
#include "nvdata.h"
|
||||||
/* me */
|
/* me */
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
@@ -47,6 +48,7 @@ void test_init(void)
|
|||||||
#else
|
#else
|
||||||
BIT_SET(DDRB, DDB0);
|
BIT_SET(DDRB, DDB0);
|
||||||
#endif
|
#endif
|
||||||
|
spi_master_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -194,6 +196,10 @@ void test_task(void)
|
|||||||
"\r\nMax:%u", (unsigned)dlmstp_max_master());
|
"\r\nMax:%u", (unsigned)dlmstp_max_master());
|
||||||
serial_bytes_send((uint8_t *)Send_Buffer, strlen(Send_Buffer));
|
serial_bytes_send((uint8_t *)Send_Buffer, strlen(Send_Buffer));
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
data_register = spi_master_transfer(0xBA);
|
||||||
|
snprintf(Send_Buffer, sizeof(Send_Buffer), "\r\nSPI:%02Xh", data_register);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user