SIM20 On Mega2560

Hi All

Have any one of you used a SIM20 transceiver?

I would like to use it on a Mega2560 on Serilal1.

I am having problems when I send AT commands and I am not able to read the response.
When I put the SIM 20 in data mode and send data (from my PCB and Mega) I get data on the test kit but it is not the same data that I send.

Pointing me in the right direction would be really appreciated.

The schematic is attached.

Thank you

Best regards

Luan

Test kit:

int  serIn;             // var that will hold the bytes-in read from the serialBuffer
char serInString[128];  // array that will hold the different bytes  100=100characters;
                        // -> you must state how long the array will be else it won't work.
int  serInIndx  = 0;    // index of serInString[] in which to insert the next incoming byte
int  serOutIndx = 0;    // index of the outgoing serInString[] array;


const int AC2DPin = 17;  


void setup() 
{
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println("Hello World");   
  
  pinMode(AC2DPin, OUTPUT);
  digitalWrite(AC2DPin, HIGH);
  delay(500);
  digitalWrite(AC2DPin, LOW); //LOW for sending data

  delay(500);
  digitalWrite(AC2DPin, HIGH);  //High for command mode  
  
  Serial1.println("AT+SRDuart=2,0");
  Serial1.println("\r\n"); 
  
  delay(500);
  digitalWrite(AC2DPin, LOW); //LOW for sending data
  
  delay(120);
}

void loop () 
{
  //simple feedback from Arduino
  
  //read the serial port and create a string out of what you read
  //readSerialString(serInString, serInIndx);
  //Serial.println("AT+SRDSN?\r\n");
  Serial1.println("AT+SRDSN?\n");
  //Serial1.print("\r\n");
  //Serial1.print("\r");
  //Serial1.print("\r\n");
  //Serial1.print("\n");
  delay(10);
  readSerialString();
  
  //do somenthing else perhaps wait for other data or read another Serial string
  Serial.println ("------------ arduino is doing somenthing else ");
  
  //try to print out collected information. it will do it only if there actually is some info.
  printSerialString();
  
  //slows down the visualization in the terminal
  delay(2000);
}



//read a string from the serial and store it in an array
//this func uses globally set variable so it's not so reusable
//I need to find the right syntax to be able to pass to the function 2 parameters:
// the stringArray and (eventually) the index count
void readSerialString () {
    int sb;   
    if(Serial1.available()) { 
       //Serial.print("reading Serial String: ");     //optional confirmation
       while (Serial1.available()){ 
          sb = Serial1.read();             
          serInString[serInIndx] = sb;
          serInIndx++;
          //serialWrite(sb);                        //optional confirmation
       }
       //Serial.println();
    }  
}

//print the string all in one time
//this func as well uses global variables
void printSerialString() {
   if( serInIndx > 0) {
      Serial.print("Arduino memorized that you said: ");     
      //loop through all bytes in the array and print them out
      for(serOutIndx=0; serOutIndx < serInIndx; serOutIndx++) {
          Serial.print( serInString[serOutIndx] );    //print out the byte at the specified index
          //serInString[serOutIndx] = "";            //optional: flush out the content
      }        
      //reset all the functions to be able to fill the string back with content
      serOutIndx = 0;
      serInIndx  = 0;
      Serial.println();
   }

}

SIM20_sch.pdf (13.1 KB)

SIM20_AT_Command_Manual_V1.04.pdf (396 KB)

You have T1OUT on the MAX3232CPE chip connected to an RX pin on the Arduino. That really does not seem right.

You have R1IN on the MAX3232CPE chip connected to a TX pin on the Arduino. That really does not seem right.

You have T1IN on the MAX3232CPE chip connected to TX on the SIM20. That does not seem right.

You have R1OUT on the MAX3232CPE chip connected to RX on the SIM20. That does not seem right.

I would expect T1OUT to be connected to the TX pin of the Arduino.
I would expect R1IN to be connected to the RX pin of the Arduino.
I would expect T1IN to be connected to TX on the SIM20.
I would expect R1OUT to be connected to RX on the SIM20.

Draw an arrow. Data comes out of the Arduino on the TX pin, goes in to the MAX3232, out of the MAX3232 in to the SIM20.

Data comes out of the SIM20 in to the MAX3232, out of the MAX3232, in to the Arduino on the RX pin.

Hi Paul

Thank you for your reply.
I was hoping my problem is with sending the , I am using Serial1.print("\r\n");

I am sure the connections are correct, unless I don't understand the MAX323.
I also had the diagram checked by a friend who is a lecturer in Electric, Electronic and Computer Engineering.

Like you said:
Data comes out of the Arduino on the TX pin (TX1), goes in to the MAX3232 (R1 IN), out (R1 OUT) of the MAX3232 in (RXD) to the SIM20.

Data comes out (TXD) of the SIM20 in (T1 IN) to the MAX3232, out (T1 OUT) of the MAX3232, in to the Arduino on the RX (RX1) pin.

Please let me know if you have any other thoughts

Thank you

Best Regards

Luan

Hi All

I got the SIM20 working with help from my friend.
The problem was that the Max323 inverts the signals so I added another Max323 to correct the inverted signals.

Attached is my new diagram.
I hope this helps someone else in the future.

Have a great day

Regards

Luan

SIM20_sch2Max323.pdf (19.2 KB)

Hi All

See attached the new diagram with level shifting with transistors, works out cheaper than ICs.

Have a nice day

TTFN

:slight_smile:

SIM20.pdf (22.6 KB)