-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmdriver.c
32 lines (27 loc) · 854 Bytes
/
mmdriver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include "mmdriver.h"
uint16_t holdReg[10];
int holdingRegisters_R(uint16_t startAddr, uint16_t nReg, uint16_t *data){
int i = 0;
printf("\tReading Multiple Registers\n");
printf("\t\tstartAddr: %d\tnReg: %d\n\t", startAddr, nReg);
for(int j = startAddr; j < nReg + startAddr; j++){
data[i] = holdReg[j];
printf("\treadHoldReg[%d] = %d", j, holdReg[j]);
i++;
}
printf("\n");
return i;
}
int holdingRegisters_W(uint16_t startAddr, uint16_t nReg, uint16_t *data){
int i = 0;
printf("\tWriting Multiple Registers\n");
printf("\t\tstartAddr: %d\tnReg: %d\n\t", startAddr, nReg);
for(int j = startAddr; j < nReg + startAddr; j++){
holdReg[j] = data[i];
printf("\tholdREG[%d] = %d", j, holdReg[j]);
i++;
}
printf("\n");
return i;
}