Go Down

Topic: Arduino DUE limited baudrate  (Read 5249 times) previous topic - next topic

Tyarel

Feb 14, 2019, 05:30 pm Last Edit: Feb 14, 2019, 05:31 pm by Tyarel
Hi everyone,

I am working on a DUE board and I have to acquire data from analog in and then send to the computer in order to be read by LabVIEW.

The problem that I am facing is that the serial transmission is a bottleneck, it is too slow. Now I am sending data at 460800 baud via programming port (using Serial.write), I know that native port is faster but here is the problem: LabVIEW needs to now the baudrate (it is a necessary info for the serial block).

I have read that SerialUSB sends data as fast as possibile but not knowing the exact rate. Another problem is that if I increase the baud with the programming I am getting garbage.

My question is if it is possible to set the baud or know it?
Alternatively, do you know a method to increase the baud without losing my data?

Thank you for your time!

Code: [Select]

#define PWMFreq  525
#define DutyCycle 0.66
#define BAUD 460800

int16_t val[2];
int16_t carrier = 0;
byte checksum ;

uint16_t RegPWM = 328125/PWMFreq;
uint16_t RegDT = (int) RegPWM*DutyCycle;


void setup() {
 
 Serial.begin(BAUD);
 while(!Serial);     
 pinMode(22, INPUT);
 
 REG_PMC_PCER1 |= PMC_PCER1_PID33;                 // Enable peripheral TC6 (TC2 Channel 0)
 REG_PIOC_ABSR |= PIO_ABSR_P26 | PIO_ABSR_P25;     // Switch the multiplexer to peripheral B for TIOA6 and TIOB6 
 REG_PIOC_PDR |= PIO_PDR_P26 | PIO_PDR_P25;        // Disable the GPIO on the corresponding pins

 REG_TC2_CMR0 = TC_CMR_BCPC_SET |                  // Set TIOB on counter match with RC0
                TC_CMR_ACPC_SET |                  // Set TIOA on counter match with RC0
                TC_CMR_BCPB_CLEAR |                // Clear TIOB on counter match with RB0
                TC_CMR_ACPA_CLEAR |                // Clear TIOA on counter match with RA0
                TC_CMR_WAVE |                      // Enable wave mode
                TC_CMR_WAVSEL_UPDOWN_RC |          // Count up with automatic trigger on RC compare !PHASE_CORRECT!
                TC_CMR_EEVT_XC0 |                  // Set event selection to XC0 to make TIOB an output
                TC_CMR_TCCLKS_TIMER_CLOCK4;        // Set the timer clock to TCLK4: /128 (MCK/128 = 84MHz/128 = 656250Hz)

 REG_TC2_RA0 = RegDT;                               // Load the RA0 register 66%DT
 REG_TC2_RB0 = 0;                                   // Load the RB0 register : --
 REG_TC2_RC0 = RegPWM;                              // Load the RC0 register as 656250/RegPWM/2(per la phase-corr) = freqHz

 REG_TC2_CCR0 = TC_CCR_SWTRG | TC_CCR_CLKEN;       // Enable the timer TC6
 
 analogReadResolution(12);
 
}

void loop() {

//float strt = micros();

//for(int i=0;i<100;i++){
 
carrier = 2*digitalRead(22)-1;
val[0] = carrier*analogRead(A0);
val[1] = carrier*analogRead(A1);

checksum = byte(val[0] >> 8) + byte(val[0]) + byte(val[1] >> 8) + byte(val[1]);

Serial.write(0x02); // Start of text

Serial.write(val[0] >> 8);
Serial.write(val[0]);
Serial.write(val[1] >> 8);
Serial.write(val[1]);

Serial.write(checksum);
//}

//float stp = micros(); Serial.print("single time: "); Serial.println((stp-strt)/100); delay (2000);

}

The commented part is just for debugging and when I say that I get garbage I know it just because Serial.prints are misprinted (maybe are only these misprinted and binaries correctly written?).

PaulS

Quote
My question is if it is possible to set the baud or know it?
Using Serial or SerialUSB? Baud rate is not a term that applies to SerialUSB, so if you are asking about SerialUSB, the answer is no. If you are talking about Serial, you already know that you have to set the baud rate.

Quote
when I say that I get garbage I know it just because Serial.prints are misprinted (maybe are only these misprinted and binaries correctly written?).
Your code doesn't have any Serial.print() statements, except those that print the time that are commented out. So, it's hard to know what Serial.print()s you are talking about.

How are you determining that the mysterious Serial.print()s are producing garbage?
The art of getting good answers lies in asking good questions.

Tyarel

Thank you for your reply and sorry if I have not been clear, I know it produces garbage when I debug it and I uncomment the part with Serial.print(), in fact, when I increase the baud more than 460800 I get garbage from the serial.print, I can't see if I get garbage from serial.write because it is already "garbage" for human eyes.

Can I use normal Serial with native USB and set the baud rate? If yes,does it go higher than the programming port?

Thank you!

PaulS

Quote
Can I use normal Serial with native USB and set the baud rate?
You can try. But, it won't work. The SerialUSB class simply doesn't use a baud rate.
The art of getting good answers lies in asking good questions.

5a5

#4
Dec 02, 2019, 02:51 am Last Edit: Dec 02, 2019, 02:55 am by 5a5
Hi guys,

I also faced with that issue. The Arduino DUE can't set 460800, 921600 baud rates (from the Eclipse Arduino IDE serial monitor drop-down list) because the ATMEGA328P chip has no appropriate multipliers for that. Only 500000, 1000000 baud are acceptable at 16Mhz default clock.

Is there a way to change serial monitor drop-down list rates?

Thanks!

ard_newbie

#5
Dec 02, 2019, 04:34 am Last Edit: Dec 02, 2019, 05:16 am by ard_newbie
Can you connect Seral1,2,3 or 4 to your monitor ?

https://stackoverflow.com/questions/21944925/arduino-serial1

These Serialsx don't use the Atmega16U2 to transmit data.

You can check Serialx correct output with this type of sketch:

Code: [Select]

/*********************************************************************/
/* Jumper between RX1 and TX2, and another one between TX1 and RX2   */
/*********************************************************************/

char c = 0;
void setup() {
 
  Serial.begin(250000);
  Serial1.begin(921600);
  Serial2.begin(921600);
  Serial2.print("Hello");
}


void loop() {
  String s;
  s.reserve(10);
  s = "";

  while (Serial1.available() > 0) {
    c = Serial1.read();
    s += c;

  }
  if (s.length() > 0) {
    Serial.println(s);
    Serial2.print(s);
  }
  delay(1000);
}


5a5

Hi, ard_newbie! Thank you for the reply.

Unfortunately, the ATMEGA328p on the Arduino UNO board has USART0 only, so only one Serial port is available.

I have some idea, it is possible to hook Eclipse's calls to the communication port and override communication speed. But I don't want to implement (waste time) that, because I've already debugged my project.  :D

Go Up