40 lines
1.8 KiB
C
40 lines
1.8 KiB
C
#ifndef RTU_H
|
||
#define RTU_H
|
||
|
||
#include <xc.h>
|
||
#include <stdint.h>
|
||
|
||
// ─────────────────────────────────────────────
|
||
// Configuration Modbus RTU
|
||
// ─────────────────────────────────────────────
|
||
|
||
#define RTU_SLAVE_ADDR 0xB7
|
||
#define RTU_FC03 0x03
|
||
|
||
#define RTU_HR0_ADDR 0x1700 // Position QEI
|
||
|
||
// ─────────────────────────────────────────────
|
||
// Timer2 — timeout inter-caractère 3.5×
|
||
// ≈ 304 µs @ 115200 bps
|
||
// prescaler 1:16, PR2 = 151
|
||
// ─────────────────────────────────────────────
|
||
|
||
#define RTU_TIMER_PRESCALER 16
|
||
#define RTU_TIMER_PR2 151
|
||
|
||
// ─────────────────────────────────────────────
|
||
// Buffer
|
||
// ─────────────────────────────────────────────
|
||
|
||
#define RTU_BUF_SIZE 32
|
||
|
||
// ─────────────────────────────────────────────
|
||
// API publique
|
||
// ─────────────────────────────────────────────
|
||
|
||
void RTU_Init(void);
|
||
void RTU_RxISR(void); // ISR UART RX haute priorité
|
||
void RTU_TimerISR(void); // ISR Timer2 basse priorité
|
||
void RTU_Task(void); // boucle principale
|
||
|
||
#endif // RTU_H
|