Hii
i am facing issues with library software serial.
according to the library, .available() function returns the number of bytes available for reading in the serial buffer. but here it is always returning 0 and breaking the loop with condition
if myserial.available() > 0{
}
Here is the test program in short for referance
actually i am transmitting some data through modbus and reading its request, so the request1[]
is the request format of data which needs to be transmitted to modbus slave
//RX
#include <SoftwareSerial.h>
const byte rxpin = 3;
const byte txpin = 2;
byte c;
byte request1[] = { 0x1, 0x4, 0x00, 0x32, 0x00, 0x2, 0xD0, 0X04 };
SoftwareSerial myserial(rxpin, txpin); //rx pin , tx pin of the device sending data
void setup() {
myserial.begin(9600);
Serial.begin(9600);
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
myserial.write(request1, sizeof(request1));
digitalWrite(7, LOW);
}
void loop() {
if (myserial.available() > 0) {
while (myserial.available() > 0) {
Serial.print("No of bytes available for reading ::>");
Serial.println(myserial.available());
c = myserial.read();
Serial.print("Value read in hex ::>");
Serial.println(c, HEX);
}
}
}
if you want to simulate the same problem, please use two arduino with software serial, programming one for sending continuous data nad with another receiving data at software serial port
well we want to trust you but it would be better for everyone if you were sharing a drawing of the circuit so that we all have a full view of the system.
are you sure it's 9600 bauds ? what about voltage ?