lhakpa dorji
/
Modbus
Modbus with stm 32
main.cpp@1:00f04cdf25aa, 2018-03-14 (annotated)
- Committer:
- lhakpa
- Date:
- Wed Mar 14 11:33:36 2018 +0000
- Revision:
- 1:00f04cdf25aa
- Parent:
- 0:40b96f9186c3
add comment
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:00f04cdf25aa | 19 | //Need to use interrupt |
lhakpa | 0:40b96f9186c3 | 20 | pc.attach(serial_callback); |
lhakpa | 0:40b96f9186c3 | 21 | // 1. button code |
lhakpa | 1:00f04cdf25aa | 22 | // a.Detect the press and push button and display on YAT |
lhakpa | 0:40b96f9186c3 | 23 | // 2. timer code |
lhakpa | 0:40b96f9186c3 | 24 | while(1) { |
lhakpa | 0:40b96f9186c3 | 25 | // loop code |
lhakpa | 0:40b96f9186c3 | 26 | myled = 1; // LED is ON |
lhakpa | 0:40b96f9186c3 | 27 | wait(0.2); // 200 ms |
lhakpa | 0:40b96f9186c3 | 28 | myled = 0; // LED is OFF |
lhakpa | 0:40b96f9186c3 | 29 | wait(1.0); // 1 sec |
lhakpa | 0:40b96f9186c3 | 30 | } |
lhakpa | 0:40b96f9186c3 | 31 | } |