54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
#ifndef MODBUS_H
|
|
#define MODBUS_H
|
|
|
|
#include "device_ring_buffer.h"
|
|
#include "device_adc.h"
|
|
#include "device_address.h"
|
|
#include "UART.h"
|
|
#include "timer.h"
|
|
#include "gpio.h"
|
|
#include <stdint.h>
|
|
|
|
#define SIZE_MODBUS_PAKET (32)
|
|
#define MAX_PAUSE (4)
|
|
|
|
// Объявление адреса Slave
|
|
#define HOLDING_REGISTER_SLAVE_ADDRESS 100
|
|
|
|
// Объявление номеров Discrete Inputs
|
|
#define DISCRETE_INPUTS_1 0x00
|
|
#define DISCRETE_INPUTS_2 0x01
|
|
#define DISCRETE_INPUTS_3 0x02
|
|
#define DISCRETE_INPUTS_4 0x03
|
|
|
|
// Объявление номеров Coil
|
|
#define COIL_1 0x00
|
|
#define COIL_2 0x01
|
|
#define COIL_3 0x02
|
|
#define COIL_4 0x03
|
|
|
|
// Объявление номеров Input Registers
|
|
#define INPUT_REGISTERS 0x00
|
|
|
|
// Объявление кодов функций
|
|
#define READ_COILS 1
|
|
#define READ_DISCRETE_INPUTS 2
|
|
#define READ_HOLDING_REGISTERS 3
|
|
#define READ_INPUT_REGISTERS 4
|
|
#define WRITE_SINGLE_COIL 5
|
|
#define WRITE_SINGLE_REGISTER 6
|
|
#define WRITE_MULTIPLE_COILS 15
|
|
#define WRITE_MULTIPLE_REGISTER 16
|
|
|
|
//Объявление кодов ошибок
|
|
#define ILLEGAL_FUNCTION 1
|
|
#define ILLEGAL_DATA_ADDRESS 2
|
|
#define SLAVE_DEVICE_FAILURE 4
|
|
|
|
uint8_t size_of_packet;
|
|
|
|
void modbus_init(void);
|
|
void modbus_rtu (void);
|
|
void modbus_answer(void);
|
|
|
|
#endif /*MODBUS_H*/ |