7#define READ_INPUT_REGISTERS 0x04
8#define READ_HOLDING_REGISTERS 0x03
9#define WRITE_SINGLE_REGISTER 0x06
18#define ILLEGAL_FUNCTION 1
19#define ILLEGAL_DATA_ADDRESS 2
20#define ILLEGAL_DATA_VALUE 3
21#define SLAVE_DEVICE_FAILURE 4
34 INTCONbits.TMR0IF = 0;
46 uint16_t adresseRegister = ((uint16_t)
rx_buf[2] << 8) |
rx_buf[3];
51 tx_buf[2] = (uint8_t)(length*2);
52 for(uint16_t i = 0; i < length; i++){
61 tx_buf[2] = (uint8_t)(length*2);
62 for(uint16_t i = 0; i < length; i++){
71 for (
int i = 2; i <= 5; i++) {
98 tx_buf[length+1] = crc >> 8;
103 for (uint8_t i = 0; i < length; i++){
uint16_t CRC16(const uint8_t *msg, uint16_t length)
CRC calculation for Modbus.
void EUSART1_SetRxInterruptHandler(void(*interruptHandler)(void))
void EUSART1_Write(uint8_t txData)
uint16_t measure_voltage()
uint16_t holding_registers[2]
void modbus_init(uint8_t address)
uint8_t modbus_analyse_and_answer(void)
#define READ_HOLDING_REGISTERS
Modbus function for read holding register = 03.
#define READ_INPUT_REGISTERS
Modbus function for read input register = 04.
void modbus_char_recvd(void)
#define WRITE_SINGLE_REGISTER
Modbus function for write a single register = 06.
void modbus_send(uint8_t length)
uint16_t input_registers[2]
void TMR0_SetInterruptHandler(void(*InterruptHandler)(void))
void TMR0_StartTimer(void)
void TMR0_StopTimer(void)