urjaman / fast-usbserial

ATMega16U2 firmare - faster than arduino-usbserial
22 stars 6 forks source link

why can not set RTS pin? #2

Open luxin88 opened 8 years ago

luxin88 commented 8 years ago

I'm using RTS and DTR for some control, but I found that, when I set DTR, PD7 goes LOW, but set RTS, PD6 not have any change.

then I change this function


/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
    /* Disable watchdog if enabled by bootloader/fuses */
    MCUSR &= ~(1 << WDRF);
    wdt_disable();

    /* Hardware Initialization */
    Serial_Init(9600, false);
    LEDs_Init();
    USB_Init();

    /* Timer0 is the LED timeout timer... */
    TCCR0B = _BV(CS02);

    /* Timer1 is the USB flush timeout timer. */
    OCR1A = 8000; // 0.5ms at 16Mhz
    TCCR1A = 0;
    TCCR1B = _BV(WGM12) | _BV(CS10);

    /* Pull target /RESET line high */
    AVR_RESET_LINE_PORT |= AVR_DTR_LINE_MASK;
    AVR_RESET_LINE_PORT |= AVR_RTS_LINE_MASK;
    AVR_RESET_LINE_DDR  |= AVR_DTR_LINE_MASK;
    AVR_RESET_LINE_DDR  |= AVR_RTS_LINE_MASK;
}

/** Event handler for the CDC Class driver Host-to-Device Line Encoding Changed event.
 *
 *  \param[in] CDCInterfaceInfo  Pointer to the CDC class interface configuration structure being referenced
 */
void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{

    bool CurrentDTRState = (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR);
    bool CurrentRTSState = (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_RTS);

    if (CurrentDTRState){
      AVR_RESET_LINE_PORT &= ~AVR_DTR_LINE_MASK;
    }else{
      AVR_RESET_LINE_PORT |= AVR_DTR_LINE_MASK;
    }

    if (CurrentRTSState){
      AVR_RESET_LINE_PORT &= ~AVR_RTS_LINE_MASK;
    }else{
      AVR_RESET_LINE_PORT |= AVR_RTS_LINE_MASK;
    }
}

and I change makefile

CDEFS += -DAVR_DTR_LINE_MASK="(1 << 7)"
CDEFS += -DAVR_RTS_LINE_MASK="(1 << 6)"

and I found that, when I setup RTS, there's nothing happen, but when I set DTR, something interesting happen, RTS and DTR goes to LOW together.

I think that function EVENT_CDC_Device_ControLineStateChanged not be called when I set RTS.

I debug, and found that, when I set RTS, function Endpoint_IsSETUPReceived return false when I set RTS, but return true when I set DTR

static inline bool Endpoint_IsSETUPReceived(void)
{
    return ((UEINTX & (1 << RXSTPI)) ? true : false);
}

I'm unfamiliar with avr MCU, and I do not know what to do that.

urjaman commented 8 years ago

I dont immediately see any issue in your code (which is annoyingly inlined instead of eg. as a commit in your repo...), also RTS isnt wired on the Uno R3, so it is not a very interesting feature for me - operating one of the J2 extension header pins would make more sense though.

So in short, I have 0 reasons to investigate your problem for you. When you get it working I'd be happy to integrate a pull request :P

(You also didnt provide any details on how are you controlling RTS (what software) and how do you know that it does it right...)

luxin88 commented 8 years ago

thanks, I use a Serial Debug Tool to control DTR and RTS pin, which I tested by using FTDI chip, and it works well. I'm not familiar with AVR chip. but I saw that in the LUFA Doc

static bool Endpoint_IsSETUPReceived ( void )
inlinestatic
Determines if the current CONTROL type endpoint has received a SETUP packet.

Returns
Boolean true if the selected endpoint has received a SETUP packet, false
otherwise.

whether it means that, I need to selected endpoint in setup, so that I can listen the RTS change. is there any select to DTR pin, i will try to find it out.

I would appreciate it if you wouldn't bother to share your knowledge with me.

2016-08-11 4:40 GMT+08:00 Urja Rannikko notifications@github.com:

I dont immediately see any issue in your code (which is annoyingly inlined instead of eg. as a commit in your repo...), also RTS isnt wired on the Uno R3, so it is not a very interesting feature for me - operating one of the J2 extension header pins would make more sense though.

So in short, I have 0 reasons to investigate your problem for you. When you get it working I'd be happy to integrate a pull request :P

(You also didnt provide any details on how are you controlling RTS (what software) and how do you know that it does it right...)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/urjaman/fast-usbserial/issues/2#issuecomment-238996809, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1WSL08hxDRlrz26dE4Ooo6-rBdh3alks5qejc9gaJpZM4JfH7G .