Skip to content

Software serial #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/arduino/ard_sup/ap3_clock_sources.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ SOFTWARE.

bool enableBurstMode();
bool disableBurstMode();
uint32_t getCpuFreqMHz();

#endif //_AP3_GPIO_H_
10 changes: 10 additions & 0 deletions cores/arduino/ard_sup/clock/ap3_clock_sources.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ap3_clock_sources.h"

uint32_t cpuFreq = 48000000; //At POR core is 48MHz

//Turns main processor from 48MHz to 96MHz
//Returns false if burst mode failed to enable
bool enableBurstMode(void)
Expand All @@ -17,6 +19,7 @@ bool enableBurstMode(void)
{
return (false);
}
cpuFreq = 96000000;
return (true);
}

Expand All @@ -36,5 +39,12 @@ bool disableBurstMode(void)
{
return (false);
}
cpuFreq = 48000000;
return (true);
}

//Returns the current core speed
uint32_t getCpuFreqMHz(void)
{
return (cpuFreq);
}
2 changes: 1 addition & 1 deletion cores/arduino/ard_sup/gpio/ap3_gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ uint32_t ap3_gpio_enable_interrupts(uint32_t ui32Pin, uint32_t eIntDir)
uint32_t ui32GPCfgClearMask;
uint32_t ui32GPCfgShft;

ui32GPCfgShft = ((ui32Pin & 0x7) << 2);
ui32GPCfgShft = ((ui32Pin & 0x7) << 2);

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

Expand Down
47 changes: 47 additions & 0 deletions libraries/SoftwareSerial/examples/Example1_TX/Example1_TX.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Author: Nathan Seidle
SparkFun Electronics
Created: June 19 2019
License: MIT. See SparkFun Arduino Apollo3 Project for more information

Feel like supporting open source hardware? Buy a board from SparkFun!
https://www.sparkfun.com/artemis

This example shows how to send characters at 9600bps. Any pin can be used for
TX or RX.

Note: In this SoftwareSerial library you cannot TX and RX at the same time.
TX gets priority. So if Artemis is receiving a string of characters
and you do a Serial.print() the print will begin immediately and any additional
RX characters will be lost.

Hardware Connections:
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
Connect
GND on SerialBasic <-> GND on Artemis
RXO on SerialBasic <-> Pin 8 on Artemis
Load this code
Open Arduino serial monitor at 57600
Open Terminal window (TeraTerm) at 9600
*/

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used

int counter = 0;

void setup() {
//We set the serial monitor speed high so that we spend less time printing the output
Serial.begin(57600);
Serial.println("Software Serial Example");

mySerial.begin(9600);
}

void loop() {

mySerial.print("Hello world: ");
mySerial.println(counter++);

delay(20); //Small delay because it takes time to send chars at 9600bps
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Author: Nathan Seidle
SparkFun Electronics
Created: June 19 2019
License: MIT. See SparkFun Arduino Apollo3 Project for more information

Feel like supporting open source hardware? Buy a board from SparkFun!
https://www.sparkfun.com/artemis

This example shows how to send characters at 9600bps. Any pin can be used for
TX or RX.

Note: In this SoftwareSerial library you cannot TX and RX at the same time.
TX gets priority. So if Artemis is receiving a string of characters
and you do a Serial.print() the print will begin immediately and any additional
RX characters will be lost.

Hardware Connections:
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
Connect
GND on SerialBasic <-> GND on Artemis
RXO on SerialBasic <-> Pin 8 on Artemis
TXO on SerialBasic <-> Pin 7 on Artemis
Load this code
Open Arduino serial monitor at 57600
Open Terminal window (TeraTerm) at 9600
Press a button in terminal window, you should see it in Arduino monitor
*/

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used

int counter = 0;

void setup() {
//We set the serial monitor speed high so that we spend less time printing the output
//and more time checking mySerial.available()
Serial.begin(57600);
Serial.println("Software Serial Example");

mySerial.begin(9600);
}

void loop() {

mySerial.print("Hi: ");
mySerial.println(counter++);

while (mySerial.available())
{
byte incoming = mySerial.read();
Serial.write(incoming);
}

delay(100); //Small delay between prints so that we can detect incoming chars if any
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Author: Nathan Seidle
SparkFun Electronics
Created: June 19 2019
License: MIT. See SparkFun Arduino Apollo3 Project for more information

Feel like supporting open source hardware? Buy a board from SparkFun!
https://www.sparkfun.com/artemis

This example shows how to send characters at 57600bps. It's counter intuitive
but by printing faster and receiving faster we can do more with interrupt
based software serial.
Any pin can be used for TX or RX.

Hardware Connections:
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
Connect
GND on SerialBasic <-> GND on Artemis
RXO on SerialBasic <-> Pin 8 on Artemis
TXO on SerialBasic <-> Pin 7 on Artemis
Load this code
Open Arduino serial monitor at 115200
Open Terminal window (TeraTerm) at 57600
Press a button in terminal window, you should see it in Arduino monitor
*/

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used

int counter = 0;

void setup() {
//We set the serial monitor speed high so that we spend less time printing the output
//and more time checking mySerial.available()
Serial.begin(115200);
Serial.println("Software Serial Example");

mySerial.begin(57600);
}

void loop() {

mySerial.print("Hi: ");
mySerial.println(counter++);

while (mySerial.available())
{
byte incoming = mySerial.read();
Serial.write(incoming);
}

delay(25); //Small delay between prints so that we can detect incoming chars if any
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Author: Nathan Seidle
SparkFun Electronics
Created: June 19 2019
License: MIT. See SparkFun Arduino Apollo3 Project for more information

Feel like supporting open source hardware? Buy a board from SparkFun!
https://www.sparkfun.com/artemis

This example shows how to enable multiple software serial ports at 57600bps.
You can only receive on one pin at a time. Use .listen() to switch between
RX pins.

Note: When multiple ports are enabled receiving at 115200bps is no longer
possible. This is because the receive interrupt has additional overhead
and cannot run fast enough to correctly capture bits in time. TX at 115200
is still supported.

Hardware Connections:
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
Connect
GND on SerialBasic <-> GND on Artemis
RXO on SerialBasic <-> Pin 8 on Artemis
TXO on SerialBasic <-> Pin 7 on Artemis
Load this code
Open Arduino serial monitor at 115200
Open Terminal window (TeraTerm) at 57600
Press a button in terminal window, you should see it in Arduino monitor
*/

#include <SoftwareSerial.h>
SoftwareSerial mySerialA(7, 8); //RX, TX - Any pins can be used
SoftwareSerial mySerialB(2, 3); //RX, TX - Any pins can be used

int counter = 0;

void setup() {
//We set the serial monitor speed high so that we spend less time printing the output
Serial.begin(115200);
Serial.println("Software Serial Example");

mySerialA.begin(57600);
mySerialB.begin(9600);

//We are now using mySerialB because it was the last one to begin. Use .listen() to change ports.
}

void loop() {
mySerialA.listen();
mySerialA.print("I'm A: ");
mySerialA.println(counter);
mySerialA.flush(); //Wait for TX buffer to get sent out

mySerialB.listen();
mySerialB.print("I'm B: ");
mySerialB.println(counter);
mySerialB.flush();

counter++;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Author: Nathan Seidle
SparkFun Electronics
Created: June 19 2019
License: MIT. See SparkFun Arduino Apollo3 Project for more information

Feel like supporting open source hardware? Buy a board from SparkFun!
https://www.sparkfun.com/artemis

This example shows how to enable burst mode. Although Artemis is running at
96MHz, software serial operates the same way.

Hardware Connections:
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
Connect
GND on SerialBasic <-> GND on Artemis
RXO on SerialBasic <-> Pin 8 on Artemis
TXO on SerialBasic <-> Pin 7 on Artemis
Load this code
Open Arduino serial monitor at 57600
Open Terminal window (TeraTerm) at 57600
Press a button in terminal window, you should see it in Arduino monitor
*/

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used

int counter = 0;

void setup() {
//We set the serial monitor speed high so that we spend less time printing the output
//and more time checking mySerial.available()
Serial.begin(57600);
Serial.println("Software Serial Example");

enableBurstMode(); //Go to 96MHz

mySerial.begin(57600);
}

void loop() {

mySerial.print("Hi: ");
mySerial.println(counter++);

while (mySerial.available())
{
byte incoming = mySerial.read();
Serial.write(incoming);
}

delay(100); //Small delay between prints so that we can detect incoming chars if any
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Author: Nathan Seidle
SparkFun Electronics
Created: June 19 2019
License: MIT. See SparkFun Arduino Apollo3 Project for more information

Feel like supporting open source hardware? Buy a board from SparkFun!
https://www.sparkfun.com/artemis

This example shows how to use different data, parity, and stop bits.
See Arduino reference for all settings: https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/

Hardware Connections:
Attach a USB to serial converter (https://www.sparkfun.com/products/15096)
Connect
GND on SerialBasic <-> GND on Artemis
RXO on SerialBasic <-> Pin 8 on Artemis
TXO on SerialBasic <-> Pin 7 on Artemis
Load this code
Open Arduino serial monitor at 57600
Open Terminal window (TeraTerm) at 9600 with special settings *8 bits, even parity, 2 stop!*
Press a button in terminal window, you should see it in Arduino monitor
*/

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); //RX, TX - Any pins can be used

int counter = 0;

void setup() {
//We set the serial monitor speed high so that we spend less time printing the output
//and more time checking mySerial.available()
Serial.begin(57600);
Serial.println("Software Serial Example");

mySerial.begin(57600, SERIAL_8E2); //Use 8 data bits, even parity, and 2 stop bits
}

void loop() {

mySerial.print("Hi: ");
mySerial.println(counter++);

while (mySerial.available())
{
byte incoming = mySerial.read();
Serial.write(incoming);
}

delay(100); //Small delay between prints so that we can detect incoming chars if any
}
Loading