UART is displaying unexpected characters

Status
Not open for further replies.

PA3040

Dear All,
My above codes working well with Proteus, But it does not working with actual hardware which I made myself

Hardware connection

RC6 to pin 11 of max232
Rc7 to pin 12 of max232

pin 13 of max232 to pin 3 of DB9
pin 14 of max 232 to pin 2 of DB9

pin 5 of DB9 is connected to GND

Communication with windows XP, using puTTy software

Banned
What is the problem? Maybe your MAX232 is damaged.

PA3040

PA3040

points: 2

alexan_e

Post a schematic of the MAX232 circuit you are using

PA3040

PA3040

points: 2

bigdogguru

What type of unexpected characters are being displayed?

BigDog

alexan_e

The capacitor in pin #6 is reversed, pin 6 is negative compared to the GND so the - of the cap goes to pin 6 and + to GND

PA3040

PA3040

points: 2

PA3040

Dear Alex Thanks for the reply

Sorry for delay to respond
Please see the attached for cct

- - - Updated - - -

Dear Bigdog Thanks for the reply

Actually unexpected characters came earlier when I simulated with Proteus, but now I am using actual hardware. it dose not receive any characters

- - - Updated - - -

Still I could not changed the IC. I will let you know after change it

Attachments

• 16.2 KB Views: 8

Banned
Please post the Schematic not the PCB layout.

alexan_e

The capacitor in pins 4 and 5 is also reversed

PA3040

PA3040

points: 2

wp100

Hi,

Just looking at your circuit, it seems you have the cap on pins 4 and 5 the wrong way round.

According to the max232 datasheet if it is a max232 chip it should have 1uf caps not 10uf, or if its a max232a it should be 0.1uf
( though not sure but it may still work with 10uf..??)

Alway best to fit a 100nf across pins 31 and 32 of the 877a.

Not too clear from the diagram, assume something is pulling up Mclre when not conencted to icsp ?

PA3040

PA3040

points: 2

PA3040

Dear All,
I corrected all 10uf Capacitors as you advised. but still problem remaining unchanged

Code:
char_loader	equ			0x20
char_reciver	equ		0x21
LIST P=P16F877
#include <p16f877a.inc>
__config 3f39

org	0x000
start		goto	main
main		call	sys_init
goto	loop

call	send_char
movlw	'E'
call	send_char
movlw	'S'
call	send_char
movlw	'T'
call	send_char
movlw	'1'
call	send_char
movlw	'2'
call	send_char
return

send_char	btfss	PIR1,TXIF			;Check the USART transmit buffer is empty
goto	$-1 movf char_loader,w movwf TXREG return sys_init clrf PORTB bsf STATUS,5 movlw b'10000000' movwf TRISC movlw 0x19 movwf SPBRG ; Set Baud rate 9600bps movlw b'10100100' ; 8-bit transmit, transmitter enabled, movwf TXSTA ; asynchronous mode, low speed mode clrf TRISB bcf STATUS,5 bsf RCSTA,SPEN ;Serial port enabled ;(configures RC7/RX/DT and ;RC6/TX/CK pins as serial port pins) movlw b'10010000' movwf RCSTA return end Please advice Attachments • 17.6 KB Views: 7 alexan_e Administrator What is the voltage in pins 2 and 6 referred to the ground? Are you sure that this is not a fault of the uard code in the mcu ? wp100 Advanced Member level 5 Hi, Your code does work in ISIS but not sure about the values you have assigned to the Usart TXSTA Assume you are using a 4mhz crystal ? Have used my standard usart init routine that I know works on hardware ok. There is no need to move your data, movlw 'T' to a separate register, the Usart picks up the value from W as nothing changes it. Also add a little delay after sending the string of data so you can see it more clearly. Code: char_loader equ 0x20 char_reciver equ 0x21 LIST P=16F877a #include <p16f877a.inc> __config 3f39 org 0x000 start goto main main call sys_init loop call load_char goto loop load_char movlw 'T' ; movwf char_loader call send_char movlw 'E' ; movwf char_loader call send_char movlw 'S' ; movwf char_loader call send_char movlw 'T' ; movwf char_loader call send_char movlw '1' ; movwf char_loader call send_char movlw '2' ; movwf char_loader call send_char ; call delay500ms ; add in a little delay to slow the messages down a bit return send_char btfss PIR1,TXIF ;Check the USART transmit buffer is empty goto$-1
movwf	TXREG
return

sys_init	clrf	PORTB
bsf		STATUS,5
movlw	b'10000000'
movwf	TRISC
;			movlw	0x19
;			movwf	SPBRG			; Set Baud rate 9600bps
;			movlw	b'10100100'		; 8-bit transmit, transmitter enabled,
;			movwf	TXSTA			; asynchronous mode, low speed mode
;			clrf	TRISB
;			bcf		STATUS,5
;			bsf		RCSTA,SPEN			;Serial port enabled
;(configures RC7/RX/DT and
;RC6/TX/CK pins as serial port pins)
;			movlw	b'10010000'
;			movwf	RCSTA

movlw   d'25'               ; 9600 baud @ 4 Mhz Fosc  8 bit Async
banksel SPBRG
movwf   SPBRG				; BRGH=1
movlw   b'00100100'
movwf   TXSTA               ;enable Async Transmission, set brgh
banksel 0
movlw   b'10010000'
movwf   RCSTA               ;enable Async Reception
return

end

PA3040

PA3040

points: 2

PA3040

I checked the MAX232 pin voltage again the datasheet

PIN no 2, 4.7v ( + )
PIN no 6, 3.7v ( + )

As per datasheet it should be +10v and -10v

As per the above data, I think better way change the MAX 232 IC first.

alexan_e

Use lower capacitor values too, the 10uf may be the cause of the problem stressing the internal charge pump

PA3040

PA3040

points: 2

wp100

Hi,

No idea of the exact voltages the max232 produces but seems to remember its always a good bit lower than the figures they quote.

If you have a Pickit2 /Clone /diy you can uses the V2.61 PK2 USART tool to act as the PC, so bypassing the max232 chip.

alexan_e

Just measured a max232CPE (1uf caps) with just power supply (no Tx/Rx) and I got -9.61, +9.78

PA3040

PA3040

points: 2

PA3040

Dear All Thanks for the replies,

Now it is working
I changed the MAX 232n, without changing Capacitors. suppose to change capacitors tomorrow
PIN no 2 = + 8.89
PIN no 6 = - 8.36

Previously I used MAX 232cpe
I think there is no big different between MAX 232cpe and max232n
I need to more improve this further, then I will let you know.

- - - Updated - - -

Hi
Dear wp100, Thanks for the reply
I applied the delay subroutine as you advised, then it isn't working (SORRY NOW IT IS WORKING)

Last edited:

PA3040

Dear All,
Now my USART Program is working

So my laptop does not have serial port ( DB9). Can I able connect this using USB to serial converter cable with my laptop

Is it possible to prepare it myself ?

Banned
Yes. You can use USB to Serial Adapter (Breakout Board). You can get it from SparkFun.

PA3040

PA3040

points: 2

PA3040

Yes. You can use USB to Serial Adapter (Breakout Board). You can get it from SparkFun.
Dear jayanth, Thanks for the reply

I mean simple USB to serial converter which is just locally available one

Breakout board, Is this special kind of board

Currently I am using PuTTy for PC interface. If I used USB to serial converter then, can I use PuTTy ?