PDA

View Full Version : Usb to serial converter with pic18f



pedja089
- 14th May 2013, 11:07
Hi,
I'm working on redesign device which have PL2303 and few passives components, and transistors. My idea is to replace PL2303 with PIC18F and to add more functionality.
But I do not know how to send serial port settings(baud rate, parity, etc) from PC to PIC.
Does any one have idea where to start? Custom drivers for windows:confused:

pedja089
- 14th May 2013, 16:49
Update:
Just found that microchip usb stack 2.x support notification system when baud rate is changed on host.
Is there any way to implement that on existing cdc example for PBP?

pedja089
- 27th June 2016, 14:12
I run into same issue, again. I needed to create full serial port emulator, like FT232, and to do some other things with pic.
I spent almost a week, trying to get C to work, and decided to give PBP another try.
This time with good result.
To get baud rate, parity and stop bits from original CDC demo, use this code

BaudRate var long BANKA SYSTEM
StopBits Var Byte BANKA SYSTEM ;0=1 stop bit, 2=2 stop bit
ParityType Var Byte BANKA SYSTEM
DataBits Var Byte BANKA SYSTEM
Main: ' original code from CDC example

GOSUB GetLineCoding 'get baudrate etc... Should do that regularly and check if anything is changed


GetLineCoding:
asm
movlb high _USBMEMORYADDRESS ; Point to proper bank

movf line_coding + dwDTERate, W
movwf BaudRate
movf line_coding + dwDTERate + 1, W
movwf BaudRate + 1
movf line_coding + dwDTERate + 2, W
movwf BaudRate + 2
movf line_coding + dwDTERate + 3, W
movwf BaudRate + 3

movf line_coding + bCharFormat, W
movwf StopBits

movf line_coding + bParityType, W
movwf ParityType

movf line_coding + bDataBits, W
movwf DataBits
endasm
RETURN