We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

trossin
Posts: 64
Joined: Sun May 19, 2019 9:44 pm

Windows COM access to PICO via USB trouble

Wed Jan 19, 2022 2:44 am

I am able to get serial communication over USB with the PICO when I use putty but when I use a Visual Studio C++ to open the COM port at 115200 baud rate, I can't receive bytes. It does not seem to matter what baud rate I open the port up with putty, it works fine (9600, 2400, 115200). When I do it with my 20 year old code that works just fine with FTDI, or other USB to TTL boards, I can't get any bytes.

Is there some secret that I am missing that putty is doing when it opens the port that I need to add to my windows code. I really don't want to use a USB-to-TTL board when there seems to be a perfectly good USB serial port on the board.

The Open works fine (using COM5,115200,200) but the read does not return bytes.

int CSerialPort::Open(char *PortName, int BaudRate, int ReadTimeOutms)
{
char s[100];

DCB dcb;
COMMTIMEOUTS timeouts;

FillMemory(&dcb,sizeof(dcb),0);
dcb.DCBlength = sizeof(dcb);

sprintf(s,"baud=%d parity=N data=8 stop=1",BaudRate);

if (!BuildCommDCB(s, &dcb)) {
m_hComm = INVALID_HANDLE_VALUE;
CloseHandle(m_hComm);
return(-1);
}

if(!SetCommState(m_hComm,&dcb)){
m_hComm = INVALID_HANDLE_VALUE;
CloseHandle(m_hComm);
return(-1);
}

/* Set time out */

GetCommTimeouts(m_hComm,&timeouts);
timeouts.ReadTotalTimeoutMultiplier = 1;
timeouts.ReadTotalTimeoutConstant = ReadTimeOutms;
if(!SetCommTimeouts(m_hComm,&timeouts)){
m_hComm = INVALID_HANDLE_VALUE;
CloseHandle(m_hComm);
return(-1);
}
return(0);
}

int CSerialPort::Read(unsigned char *data, int NumBytes)
{
unsigned long num_bytes_read;

ReadFile(m_hComm,data,NumBytes,&num_bytes_read,NULL);

return(num_bytes_read);
}

trossin
Posts: 64
Joined: Sun May 19, 2019 9:44 pm

Re: Windows COM access to PICO via USB trouble

Thu Jan 20, 2022 12:38 am

So I grabbed the source for putty and and did some hacking and found that I can get my old Windows code working with this change:

dcb.fDtrControl = DTR_CONTROL_ENABLE;

I hope this helps others if they also run into this problem.

The whole structure is filled like this (The not needed lines are different from what I used to use but did not matter. Just the one line is the key):

dcb.fBinary = true; // Not needed for PICO
dcb.fDtrControl = DTR_CONTROL_ENABLE; // This is needed for PICO.
dcb.fDsrSensitivity = false;
dcb.fTXContinueOnXoff = false;
dcb.fOutX = true; // Not needed for PICO
dcb.fInX = true; // Not needed for PICO
dcb.fErrorChar = false;
dcb.fNull = false;
dcb.fRtsControl = RTS_CONTROL_ENABLE; // Not needed for PICO
dcb.fAbortOnError = false;
dcb.fOutxCtsFlow = false;
dcb.fOutxDsrFlow = false;

dcb.BaudRate = BaudRate;
dcb.ByteSize = 8;
dcb.StopBits = ONESTOPBIT;
dcb.Parity = NOPARITY

trossin
Posts: 64
Joined: Sun May 19, 2019 9:44 pm

Re: Windows COM access to PICO via USB trouble

Thu Jan 20, 2022 2:41 am

I tried those settings with some Silicon Labs USB to TTL converter projects I've built in the past using Microchip 8 and 16 bit processors and found that things got a bit wonky with my dsPIC based logic analyzer project in that it would lock up fetching a block of samples.

https://www.sites.google.com/site/tedro ... ronics/pic

So, Here are the settings that seem to work for the Raspberry Pi PICO USB stdio and the Silicon Labs drivers for the CP210x boards.

FillMemory(&dcb,sizeof(dcb),0);
dcb.DCBlength = sizeof(dcb);

// Need to test with FTDI driver

dcb.fBinary = false; // true in Putty works with SiLabs (Not needed for PICO)
dcb.fDtrControl = DTR_CONTROL_ENABLE; // This is needed for PICO (OK with Silicon Labs driver).
dcb.fDsrSensitivity = false;
dcb.fTXContinueOnXoff = false;
dcb.fOutX = false; // true in Putty but fails SiLabs driver (Not needed for PICO)
dcb.fInX = false; // true in Putty but fail SiLabs driver (Not needed for PICO)
dcb.fErrorChar = false;
dcb.fNull = false;
dcb.fRtsControl = RTS_CONTROL_DISABLE; // RTS_CONTROL_ENABLE in Putty (Not needed for PICO)
dcb.fAbortOnError = false;
dcb.fOutxCtsFlow = false;
dcb.fOutxDsrFlow = false;

dcb.BaudRate = BaudRate;
dcb.ByteSize = 8;
dcb.StopBits = ONESTOPBIT;
dcb.Parity = NOPARITY;

if(!SetCommState(m_hComm,&dcb)){
m_hComm = INVALID_HANDLE_VALUE;
CloseHandle(m_hComm);
return(-1);
}

trossin
Posts: 64
Joined: Sun May 19, 2019 9:44 pm

Re: Windows COM access to PICO via USB trouble

Thu Jan 20, 2022 7:36 pm

The settings seem to work with my FTDI interfaces as well so that is what I’ll stick with

pmulvey
Posts: 15
Joined: Tue Feb 16, 2021 9:25 am
Location: Athlone, Ireland

Pi Pico not connecting to Win 10 **SOLVED**

Sun Jan 23, 2022 1:09 pm

I had two Picos that connected to my Win 10, 2 months ago. I revisited them this weekend and they would not connect. They connected to Win 8.1 fine but not Win 10. I uninstalled the driver checking "delete files option" and now they are back! While I was trying to figure this out I put CircuitPython on the Picos which connected just fine but was reluctant to use this as I was afraid of frying my brain trying to cope with Micropython on the ESP32 at one end of a radio link and CircuitPython at the other end. My lockdown / retirement project is a Greenhouse and I hope to load it with all sorts of tech, just for the hell of it.

Return to “General”