1

I have a very simple piece of code for Arduino Uno. Using SoftwareSerial lib.

#include <SoftwareSerial.h>
#define rxPin 6
#define txPin 7
SoftwareSerial mySerial(rxPin, txPin);

void setup() {
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  Serial.begin(9600);
  mySerial.begin(2400);
  Serial.println("Serial init");          
}

void loop() {
  delay(2000);
  Serial.println("Serial link started");

  mySerial.write(0x15);

  if(mySerial.available() ){
    int incomingByte = mySerial.read();
    Serial.print(incomingByte);
    Serial.print(" is here");   
  }
}

rxPin and txPin are connected directly to each other. Arduino is also connected to PC throught USB. I have no respone from mySerial.available() loop, mySerial.read() returns -1. Does anyone know, where could be the problem? SoftwareSerial doesnt work for me.

RanL
  • 139
  • 9

2 Answers2

1

The method SoftwareSerial::write() disables interrupts while writing, at this line. So when you are writing out your byte the arduino is deaf to the incoming bits (except maybe for the first rising edge, that maybe will be delayed until when interrupts are enabled again - I don't actually remember).

Alfonso Nishikawa
  • 1,876
  • 1
  • 17
  • 33
1

I guess MySerial (6-7) points to a modem (Sim900 or Sim300), and serial (0-1) of the ARDUINO ONE points to the USB port of the PC.

Configure your modem with jumpers so you can listen for ports 6-7

Try this:

IssueCommand ( "AT"); // or mySerial.println("AT+V") 
   ReadSerial ();

Void readSerial () {
   While (mySerial.available ()) {
     Serial.write (mySerial.read ());
     Delay (10);
   }
}

Excusme I am Live in Mexico mbnava@gmail.com to contact me. feel Free

mbnava
  • 11
  • 1