-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTM32_TestCall.ino
60 lines (46 loc) · 2.02 KB
/
STM32_TestCall.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Pin Definitions
#define POWER_KEY_PIN PA8 // Power key for the GSM module
// Create HardwareSerial for STM32 (UART2 is already set up in STM32CubeMX)
HardwareSerial sim800Serial(2); // Using UART2
// Phone number to dial
String phoneNumber = "+1234567890";
void setup() {
// Start Serial communication for debugging (for USB port)
Serial.begin(9600); // Communication with STM32 USB serial monitor
sim800Serial.begin(9600); // Communication with SIM800C module via UART2
// Power on GSM module
pinMode(POWER_KEY_PIN, OUTPUT);
digitalWrite(POWER_KEY_PIN, HIGH); // Set HIGH to power on the GSM module
delay(3000); // Hold HIGH for 3 seconds
digitalWrite(POWER_KEY_PIN, LOW); // Set LOW to power it on
// Allow time for SIM800C to initialize
delay(5000); // Wait for GSM module to power up and initialize
// Send a simple AT command to check if the GSM module is responsive
sendATCommand("AT", 1000); // Send AT command to check for response
// Make a call to the specified phone number
makeCall(phoneNumber);
}
void loop() {
// Nothing needs to be done in the loop for this example
}
// Function to send AT command and check for response
void sendATCommand(String command, unsigned long timeout) {
Serial.print("Sending: ");
Serial.println(command);
sim800Serial.println(command);
unsigned long startMillis = millis();
while (millis() - startMillis < timeout) {
if (sim800Serial.available()) {
char c = sim800Serial.read();
Serial.write(c); // Print response from GSM module to serial monitor
}
}
}
// Function to make a call using the GSM module
void makeCall(String number) {
String command = "ATD" + number + ";"; // ATD is the AT command for dialing a number
sendATCommand(command, 5000); // Dial the phone number
Serial.println("Call initiated to: " + number);
// Wait a bit before returning to ensure the call has been attempted
delay(10000); // Wait for the call to be connected or the timeout period
}