Modbus with stm 32

Dependencies:   mbed

Committer:
lhakpa
Date:
Wed Mar 14 11:28:39 2018 +0000
Revision:
0:40b96f9186c3
Child:
1:00f04cdf25aa
modbus Work

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lhakpa 0:40b96f9186c3 1 #include "mbed.h"
lhakpa 0:40b96f9186c3 2 #include "modbus.h"
lhakpa 0:40b96f9186c3 3
lhakpa 0:40b96f9186c3 4 DigitalOut myled(LED1);
lhakpa 0:40b96f9186c3 5 RawSerial pc(USBTX, USBRX);
lhakpa 0:40b96f9186c3 6
lhakpa 0:40b96f9186c3 7 void serial_callback()
lhakpa 0:40b96f9186c3 8 {
lhakpa 0:40b96f9186c3 9 uint8_t frame[6];
lhakpa 0:40b96f9186c3 10
lhakpa 0:40b96f9186c3 11 char ch = pc.getc();
lhakpa 0:40b96f9186c3 12 if (modbus_parser(ch, frame)) {
lhakpa 0:40b96f9186c3 13
lhakpa 0:40b96f9186c3 14 }
lhakpa 0:40b96f9186c3 15 }
lhakpa 0:40b96f9186c3 16
lhakpa 0:40b96f9186c3 17 int main() {
lhakpa 0:40b96f9186c3 18 // setup code
lhakpa 0:40b96f9186c3 19 pc.attach(serial_callback);
lhakpa 0:40b96f9186c3 20 // 1. button code
lhakpa 0:40b96f9186c3 21 // 2. timer code
lhakpa 0:40b96f9186c3 22 while(1) {
lhakpa 0:40b96f9186c3 23 // loop code
lhakpa 0:40b96f9186c3 24 myled = 1; // LED is ON
lhakpa 0:40b96f9186c3 25 wait(0.2); // 200 ms
lhakpa 0:40b96f9186c3 26 myled = 0; // LED is OFF
lhakpa 0:40b96f9186c3 27 wait(1.0); // 1 sec
lhakpa 0:40b96f9186c3 28 }
lhakpa 0:40b96f9186c3 29 }