I'm sending data from an Allen-Bradley PLC to an Ardbox Analog HF+ MODBUS at 9600baud (8 data bits, no parity, one stop bit)
Each second, the A-B PLC sends a packet of 20 bytes plus CR and LF. I am using a RS485-USB adapter and Hyperterminal to show that the data is being sent. The link is connected to A+ and B-. Half duplex is selected.
When the program starts, the message <Arduino is ready> is correctly displayed on the Serial Monitor (COM21). The problem is that no further data is displayed, so we assume that the Arduino is not receiving any data. (Is the problem related to the Ardbox expecting Modbus protocol?)
Can you see any problem with this?
The code from "//Leading bogie onwards" works fine. It should write to digital outputs at up to 3kHz, in a sequence Set1-Set2-Clear1-Clear2. I am using the PORT command rather than digitalOutput for extra speed.
When the communications problem is solved, I will set the speed and direction of the sequence using data sent via RS485.
Thanks for any help you can give
The code looks like this:
// Include Industrial Shields libraries
#include <RS485.h>
long interval_0 = 250000;
long count_0 = 0;
unsigned long phase_0 = 0;
long interval_1 = 150000;
long count_1 = 0;
unsigned long phase_1 = 0;
bool DMA_forwards = 0; // 1 for DMA forwards, 2 for DMB forwards
char RxBuffer[24]; // 22-character buffer, 5 DINTs and CR LF with a couple to spare
int test_available;
const int serialConfig = SERIAL_8N1;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(2000);
SerialUSB.println("<Arduino is ready>");
// Begin RS485 port
RS485.begin(9600);
//RS485.setTimeout(90); //set serial read timeout to 90ms
}
void loop() {
// Main code
if (RS485.available()) {
byte rx = RS485.read();
// Hexadecimal representation
// byte rx=0;
// SerialUSB.write(rx);
SerialUSB.print("HEX: ");
SerialUSB.println(rx, HEX);
// Decimal representation
SerialUSB.print(", DEC: ");
SerialUSB.println(rx, DEC);
test_available = RS485.available();
SerialUSB.println("Chars available");
SerialUSB.println(test_available);
}
The port settings are unchanged from the original:
DDRB is B11100001
DDRC is B11000000
DDRD is B10101101
Selecting Full Duplex on the HD/FD selector switch makes no difference
Another odd thing: Including the RS485.begin(9600); line in the setup{} routine sets output Q0.9 (looking at the LEDs on the module).