Thanks for the replys. I'm currently using the 16 byte fifo buffer but its slow to read the 16 byte buffer using the getc() function. I was also trying to avoid using interrupts as they disrupt the rest of my code.
OK, to start with, getc() itself really isn't slow. What's slow is the fact that it's waiting for a character to arrive before the function returns. This is exactly what interrupts are designed to avoid. Trust me, interrupts are not going to disrupt the rest of your code unless you design it wrong. Functions liek getc() are called "blocking" functions. They basically hang your system until some condition is met.
I just knocked up a sample piece of code to show you how to collect 16bytes into a buffer using a simple ISR (interrupt service routine). I haven't actually tried this for real but it's based on other working code I have. See the way the main while(1) loop continues to operate until the buffer has 16bytes in it? It's just one way of doing it, there's plenty of variations you can make but you'll need to think slightly different when programming for the embedded enviroment unless you use something like a RTOS (real time operating system). Without an OS you pretty much have to do everything yourself.
The Mbed libraries for the most part relieve you of many burdens but they the Mbed libraries are a framework, not an OS. Learning to work with them, extend them or use homebrew code is the key.
Remember, this is just a very simple example, a starting point.
#include "mbed.h"
DigitalOut myled(LED1);
Serial mycomms(NC, p25); // Uart1
char rx_buffer[16];
int rx_buffer_in = 0;
int handle_buffer = 0;
int main() {
mycomms.baud(9600);
LPC_UART1->IER = 0x01; // enable Uart1 RX interrupts.
while(1) {
// Each time around the loop test to see if we have
// read 16bytes into our buffer.
if (handle_buffer) {
handle_buffer = 0;
// do something with the buffer.
LPC_UART1->IER = 0x1; // Re-enable interrupts to get another 16bytes.
}
// The rest of your project code goes here....
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}
extern "C" void UART1_IRQHandler(void) __irq {
volatile uint32_t iir;
iir = LPC_UART1->IIR;
if (iir & 0x1) return;
if (iir & 0x4) {
while (LPC_UART1->LSR & 0x1) {
rx_buffer[rx_buffer_in++] = (char)LPC_UART1->RBR;
if (rx_buffer_in == 16) { // Wrap buffer in pointer and flag ready.
rx_buffer_in = 0;
handle_buffer = 1;
LPC_UART1->IER = 0; // Disable further interrupts.
}
}
}
}
I want to send a 16byte serial message to DMA from a uart and read it once it finishes transferring. Has anyone done anything similar or know of a library I can use? Does the mbed library make use of DMA in its receiving?