uuu

Dependencies:   mbed TrapezoidControl QEI Pulse LM61CIZ

Committer:
M_souta
Date:
Tue Sep 17 04:40:17 2019 +0000
Revision:
22:7d93f79a3686
Parent:
21:e3b58d675c1c
kkk

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"
M_souta 21:e3b58d675c1c 4 #include "LineHub/LineHub.h"
t_yamamoto 0:669ef71cba68 5 #include "../../LED/LED.h"
t_yamamoto 0:669ef71cba68 6 #include "../../System/Using.h"
t_yamamoto 0:669ef71cba68 7
t_yamamoto 0:669ef71cba68 8 namespace RS485 {
M_souta 21:e3b58d675c1c 9
M_souta 20:eae8c84f318c 10 DigitalOut selectBitT(SELECTBIT_T_PIN);
M_souta 21:e3b58d675c1c 11 // DigitalOut selectBitR(SELECTBIT_R_PIN);
t_yamamoto 0:669ef71cba68 12 Serial RS485Uart(RS485UART_TX, RS485UART_RX);
M_souta 20:eae8c84f318c 13 Serial RS485Line(RS485LINE_TX, RS485LINE_RX);
M_souta 21:e3b58d675c1c 14
M_souta 21:e3b58d675c1c 15 bool readFase = 0;
M_souta 21:e3b58d675c1c 16 char buffer[RS485_BUFFER_LINE] = {0};
t_yamamoto 0:669ef71cba68 17
t_yamamoto 0:669ef71cba68 18 void Transmit();
M_souta 20:eae8c84f318c 19 void Recieve();
t_yamamoto 0:669ef71cba68 20
t_yamamoto 0:669ef71cba68 21 void RS485::Initialize() {
M_souta 20:eae8c84f318c 22 selectBitT = 1; //送信固定
M_souta 21:e3b58d675c1c 23 // selectBitR = 0; //受信固定
t_yamamoto 0:669ef71cba68 24 RS485Uart.baud(38400);
M_souta 20:eae8c84f318c 25 RS485Uart.attach(Transmit, Serial::TxIrq); //送信割り込み
M_souta 21:e3b58d675c1c 26 RS485Line.baud(9600);
M_souta 20:eae8c84f318c 27 RS485Line.attach(Recieve, Serial::RxIrq); //受信割り込み
t_yamamoto 0:669ef71cba68 28 }
t_yamamoto 0:669ef71cba68 29
t_yamamoto 0:669ef71cba68 30 void Transmit() {
M_souta 21:e3b58d675c1c 31 // __disable_irq();
t_yamamoto 0:669ef71cba68 32 static uint8_t count = 0;
t_yamamoto 0:669ef71cba68 33 RS485Uart.putc(RS485SendBuffer.GetData());
t_yamamoto 0:669ef71cba68 34 if(count >= 200) {
t_yamamoto 0:669ef71cba68 35 #ifdef USE_MOTOR
t_yamamoto 0:669ef71cba68 36 LED_DEBUG2 = !LED_DEBUG2;
t_yamamoto 0:669ef71cba68 37 #endif
t_yamamoto 0:669ef71cba68 38
t_yamamoto 0:669ef71cba68 39 count = 0;
t_yamamoto 0:669ef71cba68 40 } else count++;
t_yamamoto 0:669ef71cba68 41 __enable_irq();
t_yamamoto 0:669ef71cba68 42 }
M_souta 20:eae8c84f318c 43
M_souta 20:eae8c84f318c 44 void Recieve() {
M_souta 21:e3b58d675c1c 45 __disable_irq();
M_souta 21:e3b58d675c1c 46 static uint8_t time = 0;
M_souta 20:eae8c84f318c 47 static uint8_t count = 0;
M_souta 20:eae8c84f318c 48 char data = RS485Line.getc();
M_souta 21:e3b58d675c1c 49 if (data == 'S') {
M_souta 21:e3b58d675c1c 50 readFase = true;
M_souta 21:e3b58d675c1c 51 time = 0;
M_souta 21:e3b58d675c1c 52 } else if(data == 'F') {
M_souta 21:e3b58d675c1c 53 readFase = false;
M_souta 21:e3b58d675c1c 54 for(int i = 0; i < 8; i++) {
M_souta 21:e3b58d675c1c 55 lineData[i] = buffer[i];
M_souta 21:e3b58d675c1c 56 }
M_souta 21:e3b58d675c1c 57 time = 0;
M_souta 21:e3b58d675c1c 58 } else if(readFase) {
M_souta 21:e3b58d675c1c 59 buffer[time] = data;
M_souta 21:e3b58d675c1c 60 time++;
M_souta 21:e3b58d675c1c 61 } else {
M_souta 21:e3b58d675c1c 62 readFase = false;
M_souta 21:e3b58d675c1c 63 time = 0;
M_souta 21:e3b58d675c1c 64 }
M_souta 20:eae8c84f318c 65 if(count >= 200) {
M_souta 20:eae8c84f318c 66 LED_DEBUG1 = !LED_DEBUG1;
M_souta 20:eae8c84f318c 67 count = 0;
M_souta 20:eae8c84f318c 68 } else count++;
M_souta 20:eae8c84f318c 69 __enable_irq();
M_souta 20:eae8c84f318c 70 }
M_souta 21:e3b58d675c1c 71 }