ONE WIRE总线是一种对硬件设计很友好,对软件设计不友好的总线,一根线可以完成供电、时钟、和双向数据的功能,时序要求非常严格,写驱动的时候最好配合示波器,通信速度并不快,但距离较远,传输百米以上没有问题。
驱动如下:
/******************************************************************************
* 文 件 名 称:BspOneWire.c
* 文件功能概述:实现1-WIRE通信驱动接口
* 文 件 作 者:xxx
* 版 本:V1.0.0.0
* 修 订 记 录:2017-6-30创建
******************************************************************************/
#include "BspOneWire.h"
/*-------------------------- start implemention -----------------------------*/
/*
* 1-WIRE总线设置
*/
S_GpioCtrl sOWCtrlScl[E_OW_Max] =
{
{RCC_AHB1Periph_GPIOI, GPIOI, GPIO_Pin_11},
{RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_0},
{RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_0},
{RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_3},
{RCC_AHB1Periph_GPIOA, GPIOA, GPIO_Pin_3}
};
/*******************************************************************************
* 函 数 名:static void OneWireDelayUs(uint16 Us)
* 参 数:uint16 Us : 延时单位
* 返 回:无
* 创 建 人:xxx
* 创建时间:2017-6-30
* 详 述:OneWire使用的延时函数
* 修改记录:2017-6-30创建
*******************************************************************************/
//static void OneWireDelayUs(uint16 Us)
//{
// uint32 i = 0, j = 0;
//
// for (j = 0; j < Us; j++)
// {
// for(i = 0; i < 17; i++)
// {
// ;
// }
// }
//
//}
/*******************************************************************************
* 函 数 名:static sint8 OneWireSetDirOut(E_OWx eOWx)
* 参 数:无
* 返 回:0
* 创 建 人:xxx
* 创建时间:2017-6-30
* 详 述:设置总线为数据输出方向
* 修改记录:2017-6-30创建
*******************************************************************************/
static sint8 OneWireSetDirOut(E_OWx eOWx)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = sOWCtrlScl[eOWx].GPIOxPinx;
GPIO_Init(sOWCtrlScl[eOWx].GPIOx, &GPIO_InitStructure);
return 0;
}
/*******************************************************************************
* 函 数 名:static sint8