55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
/*****************************************************************************
|
|
*
|
|
* File : modbus.h
|
|
* Compiler : IAR C 5.10C Kickstart
|
|
* Revision : $Revision: 1.0 $
|
|
* Date : $Date: 2008 / 12 / 09
|
|
* Updated by : $Author: Jongkwang Woo
|
|
*
|
|
* Support mail : spirit0305@naver.com
|
|
*
|
|
* Description : Header file for modbus.c
|
|
*
|
|
****************************************************************************/
|
|
|
|
#ifndef _MODBUS_H_
|
|
#define _MODBUS_H_
|
|
|
|
#include <stm32f4xx.h>
|
|
|
|
// Function Code Define
|
|
#define READ_COIL_STATUS 0x01
|
|
#define READ_HOLDING_REG 0x03
|
|
#define FORCE_SINGLE_COIL 0x05
|
|
#define PRESET_SINGLE_REG 0x06
|
|
#define PRESET_MULTI_REG 0x10
|
|
|
|
typedef struct
|
|
{
|
|
u8 device_addr;
|
|
u8 function_code;
|
|
u16 start_addr;
|
|
u16 number_of_data;
|
|
u8 crch;
|
|
u8 crcl;
|
|
} TModBusReadRegisterReq, *PModBusReadRegisterReq;
|
|
|
|
void GetCRC(u8 *pby, u16 nSize, u8 *byFirstReturn, u8 *bySecondReturn);
|
|
u8 ModBusPacketCheck(u8* rdata, u16 len, u8 addr);
|
|
|
|
void read_coil_process(u16 addr, u16 qty);
|
|
void write_single_coils_process(u16 addr, u16 qty);
|
|
void read_holding_reg_process(u16 addr, u16 qty);
|
|
void key_pads_process(u16 addr, u16 qty);
|
|
|
|
s16 GetRegister(u16 reg_addr);
|
|
s16 SetRegister(u16 reg_addr, s16 reg_value);
|
|
|
|
u8* ModBusReadRegister(u8 *rdata, u16 len, u16 *wlen);
|
|
u8* ModBusWriteRegister(u8 *rdata, u16 len, u16 *wlen);
|
|
|
|
void WordToByte(s16 data, u8 *bytes, u8 opt);
|
|
s16 ByteToWord(u8 *bytes, u8 opt);
|
|
|
|
#endif
|