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: buffered-serial1 mbed-rtos mbed
Fork of Serial_interrupts by
Diff: buffered_serial.cpp
- Revision:
- 2:3d959c9fc9d7
- Parent:
- 1:2f1e54d137c7
- Child:
- 5:52705b8ccb32
--- a/buffered_serial.cpp Mon Dec 10 00:32:22 2012 +0000
+++ b/buffered_serial.cpp Mon Dec 10 22:33:57 2012 +0000
@@ -1,6 +1,6 @@
#include "buffered_serial.h"
-BufferedSerial::BufferedSerial(PinName tx, PinName rx) : Serial(tx,rx)
+BufferedSerial::BufferedSerial(PinName tx, PinName rx) : Serial(tx,rx), led1(LED1), led2(LED2)
{
tx_in=0;
tx_out=0;
@@ -21,7 +21,7 @@
device_irqn = UART3_IRQn;
break;
}
- //device_irqn = UART1_IRQn;
+
// attach the interrupts
Serial::attach(this, &BufferedSerial::Rx_interrupt, Serial::RxIrq);
Serial::attach(this, &BufferedSerial::Tx_interrupt, Serial::TxIrq);
@@ -56,7 +56,8 @@
temp_char = tx_buffer[tx_out];
tx_out = (tx_out + 1) & BUFFER_SIZE;
// Send first character to start tx interrupts, if stopped
- Serial::putc(temp_char);
+ //Serial::putc(temp_char);
+ LPC_UART1->THR = temp_char;
}
// End Critical Section
NVIC_EnableIRQ(device_irqn);
@@ -95,29 +96,33 @@
// Interupt Routine to read in data from serial port
void BufferedSerial::Rx_interrupt()
{
- //led1=1;
+ //uint32_t RBR = LPC_UART1->RBR;
+ uint32_t IRR1 = LPC_UART1->IIR;
+ led1=1;
// Loop just in case more than one character is in UART's receive FIFO buffer
// Stop if buffer full
- while ((Serial::readable()) || (((rx_in + 1) & BUFFER_SIZE) == rx_out)) {
- rx_buffer[rx_in] = Serial::getc();
-// Uncomment to Echo to USB serial to watch data flow
-// monitor_Serial::putc(rx_buffer[rx_in]);
+ while ((readable()) || (((rx_in + 1) & BUFFER_SIZE) == rx_out)) {
+ rx_buffer[rx_in] = LPC_UART1->RBR;
+ //rx_buffer[rx_in] = Serial::getc();
rx_in = (rx_in + 1) & BUFFER_SIZE;
}
- //led1=0;
+ led1=0;
return;
}
// Interupt Routine to write out data to serial port
void BufferedSerial::Tx_interrupt()
{
- //led2=1;
+ //uint32_t RBR = LPC_UART1->RBR;
+ uint32_t IRR = LPC_UART1->IIR;
+ led2=1;
// Loop to fill more than one character in UART's transmit FIFO buffer
// Stop if buffer empty
- while ((Serial::writeable()) && (tx_in != tx_out)) {
- Serial::putc(tx_buffer[tx_out]);
+ while ((writeable()) && (tx_in != tx_out)) { // while serial is writeable and there are still characters in the buffer
+ //Serial::putc(tx_buffer[tx_out]);
+ LPC_UART1->THR = tx_buffer[tx_out]; // send the character
tx_out = (tx_out + 1) & BUFFER_SIZE;
}
- //led2=0;
+ led2=0;
return;
}
\ No newline at end of file
