I was hoping to run something past you guys and get some guidance hopefully. Im trying to create a seperate project to extract data from a standalone engine management system, and as part of that I need to connect to the ECU using RS232.
So before I jump into connecting to the ECU, I wanted to build a simple test to ensure I understand what Im doing first.
I found a simple loopback test on another forum topic which said if I connect up the board as follows bridging the txt and rx pins on the 9 pin connector:
#include<SoftwareSerial.h>
SoftwareSerial SUART(6, 7);
void setup()
{
Serial.begin(9600);
SUART.begin(9600);
}
void loop()
{
SUART.print('A'); //sending A using SUART port
byte n = SUART.available();
if(n != 0)
{
char x = SUART.read();
Serial.println(x);
}
delay(1000);
}
That I should see the sent character 'A' as a response in the serial monitor, which seemed logical to me. I have this configured, and now once a second I see the TX led on the Arduino flash, and at the same time I see the tx and rx led on the R232 unit flash... but I get nothing in the serial monitor.
If I remove the bridge from the 9 pin connector, sure enough I now only see the tx led on the R232 unit flash which again makes sense. So everything appears to be ok.. but I get nothing back in the serial monitor.
Would anyone be able to suggest why I might be getting these results?
Thank you for the response, but Im afraid I dont follow. What I want to understand at the minute is if I have some sort of hw issue, that is going to hinder my results when I start to connect to the ECU.
The ECU works on req/resp' so if dont get anything back from the ECU, it could be either a malformed request being sent, or a physical issue. So I want to rule out a physical issue first, so I can be sure if the ECU isnt sending anything, its down to my request and nothing else.
So at the minute I would really like to undertsand why the above does not do what I expect it to (transmit 'A', and receive and print 'A' in the serial monitor).
try the following using AltSoftSerial using pins 8 and 9 of a UNO
// SIM800l AltSoftSerial test
#include <AltSoftSerial.h>
#include <SPI.h>
#include <Wire.h>
// Mega SIM800l test
//SIM800L 5V POWER to Mega 5V
//SIM800L GND POWER to Mega GND
//SIM800L TXD to Mega RX pin 48
//SIM800L RXD to Mega TX pin 46
//SIM800L VDD to Mega 5V
//SIM800L UART TTL GND and RST not connected
//SIM800L TXD to UNO RX pin 8
//SIM800L RXD to UNO TX pin 9
AltSoftSerial simSerial;
void setup() {
Serial.begin(115200);
Serial.println("AltSoftSerial test");
//Begin serial communication with Arduino and SIM800L
simSerial.begin(9600);
Serial.println("SIM module intialized");
}
void loop() {
if (Serial.available()) {
char command = Serial.read();
//Serial.println(command);
simSerial.print(command);
}
while (simSerial.available()) {
char reponse = simSerial.read();
Serial.print(reponse);
}
}
jumper pins 8 and 9 to give a local looopback test on UNO
connect RS232 shield to pins 8 and 9
jumper pins 2 and 3 to give a RS232 loopback test
Edit: just connected a RS232 shield
RS232 TXD to UNO pin 9
RS232 RXD to UNO pin 8
jumper 9pin Dtype pins 2 and 3 give loopback test OK
Thanks for the response, I have tried the above and regardless of whether pins 8 and 9 on the Uno are bridged, or 2 and 3 on the rs232 connector, I get nothing in the serial monitor other than "AltSoftSerial test" and "SIM module initialized" obviously.
Thanks again for the response, that was my mistake - something had froze somewhere, I reloaded the code and relaunched the serial monitor and I can confirm now, that when shorting pins 8 and 9 I am receiving back what I send out which is great!
Out of interest though, do you see a reason why the first code snippet does not behave as predicted?
Ahh, ok that makes sense! Thank you all for your responses, that makes sense. I have now used AltSoftSerial in the original code snippet and it works fine, so at least I know I can send and receive data successfully.