I2C to UART and RS485 problem

Hi,

I made a custom arduino board with an SC16IS752 and this library SC16IS752/I2C_RECEIVE.ino at master · nopnop2002/SC16IS752 · GitHub

I have a MAX485 module connected to this chip (TXB and RXB) and the control pin for transmit and receive is connected to PB1 pin of my ATMEGA328PB.

So, I can ping my chip, but nothing happend when i try to send data over RS485 or receive… I don’t uderstand why i’m totally blocked…

Thanks for your help !

Without the wiring it’s going to be hard to tell what may be wrong, but as a guess. MAX485 is a protocol that uses 2 data-wires (twisted pair) + common GND to achieve ‘half-duplex’ communication.
Do you set the DE & !RE pins HIGH for transmission and switch the LOW for reception ?

Ok so i have upload my wiring.

I have an USB to RS485 adapter connected to my MAX485 :slight_smile:

  • Ground is connected to ground
  • A to A
  • B to B

Yes for the DE RE pin, I have tested whith HIGH and LOW but nothing happend

I already used this MAX485 connected directly with my uC and everything work, but i have to add RS232 and for this i need 2 UART, this is why i have add an SC16IS752…

Ok I have connected TXA and RXB of my sc16is752 and it can’t read the register, I don’t know why (i use the self example)

So i can assume that DE & !RE are HIGH on the chip on that.
Now going from the point of view that you do have an actual arduino somewhere or an FDTI or something similar that enables you to check Serial input. Let’s say with arduino, you load an empty sketch onto it, connect the receiving MAX485’s TX to the Arduino’s TX, And set the DE !RE pins LOW. Now can you transmit Serial data from the USB to MAX485 module to the receiving end ?

I have already tested the MAX485 chip directly connected to the micro controller on a prototype, and everything worked. For my needs I made another card (pcb) with two chips (MAX485 and MAX3232) so I have 0 uart for two devices, I had to add the SC16IS752 chip to switch from I2C to two UARTs.

I carried out several tests and I noticed that the problem would come from the chip and the library. When I use READ register function I read nothing at all, then I use WRITE function and notice that it writes fine to a register, but when I read again I read another register and it tells me that it’s empty !

When I use the ping function, it just writes to a register and reads that same register and everything works.

So the problem would come from writing and reading, the registers read and write sound different I get the impression. But since this library is supposed to work I wonder why I have this problem …

So this is the sketch you are running ?

#include <SPI.h>
#include <Wire.h>
#include <SC16IS752.h>

SC16IS752 i2cuart = SC16IS752(SC16IS750_PROTOCOL_I2C,SC16IS750_ADDRESS_AA);

#define baudrate_A 9600
#define baudrate_B 38400

void setup() 
{
  Serial.begin(115200);
  Serial.println("Start testing");
  // UART to Serial Bridge Initialization
  i2cuart.begin(baudrate_A, baudrate_B); //baudrate setting
  if (i2cuart.ping()!=1) {
    Serial.println("device not found");
    while(1);
  } else {
    Serial.println("device found");
  }
  Serial.println("start serial communication");
  Serial.print("baudrate(channel A) = ");
  Serial.println(baudrate_A);
  Serial.print("baudrate(channel B) = ");
  Serial.println(baudrate_B);
}

void loop() 
{
  static char buffer_A[64] = {0};
  static int index_A = 0;
  static char buffer_B[64] = {0};
  static int index_B = 0;

  if (i2cuart.available(SC16IS752_CHANNEL_A) > 0){
    // read the incoming byte:
    char c = i2cuart.read(SC16IS752_CHANNEL_A);

#if 0
    Serial.print("c=");
    if (c < 0x20) {
      Serial.print(" ");
    } else {
      Serial.print(c);
    }
    Serial.print(" 0x");
    Serial.println(c,HEX);
#endif

    if (c == 0x0d) {
      
    } else if (c == 0x0a) {
      Serial.print("Channel A=[");
      Serial.print(buffer_A);
      Serial.println("]");
      index_A = 0;
    } else {
      buffer_A[index_A++] = c;
      buffer_A[index_A] = 0;
    }
  }


  if (i2cuart.available(SC16IS752_CHANNEL_B) > 0){
    // read the incoming byte:
    char c = i2cuart.read(SC16IS752_CHANNEL_B);

#if 0
    Serial.print("c=");
    if (c < 0x20) {
      Serial.print(" ");
    } else {
      Serial.print(c);
    }
    Serial.print(" 0x");
    Serial.println(c,HEX);
#endif

    if (c == 0x0d) {
      
    } else if (c == 0x0a) {
      Serial.print("Channel B=[");
      Serial.print(buffer_B);
      Serial.println("]");
      index_B = 0;
    } else {
      buffer_B[index_B++] = c;
      buffer_B[index_B] = 0;
    }
  }
}

That has debug parts already included, what do you see when you enable them ?
You can you simply connect RXA to TXB and RXB to TXA and add something to loop() like this

if (Serial.available() > 0){
    // read the incoming byte:
    char c = Serial.read();
    i2cuart.write(SC16IS752_CHANNEL_A, c);

Or use the ‘selftest.ino’ example which is meant for the same thing.

GREAT ! I can send data and i receive on my pc the data !

But when i send through the pc to the chip, nothing happend

EDIT: I try to send data with digital pin low (RE DE) and after HIGH, in all case it send the data, I don’t know why, I have verify the pin but it’s good

Everything work ! it’s my fault i don’t declare PIN 9 as an ouput…

It happens ! great your issue has been resolved.