Serial to SIM7020X NB-IoT HAT not working but works via USB TTL putty

I'm using Arduino Micro 3.3V and via the TX and RX i can send data via serial monitor to my USB TTL via putty. My settings are 115200, 8,1,none, none,implicit CR in every LF on putty.
When I connect my USB TTL to SIM7020X it works. Sending AT gets a reply OK etc.
When I use Arduino Micro to send serial to SIM7020X i don't get a reply.
below is the code that i used.

const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
char receivedChars1[numChars];
boolean newData = false;
boolean newData1 = false;

void setup() {
Serial.begin(115200);
Serial1.begin(115200);
}
void loop() {
recvWithEndMarker();
recvSerial1();
showNewData();
showNewData1();
}

void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;

while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();

    if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
            ndx = numChars - 1;
        }
    }
    else {
        receivedChars[ndx] = '\0'; // terminate the string
        ndx = 0;
        newData = true;
    }
}

}

void recvSerial1() {
static byte ndx1 = 0;
char endMarker1 = '\r';
char rc1;

while (Serial1.available() > 0 && newData1 == false) {
    rc1 = Serial1.read();
   Serial.println(rc1);
    if (rc1 != endMarker1) {
        receivedChars1[ndx1] = rc1;
        ndx1++;
        if (ndx1 >= numChars) {
            ndx1 = numChars - 1;
        }
    }
    else {
        receivedChars1[ndx1] = '\0'; // terminate the string
        Serial.println(ndx1);
        ndx1 = 0;
        newData1 = true;
    }
}

}

void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);

    if(receivedChars[0] == 0x41){
      Serial1.write(0x41);//A
      Serial1.write(0x54);//T
      Serial1.write(0x0D);//CR
      Serial1.write(0x0A);//LF
      
     // Serial1.println('AT');//also doesn't work. 

    }else{

      Serial1.write(receivedChars);
    }
    newData = false;
}

}
void showNewData1() {
if (newData1 == true) {
Serial.print("This from NB ... ");
Serial.println(receivedChars1);

    newData1 = false;
}

}

I've tried with an Arduino micro 5v board and its also not working. I used a multimeter to measure the RX TX of the usb ttl it's 3.3v so I assume i would need a Arduino micro 3.3v board.

Please help. I've tried about everything i know.

I used the sample code and connected the USB TTL TX to SIM7020x RX and SIM7020x TX to Arduino Micro RX and Arduino Micro TX to USB TTL RX.

Using putty i was able to send message from USB TTL to SIM7020x which replied to Micro to display on serial monitor. from Micro i can send messages to USB TTL displayed on putty. however when i change/reverse the connection, i can't send message from Micro to SIM7020x and there's no reply. Does anyone know if I need to add a '\0' or \r\n etc? Why is the sim7020x not reading the messages sent from Arduino?

void setup() {
Serial.begin(115200);
Serial1.begin(115200);
}

void loop() {
if (Serial.available()) { // If anything comes in Serial (USB),
Serial1.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1)
//Serial1.println();
}

if (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1)
Serial.write(Serial1.read()); // read it and send it out Serial (USB)
}
}

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