Serial - Interrupt if RXC0 is changed

Hello together,

I try to send a Data-File containing Data Like: “11110000111000110010101011100011…” (PDM-Data) with C++ to my Arduino and intermediately push the Data to Pin2 to send it to an KLZ25-Board.

My Question is if and how its possible to interrupt if RXC0 (RX Complete) has changed so that I can push the Data to a output pin on the Arduino. I must use an interrupt because the loop is to slow and I need the Data send with over 500 Khz in the best case with 1Mhz.

I have already wrote an C++ program and a Arduino program which toggles an output pin but I get only 100Khz with this method.

Here is the C++ Code:

int main() {
/* Open File Descriptor */
   int USB = open("/dev/ttyACM1", O_RDWR | O_NONBLOCK | O_NDELAY);

/* Error Handling */
   if (USB < 0) {
       cout << "Error " << errno << " opening " << "/dev/ttyACM1" << ": " << strerror(errno) << endl;
   }

/* *** Configure Port *** */
   struct termios tty;
   memset(&tty, 0, sizeof tty);

/* Error Handling */
   if (tcgetattr(USB, &tty) != 0) {
       cout << "Error " << errno << " from tcgetattr: " << strerror(errno) << endl;
   }

/* Set Baud Rate */
   cfsetospeed(&tty, B921600);
   cfsetispeed(&tty, B921600);

/* Setting other Port Stuff */
   tty.c_cflag &= ~PARENB;        // Make 8n1
   tty.c_cflag &= ~CSTOPB;
   tty.c_cflag &= ~CSIZE;
   tty.c_cflag |= CS8;
   tty.c_cflag &= ~CRTSCTS;       // no flow control
   tty.c_lflag = 0;          // no signaling chars, no echo, no canonical processing
   tty.c_oflag = 0;                  // no remapping, no delays
   tty.c_cc[VMIN] = 0;                  // read doesn't block
   tty.c_cc[VTIME] = 5;                  // 0.5 seconds read timeout

   tty.c_cflag |= CREAD | CLOCAL;     // turn on READ & ignore ctrl lines
   tty.c_iflag &= ~(IXON | IXOFF | IXANY);// turn off s/w flow ctrl
   tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw
   tty.c_oflag &= ~OPOST;              // make raw

/* Flush Port, then applies attributes */
   tcflush(USB, TCIFLUSH);

   if (tcsetattr(USB, TCSANOW, &tty) != 0) {
       cout << "Error " << errno << " from tcsetattr" << endl;
   }

/* *** WRITE *** */
   int a = 10000000;
   unsigned char cmd[] = {'1', '\r', '\0'};
   while(1){
       write(USB, cmd, sizeof(cmd) - 1);
       a--;
   }

So does anyone know a fast method to interrupt if data is recieved on the arduino ?

Thanks and greedings,
Max

FoldFence:
My Question is if and how its possible to interrupt if RXC0 (RX Complete) has changed so that I can push the Data to a output pin on the Arduino. I must use an interrupt because the loop is to slow and I need the Data send with over 500 Khz in the best case with 1Mhz.

As far as I know the UART interrupts are used by the Serial library so you can't access them unless you disable the Serial library.

But let's start at the beginning.

If the data that you mention " "11110000111000110010101011100011..." is a series of characters then the speed at which they arrive at the Arduino will be determined by the baud rate and you won't be getting 500,000 characters per second. At 500,000 baud (which works well) you will get about 50,000 characters per second.

And, even further back in the logic chain is the question what is PDM-DATA? I wonder if it would make more sense to send data at a higher level to the Arduino (so there is much less data to send) and allow the Arduino to flesh out the details.

...R

Hey R,

PDM is pulse densitiy modulated which is used for high frequency sound for example a PDM-Microphone works at 1-3MHz and I must now simulate such a microphone with .wav data from a Host-PC.

My files are normally 1-2 seconds of such data and I must loop the data through a arduino to another board which makes an Mel Frequency Cepstral Coefficients (MFCC) to calculate speech recognition features for a Neuronal Network but I stuck at sending this data in a workable speed.

So one second are equal to 1^6 data points and 1 data point is displaying 1us of a sound wave.

Here is a excerpt of a 1KHz sin wave in PDM:

100100100100100100101001001010010101001010100101010101010101001101010101010101011010101101010110110101101011011011011011011011011101101110110111011101111011101111011101111101111011111011111101111110111111110111111111011111111111011111111111111110111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111101111111111110111111111011111111011111110111110111111011110111110111101110111101110111011101110110111011011011011011011011011011010110110101011010110101010110101010101010101010101010100101010100101010010100100101001001001010010001001001001000100100010001000100010000100010000100001000001000001000000100000010000000010000000001000000000001000000000000000001000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000100000000000010000000001000000001000000100000010000010000010000100001000010001000100010001000

Greedings M

Thanks for the explanations. However you have not said if the series "10010010010010010010" is a series of characters '1' and '0', and if not, then what is it?

Is a 16MHz Arduino fast enough for this task?

...R

Have you looked into using SPI for a higher data rate?