54 lines
1.9 KiB
C
54 lines
1.9 KiB
C
#include "dev_addr.h"
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
//This program is for educational purposes only, without the author's permission, may not be used for any other purpose
|
|
//ALIENTEK STM32F407 Development Board
|
|
//RELAY driver code
|
|
//Hot Atomic @ALIENTEK
|
|
//Forum: www.openedv.com
|
|
//Date created: 2014/6/10
|
|
//Version: V1.0
|
|
//All rights reserved pirated reserved.
|
|
//Copyright(C) Guangzhou wing electronic technology limited company 2014-2024
|
|
//All rights reserved
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//Relay IO Initialize
|
|
void DevAddrInit(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
// Device addr configuration - Charge Relay
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); // GPIOB clock
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; // ADDR 0
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; // input
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // Pull Up
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // High-speed GPIO
|
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|
|
|
// Relay output configuration - Discharge Relay
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); // GPIOD clock
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 // ADDR 1
|
|
| GPIO_Pin_14 // ADDR 2
|
|
| GPIO_Pin_13 // ADDR 3
|
|
;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; // input
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // Pull Up
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // High-speed GPIO
|
|
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
|
}
|
|
|
|
u8 GetDevAddr(void)
|
|
{
|
|
u8 result = 0;
|
|
|
|
result |= (!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_10) << 3);
|
|
result |= (!GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_15) << 2);
|
|
result |= (!GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_14) << 1);
|
|
result |= (!GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_13) << 0);
|
|
|
|
return result;
|
|
}
|
|
|