Skip to content

Commit 365d1cb

Browse files
authored
Merge pull request #48 from sparkfun/SoftwareSerial
Software serial
2 parents 248be65 + caf4700 commit 365d1cb

File tree

13 files changed

+1213
-1
lines changed

13 files changed

+1213
-1
lines changed

cores/arduino/ard_sup/ap3_clock_sources.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ SOFTWARE.
2626

2727
bool enableBurstMode();
2828
bool disableBurstMode();
29+
uint32_t getCpuFreqMHz();
2930

3031
#endif //_AP3_GPIO_H_

cores/arduino/ard_sup/clock/ap3_clock_sources.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "ap3_clock_sources.h"
22

3+
uint32_t cpuFreq = 48000000; //At POR core is 48MHz
4+
35
//Turns main processor from 48MHz to 96MHz
46
//Returns false if burst mode failed to enable
57
bool enableBurstMode(void)
@@ -17,6 +19,7 @@ bool enableBurstMode(void)
1719
{
1820
return (false);
1921
}
22+
cpuFreq = 96000000;
2023
return (true);
2124
}
2225

@@ -36,5 +39,12 @@ bool disableBurstMode(void)
3639
{
3740
return (false);
3841
}
42+
cpuFreq = 48000000;
3943
return (true);
4044
}
45+
46+
//Returns the current core speed
47+
uint32_t getCpuFreqMHz(void)
48+
{
49+
return (cpuFreq);
50+
}

cores/arduino/ard_sup/gpio/ap3_gpio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ uint32_t ap3_gpio_enable_interrupts(uint32_t ui32Pin, uint32_t eIntDir)
305305
uint32_t ui32GPCfgClearMask;
306306
uint32_t ui32GPCfgShft;
307307

308-
ui32GPCfgShft = ((ui32Pin & 0x7) << 2);
308+
ui32GPCfgShft = ((ui32Pin & 0x7) << 2);
309309

310310
ui32GPCfgAddr = AM_REGADDR(GPIO, CFGA) + ((ui32Pin >> 1) & ~0x3);
311311

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Author: Nathan Seidle
3+
SparkFun Electronics
4+
Created: June 19 2019
5+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
6+
7+
Feel like supporting open source hardware? Buy a board from SparkFun!
8+
https://www.sparkfun.com/artemis
9+
10+
This example shows how to send characters at 9600bps. Any pin can be used for
11+
TX or RX.
12+
13+
Note: In this SoftwareSerial library you cannot TX and RX at the same time.
14+
TX gets priority. So if Artemis is receiving a string of characters
15+
and you do a Serial.print() the print will begin immediately and any additional
16+
RX characters will be lost.
17+
18+
Hardware Connections:
19+
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
20+
Connect
21+
GND on SerialBasic <-> GND on Artemis
22+
RXO on SerialBasic <-> Pin 8 on Artemis
23+
Load this code
24+
Open Arduino serial monitor at 57600
25+
Open Terminal window (TeraTerm) at 9600
26+
*/
27+
28+
#include <SoftwareSerial.h>
29+
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used
30+
31+
int counter = 0;
32+
33+
void setup() {
34+
//We set the serial monitor speed high so that we spend less time printing the output
35+
Serial.begin(57600);
36+
Serial.println("Software Serial Example");
37+
38+
mySerial.begin(9600);
39+
}
40+
41+
void loop() {
42+
43+
mySerial.print("Hello world: ");
44+
mySerial.println(counter++);
45+
46+
delay(20); //Small delay because it takes time to send chars at 9600bps
47+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Author: Nathan Seidle
3+
SparkFun Electronics
4+
Created: June 19 2019
5+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
6+
7+
Feel like supporting open source hardware? Buy a board from SparkFun!
8+
https://www.sparkfun.com/artemis
9+
10+
This example shows how to send characters at 9600bps. Any pin can be used for
11+
TX or RX.
12+
13+
Note: In this SoftwareSerial library you cannot TX and RX at the same time.
14+
TX gets priority. So if Artemis is receiving a string of characters
15+
and you do a Serial.print() the print will begin immediately and any additional
16+
RX characters will be lost.
17+
18+
Hardware Connections:
19+
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
20+
Connect
21+
GND on SerialBasic <-> GND on Artemis
22+
RXO on SerialBasic <-> Pin 8 on Artemis
23+
TXO on SerialBasic <-> Pin 7 on Artemis
24+
Load this code
25+
Open Arduino serial monitor at 57600
26+
Open Terminal window (TeraTerm) at 9600
27+
Press a button in terminal window, you should see it in Arduino monitor
28+
*/
29+
30+
#include <SoftwareSerial.h>
31+
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used
32+
33+
int counter = 0;
34+
35+
void setup() {
36+
//We set the serial monitor speed high so that we spend less time printing the output
37+
//and more time checking mySerial.available()
38+
Serial.begin(57600);
39+
Serial.println("Software Serial Example");
40+
41+
mySerial.begin(9600);
42+
}
43+
44+
void loop() {
45+
46+
mySerial.print("Hi: ");
47+
mySerial.println(counter++);
48+
49+
while (mySerial.available())
50+
{
51+
byte incoming = mySerial.read();
52+
Serial.write(incoming);
53+
}
54+
55+
delay(100); //Small delay between prints so that we can detect incoming chars if any
56+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Author: Nathan Seidle
3+
SparkFun Electronics
4+
Created: June 19 2019
5+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
6+
7+
Feel like supporting open source hardware? Buy a board from SparkFun!
8+
https://www.sparkfun.com/artemis
9+
10+
This example shows how to send characters at 57600bps. It's counter intuitive
11+
but by printing faster and receiving faster we can do more with interrupt
12+
based software serial.
13+
Any pin can be used for TX or RX.
14+
15+
Hardware Connections:
16+
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
17+
Connect
18+
GND on SerialBasic <-> GND on Artemis
19+
RXO on SerialBasic <-> Pin 8 on Artemis
20+
TXO on SerialBasic <-> Pin 7 on Artemis
21+
Load this code
22+
Open Arduino serial monitor at 115200
23+
Open Terminal window (TeraTerm) at 57600
24+
Press a button in terminal window, you should see it in Arduino monitor
25+
*/
26+
27+
#include <SoftwareSerial.h>
28+
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used
29+
30+
int counter = 0;
31+
32+
void setup() {
33+
//We set the serial monitor speed high so that we spend less time printing the output
34+
//and more time checking mySerial.available()
35+
Serial.begin(115200);
36+
Serial.println("Software Serial Example");
37+
38+
mySerial.begin(57600);
39+
}
40+
41+
void loop() {
42+
43+
mySerial.print("Hi: ");
44+
mySerial.println(counter++);
45+
46+
while (mySerial.available())
47+
{
48+
byte incoming = mySerial.read();
49+
Serial.write(incoming);
50+
}
51+
52+
delay(25); //Small delay between prints so that we can detect incoming chars if any
53+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Author: Nathan Seidle
3+
SparkFun Electronics
4+
Created: June 19 2019
5+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
6+
7+
Feel like supporting open source hardware? Buy a board from SparkFun!
8+
https://www.sparkfun.com/artemis
9+
10+
This example shows how to enable multiple software serial ports at 57600bps.
11+
You can only receive on one pin at a time. Use .listen() to switch between
12+
RX pins.
13+
14+
Note: When multiple ports are enabled receiving at 115200bps is no longer
15+
possible. This is because the receive interrupt has additional overhead
16+
and cannot run fast enough to correctly capture bits in time. TX at 115200
17+
is still supported.
18+
19+
Hardware Connections:
20+
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
21+
Connect
22+
GND on SerialBasic <-> GND on Artemis
23+
RXO on SerialBasic <-> Pin 8 on Artemis
24+
TXO on SerialBasic <-> Pin 7 on Artemis
25+
Load this code
26+
Open Arduino serial monitor at 115200
27+
Open Terminal window (TeraTerm) at 57600
28+
Press a button in terminal window, you should see it in Arduino monitor
29+
*/
30+
31+
#include <SoftwareSerial.h>
32+
SoftwareSerial mySerialA(7, 8); //RX, TX - Any pins can be used
33+
SoftwareSerial mySerialB(2, 3); //RX, TX - Any pins can be used
34+
35+
int counter = 0;
36+
37+
void setup() {
38+
//We set the serial monitor speed high so that we spend less time printing the output
39+
Serial.begin(115200);
40+
Serial.println("Software Serial Example");
41+
42+
mySerialA.begin(57600);
43+
mySerialB.begin(9600);
44+
45+
//We are now using mySerialB because it was the last one to begin. Use .listen() to change ports.
46+
}
47+
48+
void loop() {
49+
mySerialA.listen();
50+
mySerialA.print("I'm A: ");
51+
mySerialA.println(counter);
52+
mySerialA.flush(); //Wait for TX buffer to get sent out
53+
54+
mySerialB.listen();
55+
mySerialB.print("I'm B: ");
56+
mySerialB.println(counter);
57+
mySerialB.flush();
58+
59+
counter++;
60+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Author: Nathan Seidle
3+
SparkFun Electronics
4+
Created: June 19 2019
5+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
6+
7+
Feel like supporting open source hardware? Buy a board from SparkFun!
8+
https://www.sparkfun.com/artemis
9+
10+
This example shows how to enable burst mode. Although Artemis is running at
11+
96MHz, software serial operates the same way.
12+
13+
Hardware Connections:
14+
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
15+
Connect
16+
GND on SerialBasic <-> GND on Artemis
17+
RXO on SerialBasic <-> Pin 8 on Artemis
18+
TXO on SerialBasic <-> Pin 7 on Artemis
19+
Load this code
20+
Open Arduino serial monitor at 57600
21+
Open Terminal window (TeraTerm) at 57600
22+
Press a button in terminal window, you should see it in Arduino monitor
23+
*/
24+
25+
#include <SoftwareSerial.h>
26+
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used
27+
28+
int counter = 0;
29+
30+
void setup() {
31+
//We set the serial monitor speed high so that we spend less time printing the output
32+
//and more time checking mySerial.available()
33+
Serial.begin(57600);
34+
Serial.println("Software Serial Example");
35+
36+
enableBurstMode(); //Go to 96MHz
37+
38+
mySerial.begin(57600);
39+
}
40+
41+
void loop() {
42+
43+
mySerial.print("Hi: ");
44+
mySerial.println(counter++);
45+
46+
while (mySerial.available())
47+
{
48+
byte incoming = mySerial.read();
49+
Serial.write(incoming);
50+
}
51+
52+
delay(100); //Small delay between prints so that we can detect incoming chars if any
53+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Author: Nathan Seidle
3+
SparkFun Electronics
4+
Created: June 19 2019
5+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
6+
7+
Feel like supporting open source hardware? Buy a board from SparkFun!
8+
https://www.sparkfun.com/artemis
9+
10+
This example shows how to use different data, parity, and stop bits.
11+
See Arduino reference for all settings: https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/
12+
13+
Hardware Connections:
14+
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
15+
Connect
16+
GND on SerialBasic <-> GND on Artemis
17+
RXO on SerialBasic <-> Pin 8 on Artemis
18+
TXO on SerialBasic <-> Pin 7 on Artemis
19+
Load this code
20+
Open Arduino serial monitor at 57600
21+
Open Terminal window (TeraTerm) at 9600 with special settings *8 bits, even parity, 2 stop!*
22+
Press a button in terminal window, you should see it in Arduino monitor
23+
*/
24+
25+
#include <SoftwareSerial.h>
26+
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used
27+
28+
int counter = 0;
29+
30+
void setup() {
31+
//We set the serial monitor speed high so that we spend less time printing the output
32+
//and more time checking mySerial.available()
33+
Serial.begin(57600);
34+
Serial.println("Software Serial Example");
35+
36+
mySerial.begin(57600, SERIAL_8E2); //Use 8 data bits, even parity, and 2 stop bits
37+
}
38+
39+
void loop() {
40+
41+
mySerial.print("Hi: ");
42+
mySerial.println(counter++);
43+
44+
while (mySerial.available())
45+
{
46+
byte incoming = mySerial.read();
47+
Serial.write(incoming);
48+
}
49+
50+
delay(100); //Small delay between prints so that we can detect incoming chars if any
51+
}

0 commit comments

Comments
 (0)