Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

connection with FTDI FT232 and PIC ?

Status
Not open for further replies.

skyrock

New Member
Hello all,

I've just purchased a USB->SERIAL connector but not sure how to connect it to the PIC16F877.

The connector has 4 connections, TX, RX, GND, +v.

The USB converter actually powers itself from the USB and it says on the manual that the +v pin can be also be used to power the PIC.

Tx and Rx is fine, but do I connect the +v and gnd to the pic power source too? (my pic runs from another power source without using USB power)

thanks for any kind replies.
 
Don't forget an RS232 level shifter as well.
 
Hello all,

I've just purchased a USB->SERIAL connector but not sure how to connect it to the PIC16F877.

The connector has 4 connections, TX, RX, GND, +v.

The USB converter actually powers itself from the USB and it says on the manual that the +v pin can be also be used to power the PIC.

Tx and Rx is fine, but do I connect the +v and gnd to the pic power source too? (my pic runs from another power source without using USB power)

thanks for any kind replies.
Which one?

There are a number of modules based on the partial chip number you call out. Some are RS232, some are digital, or are you talking about a raw chip?

Only the first needs level translators. Simply tie the gnd and signal wires together, watching which is input and which is output since they can be confusing.
 
Which one?

There are a number of modules based on the partial chip number you call out. Some are RS232, some are digital, or are you talking about a raw chip?

Only the first needs level translators. Simply tie the gnd and signal wires together, watching which is input and which is output since they can be confusing.

I don't know why, but when I read his original post, I got the impression that he had a cable with the converter in it, not just a chip. I thought he was asking how to connect that cable to the pic. Now that I read it again, it doesn't say which and it is probably that he has a chip and not a cable.

Glad you came in and said something, I'd have hated for him to make a boo-boo because of me.
 
I don't know why, but when I read his original post, I got the impression that he had a cable with the converter in it, not just a chip. I thought he was asking how to connect that cable to the pic. Now that I read it again, it doesn't say which and it is probably that he has a chip and not a cable.

Glad you came in and said something, I'd have hated for him to make a boo-boo because of me.
his post is a bit convoluted... naming conventions are confused. He says one thing that sounds like he has an RS232 connector but the part number is a partial for the chip.
 
sorry to confuse. I actually had a complete part which built with the FTDI chip. so, I just have to attach 4 wires to the PIC using UART. I've tried Nigel's solution and worked.

I was just confused with the optional +5v supply whether should be used or not.

If took some sample code from Nigel's tutorial to test. it worked fine on transmission, but when it comes to receiving, it just doesnt work correctly.
my question is , should I set RC7 as input pin? or is it something else?

Hardware:
USB to UART convertor connected to 16f877, RC6,RC7,GND
RX ---- TX
TX ---- RX
GND --- GND

Code:
 	LIST	p=16F877		;tell assembler what chip we are using
	include "P16F877.inc"		;include the defaults for the chip
	ERRORLEVEL	0,	-302	;suppress bank selection messages
	__config 0x393A			;sets the configuration settings (oscillator type etc.)




		cblock	0x20		;start of general purpose registers
			count			;used in looping routines
			count1			;used in delay routine
			counta			;used in delay routine
			countb			;used in delay routine
			templcd			;temp store for 4 bit mode
			templcd2
			lcdtmp
		endc


org	0x0000
		BANKSEL ADCON1
		movlw 	0x06
		movwf 	ADCON1
		movlw	0x00
		movwf	TRISC
		movlw	b'00000001'
		movwf	TRISB
		BANKSEL PORTA			;turn analogue inputs off

Initialise	
		clrf	count
		clrf	PORTA
		clrf	PORTB
		call	SER_INIT		;initialise serial port
		bsf		PORTC, 0
Loop	;call	Rcv_RS232
		btfsc	PORTB, 0
		goto	Loop
		movlw	0x4b
		call	XMIT_RS232
		call	Delay255
		goto	Loop


;USART Serial routines

SER_INIT
            BSF     STATUS, RP0           ;select bank 1
     		MOVLW   d'129'                ;9600 baud @ 20 Mhz Fosc +0.16 err
     		MOVWF   SPBRG
     		MOVLW   b'00100100'           ;brgh = 1
     		MOVWF   TXSTA                 ;enable Async Transmission, set brgh
            BCF     STATUS, RP0           ;select bank 0
     		MOVLW   b'10010000'
     		MOVWF   RCSTA                 ;enable Async Reception
            RETURN

XMIT_RS232  btfss   PIR1,	TXIF 	      ;xmit buffer empty?
			GOTO	XMIT_RS232            ;no, wait
			MOVWF   TXREG		      ;now send
			RETURN

Rcv_RS232   BTFSS   PIR1,	RCIF 	      ; check for received data
     		GOTO    Rcv_RS232
            MOVF    RCREG,	W
            RETURN
 
take the PIC off of it and measure the voltage at the pins. The RS232 spec calls out +/-6V to +/-15V for the line levels. you are not doing yourself any good if you are connecting lines that want to be at those levels directly to the PIC.
 
sorry to confuse. I actually had a complete part which built with the FTDI chip. so, I just have to attach 4 wires to the PIC using UART.

You have not reduced the confusion with this :(

The FTDI sell different "parts", some of them are USB on one side and TTL on the other, and some are USB on one side and RS232 on another.

The output of the FTDI chip (for example FT2232 I use) is TTL so 0 - 5V, but you can find circuits that are USB to RS232 that have RS232 output levels +/- 12V IIRC (or even more)

So, can you make a picture of what you are connecting with what, or give us the link to the part number you are using as a USB to UART adapter.

If you are using something like this:
**broken link removed**
or like this:
**broken link removed**
Then you can connect it to your PIC directly (just set the jumper to 5V as your PIC is 5V and not 3V)

then again, if you are using something like this:
**broken link removed**
you cannot attach it directly to a pic because this one have RS232 level outputs (+/- 12V)

on the other hand, this one:
**broken link removed**
can be connected to both directly PIC (via CBUS connector on the side) or to RS232 device (via DB9 connector on the back)

so, which one is it ? they are all FTDI evaluation kit's, and that is just a small section of them as they offer much more

IF we take that your levels are compatible (5V TTL on both sides), you have to check your source... I'm rusty on the asm but if I remember correctly, you should enable interrupt for UART that will trigger when byte is received. You do not even call your Rcv_RS232 function at all (it is commented out) so how can you ever receive data ? (except if there is some macro that defines Rcv_RS232 as uart interrupt)

Code:
		movlw	0x00
		movwf	TRISC

one more thing, RX pin on the pic should be INPUT and TX pin on the pic should be OUTPUT, your code set them both to output, how can you receive data on output pin ?
 
Last edited:
Ok, problem solved.

it seems that i'm having a trouble of FERR due to I input too fast in between 'call Long_Delay'. After I put a debug code to check for FERR and OERR, it finally shows the cause. So, hardware wise is not an issue.

now I can see the correct response from my hyperterminal with both receiving and transmitting.

F.Y.I. below is the code i modified:
Code:
	LIST	p=16F877		;tell assembler what chip we are using
	include "P16F877.inc"		;include the defaults for the chip
	ERRORLEVEL	0,	-302	;suppress bank selection messages
	__config 0x393A			;sets the configuration settings (oscillator type etc.)




		cblock	0x20		;start of general purpose registers
			count			;used in looping routines
			count1			;used in delay routine
			counta			;used in delay routine
			countb			;used in delay routine
			templcd			;temp store for 4 bit mode
			templcd2
			lcdtmp
			received
		endc


org	0x0000
		BANKSEL ADCON1
		movlw 	0x06
		movwf 	ADCON1
		movlw	b'10000000'
		movwf	TRISC
		movlw	b'00000001'
		movwf	TRISB
		BANKSEL PORTA			;turn analogue inputs off

Initialise	
		clrf	count
		clrf	PORTA
		clrf	PORTB
		call	SER_INIT		;initialise serial port
		bsf		PORTC, 0
Loop	call	Rcv_RS232
		btfss	RCSTA, 2
		goto	step1
		movlw	0x4b
		call	XMIT_RS232
step1	btfss	RCSTA, 1
		goto	step2
		movlw	0x4c
		call	XMIT_RS232		
		call	Delay255
		goto	Loop
step2	movfw	received
		call	XMIT_RS232
		call	Delay255
		goto	Loop


;USART Serial routines

SER_INIT
            BSF     STATUS, RP0           ;select bank 1
     		MOVLW   d'129'                ;9600 baud @ 20 Mhz Fosc +0.16 err
     		MOVWF   SPBRG
     		MOVLW   b'00100100'           ;brgh = 1
     		MOVWF   TXSTA                 ;enable Async Transmission, set brgh
            BCF     STATUS, RP0           ;select bank 0
     		MOVLW   b'10010000'
     		MOVWF   RCSTA                 ;enable Async Reception
            RETURN

XMIT_RS232  btfss   PIR1,	TXIF 	      ;xmit buffer empty?
			GOTO	XMIT_RS232            ;no, wait
			MOVWF   TXREG		      ;now send
			RETURN

Rcv_RS232   BTFSS   PIR1,	RCIF 	      ; check for received data
     		GOTO    Rcv_RS232
            MOVF    RCREG,	W
			movwf	received
			incf	received
            RETURN

;End of serial routines






;Delay routines

Long_Delay
		call	Delay255
		call	Delay255
		call	Delay255
		call	Delay255
		return

Delay255	movlw	0xff		;delay 255 mS
		goto	d0
Delay100	movlw	d'100'		;delay 100mS
		goto	d0
Delay50		movlw	d'50'		;delay 50mS
		goto	d0
Delay20		movlw	d'20'		;delay 20mS
		goto	d0
Delay10		movlw	d'10'		;delay 10mS
		goto	d0
Delay1		movlw	d'1'		;delay 1mS
		goto	d0
Delay5		movlw	0x05		;delay 5.000 ms (4 MHz clock)
d0		movwf	count1
d1		movlw	0xE7
		movwf	counta
		movlw	0x04
		movwf	countb
Delay_0		decfsz	counta, f
		goto	$+2
		decfsz	countb, f
		goto	Delay_0

		decfsz	count1	,f
		goto	d1
		retlw	0x00

;end of Delay routines


end
 

Attachments

  • USB to UART.JPG
    USB to UART.JPG
    48.4 KB · Views: 1,408
  • 16f877 dev board.JPG
    16f877 dev board.JPG
    69.5 KB · Views: 1,246
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top