Go Down

Topic: How to set DUE's native USB port from high-speed to low or full speed? (Read 1 time) previous topic - next topic



I have tried to put the native USB port of Arduino DUE acting as a low speed or full speed device. At this point, I'm a bit lost. All I have managed was to increase signals' levels from 400mVpp (as they are for a high speed device) to 3V. And to get an "unrecognized USB device" message or so.

Do you have a suggestion for a starting point in doing this correctly?
I presume that my USB communication problems of spurious detaching and reattaching of the device are somehow related with a low quality USB cable and a noisy environment. And eventually with my program. So, hardware, software... did I missed something...?  :)

Thank you all!


Hi everybody!

I didn't succeeded to change the native USB settings to make it act as a low or full speed device. So, I moved the communications to the programming port and set it at 921600bps. There is something I don't understand: using RealTerm to monitor the ASCII characters sent by DUE, I have observed that RealTerm doesn't interpret them correctly if is set to 8 bits per character.
However, if I set RealTerm to receive 7 bits characters, I see correct data frames.

I changed the speed back to 115200bps at DUE's side. At that speed, RealTerm is acting normally (characters are received correctly at 8bits/character).

In the same time, it appears to me that serialEvent() doesn't manage to work properly above 115200bps. This is the highest speed at which I succeeded to communicate bidirectionally with DUE.
Above this speed, serialEvent() -which I understood that works similarly to a serial communication ISR- is triggered. It enters on every character, I counted. However, Serial.read() returns zeros, as I somehow get the receiving buffer altered.
I tried few different approaches on serialEvent() and all worked (finally) at 115200bps. At superior speeds, they fail.
As far as I think, there is not a problem of RealTerm: I have the same results by communicating with my LabVIEW application.

Can you help me, please, to understand where I'm do it wrong?

Bellow is a fragment of code. In serialEvent() are few commented variants I have tried.
Thank you for any help!

Code: [Select]

// function which links the serialEvent
// serialEvent wouldn't be called without it
void serialEventRun(void) {
  if (Serial.available()) serialEvent();

void serialEvent()
  char ch = Serial.read();
//  Serial.print(ch);
//  if (ch == '*') len = 0; //synchronize header
  if (ch != -1)  // a valid character
      if (ch == '*') len = 0; //synchronize header
      serial_buffer[len] = ch; len++; 
      if ( (ch == '\n' || ch == '\r') && (serial_buffer[0] == '*') ) {serial_data = true;}
      else if ( (ch == '\n' || ch == '\r') && (serial_buffer[0] != '*') ) len = 0;

/*unsigned char i;
  for (i=0; i<len; i++) {
    serial_buffer[ser_count] = Serial.read();
    if (serial_buffer[ser_count]=='\n') serial_data=true;

//  Serial.readBytes(serial_buffer, len);
//  for (i=0; i<=len; i++) if (serial_buffer[i]=='\n') serial_data = true;

  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') serial_data = true;

Code: [Select]

void setup(){

  Wire.begin();  // initialise the I2C connection
  definePins();  // define pin modes for digital I/O
  initialize_digout();  // initialize relay outputs
  get_parameters();  // prototype in Flash_Memory.ino. Reads parameters stored in flash

  // native USB. Used for data streaming
//  SerialUSB.begin(0);

  /* PWM channel initialization */
  /* http://forum.arduino.cc/index.php?topic=198906.0 */
  pmc_enable_periph_clk (PWM_INTERFACE_ID) ;  // turn on clocking to PWM unit

  PWMC_ConfigureChannel (PWM, 6, 1, 0, 0) ; // PWM, channel 6, clock = MCLK/2 = 42MHz
  PWMC_SetPeriod (PWM, 6, 4095) ;  // PWM, channel 6, period = 4095 pwm clocks => 10.256kHz
  //  PWMC_SetDutyCycle (PWM, 6, 200) ;  // PWM, channel 6, duty set
  PWMC_EnableChannel (PWM, 6) ;   // PWM, channel 6 enable

  // Configure pin 7 (PC23) to be driven by peripheral B (PWM channel 6 L)
  // see documentation on SAM microcontroller
  PIOC->PIO_PDR = 1<<23 ;  // disable PIO control
  PIOC->PIO_IDR = 1<<23 ;   // disable PIO interrupts
  PIOC->PIO_ABSR |= 1<<23 ;  // switch to B peripheral

  // Interrupt Service Routine for IGBT_FAULT
  //  attachInterrupt(IGBT_FAULT, igbt_fault, LOW);
  // Interrupt Service Routine for optic sensor
  //  attachInterrupt(50, speed_interrupt, FALLING);
  // se asigneaza rutinei ISR "speed_interrupt()" o intrerupere pe front cazator pe pinul 50
  // speed_interrupt este definita in Freq_Phase_Handlers

  startTimer(); // programarea si pornirea timerelor.

  initialize_PID();  // prototype in PID.ino

void loop()

  //  delay(streamtime);
  if (data_ready == true) {data_ready = false; transmit_values();} // call USB data streaming routine
  if (serial_data == true) {serial_data = false; take_USB_data();}
  if (digitalRead(IGBT_FAULT) == LOW) {delayMicroseconds(20); if (digitalRead(IGBT_FAULT) == LOW) igbt_fault();}

Go Up