赤ゾーンを青ゾーン仕様に

Dependencies:   mbed

Committer:
M_souta
Date:
Tue Aug 27 04:33:08 2019 +0000
Revision:
20:eae8c84f318c
Parent:
0:669ef71cba68
Child:
21:e3b58d675c1c
ttsts

Who changed what in which revision?

UserRevisionLine numberNew 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 {
M_souta 20:eae8c84f318c 8 DigitalOut selectBitT(SELECTBIT_T_PIN);
M_souta 20:eae8c84f318c 9 DigitalOut selectBitR(SELECTBIT_R_PIN);
t_yamamoto 0:669ef71cba68 10 Serial RS485Uart(RS485UART_TX, RS485UART_RX);
M_souta 20:eae8c84f318c 11 Serial RS485Line(RS485LINE_TX, RS485LINE_RX);
t_yamamoto 0:669ef71cba68 12
t_yamamoto 0:669ef71cba68 13 void Transmit();
M_souta 20:eae8c84f318c 14 void Recieve();
t_yamamoto 0:669ef71cba68 15
t_yamamoto 0:669ef71cba68 16 void RS485::Initialize() {
M_souta 20:eae8c84f318c 17 selectBitT = 1; //送信固定
M_souta 20:eae8c84f318c 18 selectBitR = 0; //受信固定
t_yamamoto 0:669ef71cba68 19 RS485Uart.baud(38400);
M_souta 20:eae8c84f318c 20 RS485Uart.attach(Transmit, Serial::TxIrq); //送信割り込み
M_souta 20:eae8c84f318c 21 RS485Line.baud(38400);
M_souta 20:eae8c84f318c 22 RS485Line.attach(Recieve, Serial::RxIrq); //受信割り込み
t_yamamoto 0:669ef71cba68 23 }
t_yamamoto 0:669ef71cba68 24
t_yamamoto 0:669ef71cba68 25 void Transmit() {
M_souta 20:eae8c84f318c 26 __disable_irq();
t_yamamoto 0:669ef71cba68 27 static uint8_t count = 0;
t_yamamoto 0:669ef71cba68 28 RS485Uart.putc(RS485SendBuffer.GetData());
t_yamamoto 0:669ef71cba68 29 if(count >= 200) {
t_yamamoto 0:669ef71cba68 30 #ifdef USE_MOTOR
t_yamamoto 0:669ef71cba68 31 LED_DEBUG2 = !LED_DEBUG2;
t_yamamoto 0:669ef71cba68 32 #endif
t_yamamoto 0:669ef71cba68 33
t_yamamoto 0:669ef71cba68 34 count = 0;
t_yamamoto 0:669ef71cba68 35 } else count++;
t_yamamoto 0:669ef71cba68 36 __enable_irq();
t_yamamoto 0:669ef71cba68 37 }
M_souta 20:eae8c84f318c 38
M_souta 20:eae8c84f318c 39 void Recieve() {
M_souta 20:eae8c84f318c 40 static uint8_t count = 0;
M_souta 20:eae8c84f318c 41 __disable_irq();
M_souta 20:eae8c84f318c 42 char data = RS485Line.getc();
M_souta 20:eae8c84f318c 43 if(count >= 200) {
M_souta 20:eae8c84f318c 44 LED_DEBUG1 = !LED_DEBUG1;
M_souta 20:eae8c84f318c 45 count = 0;
M_souta 20:eae8c84f318c 46 } else count++;
M_souta 20:eae8c84f318c 47 __enable_irq();
M_souta 20:eae8c84f318c 48 }
t_yamamoto 0:669ef71cba68 49 }