Data Transmission Between Teensy and DTV

skylight

Member
Hey guys.

I've been trying to transmit data between my teensy 4.0 and DTV connected to its host. Unfortunately, userial seems to be unavailable whenever I try to do a read or write operation. Here's the simple code I'm using for that transmission, which is very similar to one of the examples in USBHost_t36 library (USB to USBHost). I wonder why I can't have this communication.

I would appreciate your help.
 

Attachments

  • ino.ino
    2.3 KB · Views: 22
When you post code can you insert it between CODE tags using the </> button rather than inserting a file.
That file MIGHT contain a virus and thus people are loathed to download it and therefore help you.
Below is your code inserted between code tags.
Code:
#include <USBHost_t36.h>

#define BAUD 115200


uint32_t             format = USBHOST_SERIAL_8N1;
USBHost              myusb;
USBSerial_BigBuffer  userial(myusb, 1, PID, VID, USBSerialBase::CP210X, 0);
char                 buffer[512];
char                 mybuffer[512] = "12345612345678901234567890123456789012567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234561234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";


void setup() {
  myusb.begin();
  userial.begin(BAUD);
  Serial1.begin(BAUD); 
  Serial.begin(BAUD);
  Serial1.println("setup completed.");
}

void loop() {
  myusb.Task();
  uint16_t rd, wr, n;

    wr = userial.availableForWrite();
    if (wr > 0){
      
    // write to dtv
      userial.write(mybuffer, sizeof(mybuffer));
      Serial1.println("wrote to tuner successfully!");
    }
    
    else{
      Serial1.println("userial not available");
    }
    

    unsigned long startMillis = millis();
    unsigned long currentMillis;
    unsigned long timeout = 2000;
    
    while(true){

      currentMillis = millis();
      
      rd = userial.available();
      
      if(rd > 0) break;
      
      if(currentMillis - startMillis > timeout){
        Serial1.println("timeout");
        break;
      }
      
    }
    
  
    if (rd > 0) {
      Serial1.println("dtv available");
      n = userial.readBytes((char *)buffer, rd);
      Serial1.println((char *)buffer);
      // check if the USB virtual serial port is ready to transmit
      wr = Serial.availableForWrite();
      if (wr > 0) {
        // compute how much data to move, the smallest
        // of rd, wr and the buffer size
        if (rd > wr) rd = wr;
        if (rd > 80) rd = 80;
        // read data from the USB host serial port
        n = userial.readBytes((char *)buffer, rd);
        // write it to the USB port
        Serial1.println("read data fom dtv successfully!");
      }
    }

    delay(10);
    
 }
 
Looking at your code I see that you are using Serial1 a lot. Do you realise that this is a UART port NOT USB serial connected to your computer.
The USB Serial port connecting to your computer is addressed as Serial.
Serial1 .. Serialxx are actual UART ports.
 
oh... I see. okay. Well yeah I do realize that, and I'm currently using this UART (Serial1) to see results in serial monitor.
Any ideas about why userial is not available tho?
 
On the Teensy the IDE's Serial monitor is Serial NOT Serial1.
Change all your Serial1's to Serial and delete resulting multiple Serial.begin's.
 
On the Teensy the IDE's Serial monitor is Serial NOT Serial1.
Change all your Serial1's to Serial and delete resulting multiple Serial.begin's.
Yeah I first choose the UART port manually before opening the serial monitor.
Hmm I don't know how that's gonna affect userial, modifying the code in the way suggested
 
Back
Top