Arduino with SC16IS750

Hello, everyone

I got a UART for I2C module and wanted to try to program this with two Arduinos. So an Uno connected to the SC16IS750 via I2C and the SC16IS750 via RX / TX to a second Arduino Uno. I used the SC16IS750.h library and tried to exchange data using the example sketch. But this doesn't work.
I connected the module directly to the Arduino because the pins are tolerant up to 5.5V. But what I suspect, are the I2C and RX / TX pins still controlled with 3.3V? Then do I have to use a LevelConverter?
But apart from that, should I see any data on the Uno that is being received, even if the voltage level is not the same, right? Has anyone ever experimented with that part?
What I also saw that the module can only pack up to 64 bytes in the buffer. How can you send the data in such a way that the buffer never overflows and everything arrives?

Here are the codes:

/*Arduino 1 has the SC16IS750 connected on SDA/SCL
 *TX/RX of the SC16IS750 is connected to Arduino 2
 *VCC/GND
 *I2C of the SC16IS750 is connected to VCC
 *A0 and A1 of the SC16IS750 is connected as shown in the address table below
 */

#include <Wire.h>
#include <SC16IS750.h>

SC16IS750 i2cuart = SC16IS750(SC16IS750_PROTOCOL_I2C,SC16IS750_ADDRESS_AA);   /*Address table:  A1    A0    Address
                                                                                               VDD   VDD    0x90 => AA
                                                                                               VDD   GND    0x92 => AB
                                                                                               VDD   SCL    0x94 => AC
                                                                                               VDD   SDA    0x96 => AD
                                                                                               GND   VDD    0x98 => BA
                                                                                               GND   GND    0x9A => BB
                                                                                               GND   SCL    0x9C => BC
                                                                                               GND   SDA    0x9E => BD
                                                                                               SCL   VDD    0xA0 => CA
                                                                                               SCL   GND    0xA2 => CB
                                                                                               SCL   SCL    0xA4 => CC
                                                                                               SCL   SDA    0xA6 => CD
                                                                                               SDA   VDD    0xA8 => DA
                                                                                               SDA   GND    0xAA => DB
                                                                                               SDA   SCL    0xAC => DC
                                                                                               SDA   SDA    0xAE => DD
                                                                                               */
int x = 0;
int y = 20;
int z = 300;
int A = 0;
int B = 0;
int C = 0;
char var;

void setup() {

Serial.begin(38400);
i2cuart.begin(9600);

}

void loop() {

x = x + 1;

i2cuart.write('X');
i2cuart.write(x);
i2cuart.write('Y');
i2cuart.write(y);
i2cuart.write('Z');
i2cuart.write(z);



while(i2cuart.available() > 0){
  var = i2cuart.read();
  switch(var){
    case 'A' : A = i2cuart.read();
               A |= i2cuart.read() << 8;
               Serial.print("A = ");
               Serial.println(A);
               break;
    case 'B' : B = i2cuart.read();
               B |= i2cuart.read() << 8;
               Serial.print("B = ");
               Serial.println(B);
               break;
    case 'C' : C = i2cuart.read();
               C |= i2cuart.read() << 8;
               Serial.print("C = ");
               Serial.println(C);
               break;
  }
}

}
/*Arduino 2 has the SC16IS750 connected on TX/RX
 */

int a = 0;
int b = 152;
int c = 1200;
char var;

void setup() {

Serial.begin(9600);

}

void loop() {

a = a + 1;

Serial.write('A');
Serial.write(a);
Serial.write('B');
Serial.write(b);
Serial.write('C');
Serial.write(c);



while(Serial.available() > 0){
  var = Serial.read();
  switch(var){
    case 'X' : Serial.print("X = ");
               Serial.println(Serial.parseInt());
               Serial.flush();
               break;
    case 'Y' : Serial.print("Y = ");
               Serial.println(Serial.parseInt());
               Serial.flush();
               break;
    case 'Z' : Serial.print("Z = ");
               Serial.println(Serial.parseInt());
               Serial.flush();
               break;
  }
}

}

Bally

Hi @bally94

to facilitate our help work, publish the complete schematic of your project.

Can be done freehand.

RV mineirin

As described in my sketch header.

Hi @bally94

I could not identify the PullUp resistors of the I2C bus.
Check if they exist on your SC16IS750 board or on the SC16IS750 IC datasheet if it has these resistors internally.

If not, you should add these resistors.
PS:
It seems there is:
but the value is too high, use external 10K resistors on each I2C pin. (about 3.6 MOhms)
Ref: RPU pag 43
RV mineirin

Okay, I will try to add 10k pullup resistors on SDA and SCL. But there are not built in resistors as I see it now, right? If so, I can add some 4.7k resistors instead of 10k. The Uno has not resistors too, for that reason 10k is probably too high!?

Okay, I have added some 4.7k resistors and get this on my serial monitor from the Arduino 2 where RX/TX is connected:

⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A⸮B⸮C⸮A

And on the serial monitor from the Arduino 1 where I2C is connected I get only an output if the TX/RX on my Arduino 2 is not connected:

A = -26963
A = -26963
A = -1749
B = -212
B = -19867
B = 8212
A = -256
B = -21179
B = -31702
A = -14940
A = 23060
A = 5209
C = 17750
A = 5209
C = -39
C = 5209
A = 5209
C = 5209
A = 23060
A = 17750
A = -2983
A = 5209
C = 5209
A = 5209
A = 23060
A = -14940
A = 23060
A = -14940
A = 23060
A = 23060
B = 17664
A = -20014
B = 17664
A = 23072
B = 25889
B = 22921
A = -13403
B = 18720
B = -28160
B = 18577
A = -20016
B = 4096
B = -20480
A = 20736
B = 5120
A = 5120
B = -28272
B = 22893
B = 25741
B = 25805
B = 25701
B = 25877
B = -13771
B = -27568
B = 19093
B = -23552
A = -30126
A = -20014
B = 18688
A = -256
B = 5120
A = -27055
A = -27819
B = 25957
B = 26005
B = 25925
B = 25965
A = 5193
B = 25933
B = 25965
C = -27371
B = -14059
C = 5209
A = 5209
A = 17109

But both outputs are not as expected. What is wrong with the code?

Got it! Here is the working code. The master code is on the Arduino with the SC16IS750 connected over I2C and the slave code is on the Arduino connected over TX/RX.
I remembered on my app for BLE connection on my Android phone. There was the same issue because of the limited buffer! Now I send one character after the other in both directions, because they passes the I2C connection for reading and writing. Here it is:

Master code:

/*Arduino 1 has the SC16IS750 connected on SDA/SCL
 *TX/RX of the SC16IS750 is connected to Arduino 2
 *VCC/GND
 *I2C of the SC16IS750 is connected to VCC
 *A0 and A1 of the SC16IS750 is connected as shown in the address table below
 */
 
#include <Wire.h>
#include <SC16IS750.h>

SC16IS750 i2cuart = SC16IS750(SC16IS750_PROTOCOL_I2C,SC16IS750_ADDRESS_AA);   /*Address table:  A1    A0    Address
                                                                                               VDD   VDD    0x90 => AA
                                                                                               VDD   GND    0x92 => AB
                                                                                               VDD   SCL    0x94 => AC
                                                                                               VDD   SDA    0x96 => AD
                                                                                               GND   VDD    0x98 => BA
                                                                                               GND   GND    0x9A => BB
                                                                                               GND   SCL    0x9C => BC
                                                                                               GND   SDA    0x9E => BD
                                                                                               SCL   VDD    0xA0 => CA
                                                                                               SCL   GND    0xA2 => CB
                                                                                               SCL   SCL    0xA4 => CC
                                                                                               SCL   SDA    0xA6 => CD
                                                                                               SDA   VDD    0xA8 => DA
                                                                                               SDA   GND    0xAA => DB
                                                                                               SDA   SCL    0xAC => DC
                                                                                               SDA   SDA    0xAE => DD
                                                                                               */

const byte bufferSize {10};
char serialBuffer[bufferSize+1] {""};
char myData[bufferSize];
char myData1[bufferSize];
char myData2[bufferSize];

char var;
int E = 0;
int F = 0;
int G = 0;
int H = 0;
int BUT = 0;

static byte i = 0;
static byte j = 0;
static byte k = 0;
int y = 0;


void setup (void)
{
  i2cuart.begin(9600);
  Serial.begin(38400);
}

void loop (void)
{

  Serial.print("E = ");
  Serial.println(E);
  Serial.print("F = ");
  Serial.println(F);
  Serial.print("G = ");
  Serial.println(G);
  Serial.print("H = ");
  Serial.println(H);
  Serial.print("BUT = ");
  Serial.println(BUT);

  
  command("A0");
  command("B55");
  command("C180");
  command("D125");
  command("@12");


while(i2cuart.available()) {
    char m = i2cuart.read();
    if(m != '\n') {
      myData[i++] = m;
    }
    
    else if(m == '\n') {
      i = 0;
      while(i <= strlen(myData) ) {
        if(isdigit(myData[i]) == true) {
          myData1[j] = myData[i];
          j++;
          i++;
        }
        else {
          myData2[k] = myData[i];
          k++;
          i++;
        }
      }
      memset(myData, 0, sizeof myData);
      j = 0;
      k = 0;
      i = 0;
      
      y = atoi(myData1);  //making the integer part
      var = myData2[0];

      memset(myData1, 0, sizeof myData1);
      memset(myData2, 0, sizeof myData2);

      switch(var) {
      case 'E' : E = y;
                 break;
      case 'F' : F = y;
                 break;
      case 'G' : G = y;
                 break;
      case 'H' : H = y;
                 break;
      case '#' : BUT = y;
                 break;
      }
    }
  }  
}



void command(String value) {
  memset(serialBuffer, 0, sizeof serialBuffer);
  sendToSlaveI2C(serialBuffer, value);
}


void sendToSlaveI2C (char *const buffer, String command)
{
  command.toCharArray(buffer, bufferSize);
  const size_t numberOfChar {strlen(buffer)};
  Serial.print("length: "); Serial.println(numberOfChar);

  for (byte i = 0; i < numberOfChar; i++)
  {
    i2cuart.write(buffer[i]);
    Serial.print("sent: ");
    Serial.println(buffer[i]);
  }
  i2cuart.write('\n');

}

Slave code:

/*Arduino 2 has the SC16IS750 connected on TX/RX
 */

const byte bufferSize {10};
char serialBuffer[bufferSize+1] {""};
char myData[bufferSize];
char myData1[bufferSize];
char myData2[bufferSize];

char var;
int A = 0;
int B = 0;
int C = 0;
int D = 0;
int BUT = 0;

static byte i = 0;
static byte j = 0;
static byte k = 0;
int y = 0;

  
void setup()
{
  Serial.begin(9600);
  
}

void loop() {

  
  Serial.print("A = ");
  Serial.println(A);
  Serial.print("B = ");
  Serial.println(B);
  Serial.print("C = ");
  Serial.println(C);
  Serial.print("D = ");
  Serial.println(D);
  Serial.print("BUT = ");
  Serial.println(BUT);


  command("E10");
  command("F5");
  command("G147");
  command("H251");
  command("#33");
  
  
  while(Serial.available()) {
    char m = Serial.read();
    if(m != '\n') {
      myData[i++] = m;
    }
    
    else if(m == '\n') {
      //Serial.print("myData: ");
      //Serial.println(myData);
      i = 0;
      while(i <= strlen(myData) ) {
        if(isdigit(myData[i]) == true) {
          myData1[j] = myData[i];
          j++;
          i++;
        }
        else {
          myData2[k] = myData[i];
          k++;
          i++;
        }
      }
      memset(myData, 0, sizeof myData);
      j = 0;
      k = 0;
      i = 0;
      //Serial.print("myData1: ");
      //Serial.println(myData1);
      //Serial.print("myData2: ");
      //Serial.println(myData2);
      
      y = atoi(myData1);  //making the integer part
      var = myData2[0];
      //Serial.println(var);
      //Serial.println(y);
      memset(myData1, 0, sizeof myData1);
      memset(myData2, 0, sizeof myData2);

      switch(var) {
      case 'A' : A = y;
                 break;
      case 'B' : B = y;
                 break;
      case 'C' : C = y;
                 break;
      case 'D' : D = y;
                 break;
      case '@' : BUT = y;
                 break;
      }
    }
  }
}


void command(String value) {
  memset(serialBuffer, 0, sizeof serialBuffer);
  sendToUART(serialBuffer, value);
}


void sendToUART (char *const buffer, String command)
{
  command.toCharArray(buffer, bufferSize);
  const size_t numberOfChar {strlen(buffer)};

  for (byte i = 0; i < numberOfChar; i++)
  {
    Serial.write(buffer[i]);
  }
  Serial.write('\n');

}

Now, I have tried to adapt this code for the SC16IS752 with two UART ports. If I delete or comment out the "readSerial()" section, it sends the data and the Arduino on the UART receives it. But if I put the "readSerial()" section in that should receive the data from the Arduino on the UART of the SC16IS752, I get only this on the serial monitor:

***********Data available***********
=====Available data:64
=====Available data:64
***********Data available***********
=====Available data:64
=====Available data:64
***********Data available***********
=====Available data:64
=====Available data:64
***********Data available***********
=====Available data:64
=====Available data:64
***********Data available***********
=====Available data:64
=====Available data:64
***********Data available***********
=====Available data:64
=====Available data:64
***********Data available***********
=====Available data:64
=====Available data:64
***********Data available***********
=====Available data:64

I have used this code for the master with the SC16IS752 connected with I2C:

/*Arduino 1 has the SC16IS752 connected on SDA/SCL
 *TX/RX of the SC16IS750 is connected to Arduino 2
 *VCC/GND
 *I2C of the SC16IS750 is connected to VCC
 *A0 and A1 of the SC16IS750 is connected as shown in the address table below
 */
 
#include <Wire.h>
#include <SC16IS752.h>

SC16IS752 i2cuart = SC16IS752(SC16IS750_PROTOCOL_I2C,SC16IS750_ADDRESS_AA);   /*Address table:  A1    A0    Address
                                                                                               VDD   VDD    0x90 => AA
                                                                                               VDD   GND    0x92 => AB
                                                                                               VDD   SCL    0x94 => AC
                                                                                               VDD   SDA    0x96 => AD
                                                                                               GND   VDD    0x98 => BA
                                                                                               GND   GND    0x9A => BB
                                                                                               GND   SCL    0x9C => BC
                                                                                               GND   SDA    0x9E => BD
                                                                                               SCL   VDD    0xA0 => CA
                                                                                               SCL   GND    0xA2 => CB
                                                                                               SCL   SCL    0xA4 => CC
                                                                                               SCL   SDA    0xA6 => CD
                                                                                               SDA   VDD    0xA8 => DA
                                                                                               SDA   GND    0xAA => DB
                                                                                               SDA   SCL    0xAC => DC
                                                                                               SDA   SDA    0xAE => DD
                                                                                               */

const byte bufferSize {10};
char serialBuffer[bufferSize+1] {""};
char myData[bufferSize];
char myData1[bufferSize];
char myData2[bufferSize];

char var;
char m;
int E = 0;
int F = 0;
int G = 0;
int H = 0;
int BUT = 0;

static byte i = 0;
static byte j = 0;
static byte k = 0;
int y = 0;


void setup (void)
{
  i2cuart.begin(38400, 38400); //UART A, UART B
  Serial.begin(38400);
}

void loop (void)
{
  readSerial();
  
  
  Serial.print("E = ");
  Serial.println(E);
  Serial.print("F = ");
  Serial.println(F);
  Serial.print("G = ");
  Serial.println(G);
  Serial.print("H = ");
  Serial.println(H);
  Serial.print("BUT = ");
  Serial.println(BUT);

  
  command("A0");
  command("B55");
  command("C180");
  command("D125");
  command("@12");
 
}



void command(String value) {
  memset(serialBuffer, 0, sizeof serialBuffer);
  sendToSlaveI2C(serialBuffer, value);
}


void sendToSlaveI2C (char *const buffer, String command)
{
  command.toCharArray(buffer, bufferSize);
  const size_t zeichenAnzahl {strlen(buffer)};
  Serial.print("laenge: "); Serial.println(zeichenAnzahl);

  if(strchr("ABC", buffer[0]) != NULL){
  for (byte i = 0; i < zeichenAnzahl; i++)
  {
    i2cuart.write(SC16IS752_CHANNEL_A, buffer[i]);
    Serial.print("sent: ");
    Serial.println(buffer[i]);
  }
  i2cuart.write(SC16IS752_CHANNEL_A, '\n');
  }

  else if(strchr("D@", buffer[0]) != NULL){
  for (byte i = 0; i < zeichenAnzahl; i++)
  {
    i2cuart.write(SC16IS752_CHANNEL_B, buffer[i]);
    Serial.print("sent: ");
    Serial.println(buffer[i]);
  }
  i2cuart.write(SC16IS752_CHANNEL_B, '\n');
  }
}


void readSerial(){
  while(i2cuart.available(SC16IS752_CHANNEL_A)) {
    m = i2cuart.read(SC16IS752_CHANNEL_A);
    receiveData();
  }

  while(i2cuart.available(SC16IS752_CHANNEL_B)) {
    m = i2cuart.read(SC16IS752_CHANNEL_B);
    receiveData();
  }
}


void receiveData(){
  if(m != '\n') {
      myData[i++] = m;
    }
    
    else if(m == '\n') {
      i = 0;
      while(i <= strlen(myData) ) {
        if(isdigit(myData[i]) == true) {
          myData1[j] = myData[i];
          j++;
          i++;
        }
        else {
          myData2[k] = myData[i];
          k++;
          i++;
        }
      }
      memset(myData, 0, sizeof myData);
      j = 0;
      k = 0;
      i = 0;
      
      y = atoi(myData1);  //making the integer part
      var = myData2[0];

      memset(myData1, 0, sizeof myData1);
      memset(myData2, 0, sizeof myData2);

      switch(var) {
      case 'E' : E = y;
                 break;
      case 'F' : F = y;
                 break;
      case 'G' : G = y;
                 break;
      case 'H' : H = y;
                 break;
      case '#' : BUT = y;
                 break;
      }
    }
}

And this code for the slave that is connected with the RX/TX:

/*Arduino 2 has the SC16IS750 connected on TX/RX
 */

const byte bufferSize {10};
char serialBuffer[bufferSize+1] {""};
char myData[bufferSize];
char myData1[bufferSize];
char myData2[bufferSize];

char var;
int A = 0;
int B = 0;
int C = 0;
int D = 0;
int BUT = 0;

static byte i = 0;
static byte j = 0;
static byte k = 0;
int y = 0;

  
void setup()
{
  Serial.begin(38400);
  
}

void loop() {

  readSerial();

  
  Serial.print("A = ");
  Serial.println(A);
  Serial.print("B = ");
  Serial.println(B);
  Serial.print("C = ");
  Serial.println(C);
  Serial.print("D = ");
  Serial.println(D);
  Serial.print("BUT = ");
  Serial.println(BUT);


  command("E10");
  command("F5");
  command("G147");
  command("H251");
  command("#33");
  
}


void command(String value) {
  memset(serialBuffer, 0, sizeof serialBuffer);
  sendToUART(serialBuffer, value);
}


void sendToUART (char *const buffer, String command)
{
  command.toCharArray(buffer, bufferSize);
  const size_t zeichenAnzahl {strlen(buffer)};

  for (byte i = 0; i < zeichenAnzahl; i++)
  {
    Serial.write(buffer[i]);
  }
  Serial.write('\n');

}


void readSerial(){
    while(Serial.available()) {
    char m = Serial.read();
    if(m != '\n') {
      myData[i++] = m;
    }
    
    else if(m == '\n') {
      //Serial.print("myData: ");
      //Serial.println(myData);
      i = 0;
      while(i <= strlen(myData) ) {
        if(isdigit(myData[i]) == true) {
          myData1[j] = myData[i];
          j++;
          i++;
        }
        else {
          myData2[k] = myData[i];
          k++;
          i++;
        }
      }
      memset(myData, 0, sizeof myData);
      j = 0;
      k = 0;
      i = 0;
      //Serial.print("myData1: ");
      //Serial.println(myData1);
      //Serial.print("myData2: ");
      //Serial.println(myData2);
      
      y = atoi(myData1);  //making the integer part
      var = myData2[0];
      //Serial.println(var);
      //Serial.println(y);
      memset(myData1, 0, sizeof myData1);
      memset(myData2, 0, sizeof myData2);

      switch(var) {
      case 'A' : A = y;
                 break;
      case 'B' : B = y;
                 break;
      case 'C' : C = y;
                 break;
      case 'D' : D = y;
                 break;
      case '@' : BUT = y;
                 break;
      }
    }
  }
}

What is wrong with the master code?

Nobody used this IC before or has an idea what could be wrong? I have really no idea because it is the same chip as the SC16IS750, only with two UART ports channel A and channel B. Normally it should work, should not it?
I have looked over the library, but have not found a mistake. Also the registers seems to be correct (same as on the SC16IS750).

I will use now three SC16IS740. They should work the same as the 750. The 752 with two UART's do not work and I do not see the mistake in my code.
But the other way, if I use three 740 or two 752, the size of the PCB I will need is nearly the same. The coding with the 740 or 750 IC's are better, because I can give each IC a specific name for the UART. The 752 needs channel A and channel B what is not that easy to write the code and needs more to define the UART's.
I think it is really not bad to use the single UART IC's 740 or 750. For me it is the better choice now.

But anyway, if someone could get the 752 working and find the mistake in my code, please write me. I am very interested in this why it is not working... :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.