Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem mbed
Fork of PES4_Programme by
Diff: source/serialConnection.cpp
- Revision:
- 93:32cd0af29c2b
- Parent:
- 89:f63e4736d875
- Child:
- 94:b24d2b432b27
--- a/source/serialConnection.cpp Mon Apr 09 15:19:36 2018 +0000
+++ b/source/serialConnection.cpp Tue Apr 10 07:40:58 2018 +0000
@@ -1,9 +1,44 @@
#include "serialConnection.h"
-/*
+
+Serial pc(USBTX, USBRX);
+
+void setBaud()
+{
+ pc.baud(460800);
+}
+
+void attachSerialInterrupts()
+{
// Setup a serial interrupt function to receive data
pc.attach(&Rx_interrupt, Serial::RxIrq);
// Setup a serial interrupt function to transmit data
pc.attach(&Tx_interrupt, Serial::TxIrq);
+}
+
+// Interupt Routine to read in data from serial port
+void Rx_interrupt()
+{
+ // Loop just in case more than one character is in UART's receive FIFO buffer
+ // Stop if buffer full
+ while ((pc.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
+ rx_buffer[rx_in] = pc.getc();
+ rx_in = (rx_in + 1) % buffer_size;
+ }
+ return;
+}
+
+
+// Interupt Routine to write out data to serial port
+void Tx_interrupt()
+{
+ // Loop to fill more than one character in UART's transmit FIFO buffer
+ // Stop if buffer empty
+ while ((pc.writeable()) && (tx_in != tx_out)) {
+ pc.putc(tx_buffer[tx_out]);
+ tx_out = (tx_out + 1) % buffer_size;
+ }
+ return;
+}
// Copy tx line buffer to large tx buffer for tx interrupt routine
@@ -15,7 +50,7 @@
i = 0;
// Start Critical Section - don't interrupt while changing global buffer variables
- NVIC_DisableIRQ(UART1_IRQn);
+ NVIC_DisableIRQ(USB0_IRQn);
empty = (tx_in == tx_out);
while ((i==0) || (tx_line[i-1] != '\n')) {
// Wait if buffer full
@@ -35,7 +70,7 @@
temp_char = tx_buffer[tx_out];
tx_out = (tx_out + 1) % buffer_size;
// Send first character to start tx interrupts, if stopped
- device.putc(temp_char);
+ pc.putc(temp_char);
}
// End Critical Section
NVIC_EnableIRQ(UART1_IRQn);
@@ -70,29 +105,3 @@
rx_line[i-1] = 0;
return;
}
-
-
-// Interupt Routine to read in data from serial port
-void Rx_interrupt()
-{
- // Loop just in case more than one character is in UART's receive FIFO buffer
- // Stop if buffer full
- while ((device.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
- rx_buffer[rx_in] = device.getc();
- rx_in = (rx_in + 1) % buffer_size;
- }
- return;
-}
-
-
-// Interupt Routine to write out data to serial port
-void Tx_interrupt()
-{
- // Loop to fill more than one character in UART's transmit FIFO buffer
- // Stop if buffer empty
- while ((device.writeable()) && (tx_in != tx_out)) {
- device.putc(tx_buffer[tx_out]);
- tx_out = (tx_out + 1) % buffer_size;
- }
- return;
-}*/
\ No newline at end of file
