43 lines
1.9 KiB
C
43 lines
1.9 KiB
C
#ifndef RTU_H
|
||
#define RTU_H
|
||
|
||
#include <xc.h>
|
||
#include <stdint.h>
|
||
|
||
// ─────────────────────────────────────────────
|
||
// Configuration Modbus RTU
|
||
// ─────────────────────────────────────────────
|
||
|
||
#define RTU_SLAVE_ADDR 183
|
||
#define RTU_FC03 0x03
|
||
#define RTU_FC06 0x06
|
||
#define RTU_FC16 0x10
|
||
|
||
#define RTU_HR0_ADDR 0x1700 // Position QEI
|
||
#define RTU_HR1_ADDR 0x1701 // Position cible ARM (micropas)
|
||
|
||
// ─────────────────────────────────────────────
|
||
// 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
|