Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Communication/RS485/RS485.cpp
- Revision:
- 20:eae8c84f318c
- Parent:
- 0:669ef71cba68
- Child:
- 21:e3b58d675c1c
diff -r 96a462583af9 -r eae8c84f318c Communication/RS485/RS485.cpp
--- a/Communication/RS485/RS485.cpp Tue Jul 16 06:48:51 2019 +0000
+++ b/Communication/RS485/RS485.cpp Tue Aug 27 04:33:08 2019 +0000
@@ -5,20 +5,26 @@
#include "../../System/Using.h"
namespace RS485 {
- DigitalOut selectBit(SELECTBIT_PIN);
+ DigitalOut selectBitT(SELECTBIT_T_PIN);
+ DigitalOut selectBitR(SELECTBIT_R_PIN);
Serial RS485Uart(RS485UART_TX, RS485UART_RX);
+ Serial RS485Line(RS485LINE_TX, RS485LINE_RX);
void Transmit();
+ void Recieve();
void RS485::Initialize() {
- selectBit = 1; //送信固定
+ selectBitT = 1; //送信固定
+ selectBitR = 0; //受信固定
RS485Uart.baud(38400);
- RS485Uart.attach(Transmit, Serial::TxIrq);
+ RS485Uart.attach(Transmit, Serial::TxIrq); //送信割り込み
+ RS485Line.baud(38400);
+ RS485Line.attach(Recieve, Serial::RxIrq); //受信割り込み
}
void Transmit() {
+ __disable_irq();
static uint8_t count = 0;
- __disable_irq();
RS485Uart.putc(RS485SendBuffer.GetData());
if(count >= 200) {
#ifdef USE_MOTOR
@@ -29,4 +35,15 @@
} else count++;
__enable_irq();
}
+
+ void Recieve() {
+ static uint8_t count = 0;
+ __disable_irq();
+ char data = RS485Line.getc();
+ if(count >= 200) {
+ LED_DEBUG1 = !LED_DEBUG1;
+ count = 0;
+ } else count++;
+ __enable_irq();
+ }
}