daad
Dependencies: mbed TrapezoidControl QEI
Communication/RS485/RS485.cpp@0:669ef71cba68, 2018-09-08 (annotated)
- Committer:
- t_yamamoto
- Date:
- Sat Sep 08 06:05:22 2018 +0000
- Revision:
- 0:669ef71cba68
- Child:
- 21:1f1e9c585da8
???????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
t_yamamoto | 0:669ef71cba68 | 1 | #include "RS485.h" |
t_yamamoto | 0:669ef71cba68 | 2 | #include "mbed.h" |
t_yamamoto | 0:669ef71cba68 | 3 | #include "ActuatorHub/ActuatorHub.h" |
t_yamamoto | 0:669ef71cba68 | 4 | #include "../../LED/LED.h" |
t_yamamoto | 0:669ef71cba68 | 5 | #include "../../System/Using.h" |
t_yamamoto | 0:669ef71cba68 | 6 | |
t_yamamoto | 0:669ef71cba68 | 7 | namespace RS485 { |
t_yamamoto | 0:669ef71cba68 | 8 | DigitalOut selectBit(SELECTBIT_PIN); |
t_yamamoto | 0:669ef71cba68 | 9 | Serial RS485Uart(RS485UART_TX, RS485UART_RX); |
t_yamamoto | 0:669ef71cba68 | 10 | |
t_yamamoto | 0:669ef71cba68 | 11 | void Transmit(); |
t_yamamoto | 0:669ef71cba68 | 12 | |
t_yamamoto | 0:669ef71cba68 | 13 | void RS485::Initialize() { |
t_yamamoto | 0:669ef71cba68 | 14 | selectBit = 1; //送信固定 |
t_yamamoto | 0:669ef71cba68 | 15 | RS485Uart.baud(38400); |
t_yamamoto | 0:669ef71cba68 | 16 | RS485Uart.attach(Transmit, Serial::TxIrq); |
t_yamamoto | 0:669ef71cba68 | 17 | } |
t_yamamoto | 0:669ef71cba68 | 18 | |
t_yamamoto | 0:669ef71cba68 | 19 | void Transmit() { |
t_yamamoto | 0:669ef71cba68 | 20 | static uint8_t count = 0; |
t_yamamoto | 0:669ef71cba68 | 21 | __disable_irq(); |
t_yamamoto | 0:669ef71cba68 | 22 | RS485Uart.putc(RS485SendBuffer.GetData()); |
t_yamamoto | 0:669ef71cba68 | 23 | if(count >= 200) { |
t_yamamoto | 0:669ef71cba68 | 24 | #ifdef USE_MOTOR |
t_yamamoto | 0:669ef71cba68 | 25 | LED_DEBUG2 = !LED_DEBUG2; |
t_yamamoto | 0:669ef71cba68 | 26 | #endif |
t_yamamoto | 0:669ef71cba68 | 27 | |
t_yamamoto | 0:669ef71cba68 | 28 | count = 0; |
t_yamamoto | 0:669ef71cba68 | 29 | } else count++; |
t_yamamoto | 0:669ef71cba68 | 30 | __enable_irq(); |
t_yamamoto | 0:669ef71cba68 | 31 | } |
t_yamamoto | 0:669ef71cba68 | 32 | } |