Following the information in SC16IS752 and in MAX232, I'm attempting to make 2 Arduinos communicate with each other over RS232 (because of the distance it can get compared to other protocols) and using the I2C to 2 UART so that several UARTs can exist at the same time.
I've attached the schematic I've used for each side.
In addition, I've tried just getting the SC chip to talk to another and had success, and I've had an Atmega328p using the MAX232 on its hardware serial port talking to a desktop. Neither of these were a problem, but when trying to get 2 Arduinos communicating over the I2C to RS232 or even just getting one Arduino to talk to a desktop, it doesn't work.
In the next post I'll upload the code for the Arduino.
When the Arduino communicates to the computer, I see 0xFF on the computer side and 0x00 on the Arduino side.
In the datasheet of the SC16IS752, it says that its pins are 5V tolerant. Then it is okay to connect its SDA and SCL pins to the ATmega328P.
I assume that the SC16IS752 is working, so you don't have to test that.
A logic analyzer would help. I'm very fond of the 30 dollar LHT00SU1 with sigrok/PulseView.
Do you use the SPI bus ? If not, please remove this line: #include <SPI.h>
I'm confused when I try to read the sketch. I think the millis-timer and the way the data is flowing is not okay.
For example this:
while(altSerial.available()){
Serial.print(c);
}
The normal way is to always check incoming data, and only now and then transmit something.
Can you make a drawing how everything is connected and how the data flows in the sketch ? The problem seems to be the structure of the sketch. Maybe you should start all over.
You should start with the most simple test sketch.
The body of the loop() should check all the things, and act if something was received or if a timer is ready.
void loop()
{
check if something is received via Serial
check if something is received via AltSerial
check if something is received via I2Cuart
check a millis-timer
check another millis-timer
check yet another millis-timer
}
abs0:
What is wrong with checking it every so often?
A buffer could be empty, or (almost) full. Because that is unknown, it is better to read it as fast as possible. With multiple data inputs, it is even more important to check everything. It costs almost no time.
In case the other device only returns data after sending a command to it, then it might be possible to read the reply after sending the command. Personally, I prefer to check the input all the time in that situation as well.
Can you try a pass-through sketch ?
Connect the MAX232 to a computer and run a terminal program for that serial port.
Connect the Arduino IDE to the Arduino and open the serial monitor.
Try to send text in both directions.
The thing is, when I try the SC16IS752 where I connect its TX and RX together, a loop, I get the information in that I pushed out, but when I try to connect 2 of them together, I get nothing on one side and garbage (usually values that aren't in the 7bit ASCII table).