Hi, I'm trying to get an Arduino to talk to the scalextric C7042 powerbase to allow using the protocoll it supports for talking to computers.
I have done this via a laptop, and once I got the serial port configured it worked fine.
the device uses RS-485 to talk, the protocol is basically transmit 9 bytes, get 15 bytes back, repeat at will.
I have managed to get two Arduino talking over RS-485, using Max485 chips on the handy little modules you can get cheaply on line, and sending the same data back and forth. But so far cannot coax a response from the C7042 - which will talk to a laptop quite well.
I suspect the issue is in the serial port configuration, the required specification is thus:
1 start bit
8 data bits
no parity bit
1 stop bit
19,200 baud.
the code used on the laptop to open the serial port is thus:
struct termios options;
#define DEVICE "/dev/tty.usbserial-AI023L0L"
int FD;
// try to close the port
close(FD);
FD = open(DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (FD <0)
{
// Error opening port
return 1;
}
// set back to blocking mode
if(fcntl(FD, F_SETFL, 0) == -1)
{
// Error configuring Port
return 2;
}
tcgetattr(FD, &options);
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8; // 8 bit data
options.c_cflag |= (CLOCAL | CREAD);
options.c_lflag = 0;
options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF);
options.c_cc[VMIN] = 14; // read 14 char --> full input packet
options.c_cc[VTIME] = 1;
if (tcsetattr(FD, TCSANOW, &options) == -1)
{
// Error configuring port
return 3;
}
this is obviously part of something quite a bit larger, this works
on the arduino the RS-485 module is connected to the Rx & Tx pins and the serial port opened with:
Serial.begin(19200, SERIAL_8N1);
which I think sets the baud rate to 19,200, 8 bit data, no parity and 1 stop bit
I can then use this configuration between two Arduino to talk happily, guessing because they both have the same configuration. tying this to the C7042 leads to the write operation reporting it worked (but then it is easily pleased as its just talking to the Max485 chip). yet the Serial.readBytes() operation times out and returns zero bytes - the C7042 isn't itself responding to what has been sent.
my question is this: is the Arduino serial port configuration in Serial.begin() likely correct/complete or is there another step required somewhere?
I've had a look on line at various tutorials which got the two Arduinos talking after a bit of fiddling sending binary data back and forth well so presumably the hardware etc is working fine meaning its either the configuration, while workable, is wrong for the target device, or there is something wrong in the checksum code - though the same code works fine on a laptop, and is the code lifted from the C7042 specification.
any guidance or references for where would be a good place to go with this most welcome