Commit ff315ae2 authored by Mark van Renswoude's avatar Mark van Renswoude

Fixed communication

parent 06b5a0e7
......@@ -9,6 +9,15 @@
#include <stdint.h>
// Baud rate for the RS485 communication
// At 16 Mhz we pick a baud rate with a very acceptable 0.2% error rate
// Source: http://www.robotroom.com/Asynchronous-Serial-Communication-2.html
const uint32_t CommBaudRate = 76800;
// Pin connected to the MAX485's Receiver and Driver Output Enable pins
const uint8_t CommWriteEnablePin = 2;
// How long the display should stay on once it's idle and showing the
// current step numbers.
const uint32_t DisplayIdleTimeout = 5000;
......
......@@ -7,6 +7,7 @@
#include <Arduino.h>
#include <Wire.h>
#include "global.h"
#include "config.h"
#include "display.h"
#include "protocol.h"
......@@ -22,7 +23,8 @@ void setup()
// At 16 Mhz we pick a baud rate with a very acceptable 0.2% error rate
// Source: http://www.robotroom.com/Asynchronous-Serial-Communication-2.html
Serial.begin(76800);
Serial.begin(CommBaudRate);
pinMode(CommWriteEnablePin, OUTPUT);
comm.begin();
}
......@@ -51,6 +53,14 @@ void loop()
void sendCommMessage(const uint8_t* data, uint8_t size)
{
digitalWrite(CommWriteEnablePin, HIGH);
comm.sendMsg(data, size);
digitalWrite(CommWriteEnablePin, LOW);
}
void handleCommMessage()
{
uint8_t* data = comm.getData();
......@@ -93,7 +103,7 @@ void handleCommMessage()
{
// Sender expects a response from us
const uint8_t msg[] = { ResponseUhmWhat, moduleIndex };
comm.sendMsg(msg, sizeof(msg));
sendCommMessage(msg, sizeof(msg));
}
}
}
......@@ -102,7 +112,7 @@ void handleCommMessage()
void handlePing(uint8_t* data, uint8_t length)
{
const uint8_t msg[] = { ResponsePing, settings.getModuleIndex() };
comm.sendMsg(msg, sizeof(msg));
sendCommMessage(msg, sizeof(msg));
}
......@@ -163,7 +173,7 @@ void handleSetPWM(uint8_t* data, uint8_t length)
}
const uint8_t msg[] = { ResponseSetPWM, settings.getModuleIndex() };
comm.sendMsg(msg, sizeof(msg));
sendCommMessage(msg, sizeof(msg));
}
......@@ -175,5 +185,5 @@ void handleGetSensors(uint8_t* data, uint8_t length)
uint8_t sensor2 = 0;
const uint8_t msg[] = { ResponseSetPWM, settings.getModuleIndex(), sensor1, sensor2 };
comm.sendMsg(msg, sizeof(msg));
sendCommMessage(msg, sizeof(msg));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment