PDA

View Full Version : Problem with UART... here is a real challenge



matias
- 3rd May 2007, 21:56
Hi I am having a really unusual problem, I can recive a string from hiper therminal, and a friend with his microcontroller sends me the same code for deparcing and it continuos working, then a program that runs in windows sends me the same code but it dosen`t work. PIC is working ok with other devices , but when pc sends the same code that hiper therminal sends, pic dosen`t. can the problem be that pc sends the string faster between characters...or a don`t know you tell me what can it be.
thanks.

mister_e
- 3rd May 2007, 22:52
This will help if we see some code and Schematic. In general, the baudrate setting should be the problem... if your target PIC have the usual Bootloader circuit and the VB application don't care about the DTR line, this may be the cause. And then there's also the data format. Text representation or what?

Unless life should be good.

skimask
- 4th May 2007, 00:37
Any bets that Hyperterminal has a character pacing setting in it that's being used and the VB program doesn't?
Or maybe an internal oscillator is being used on the PIC?
Who knows? Can't really tell now can we......again....

matias
- 4th May 2007, 01:40
Tomorrow I will publiesh the code don`t have it with me..

matias
- 4th May 2007, 19:43
' Defines for USART

INCLUDE "bs2defs.bas"
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h '24h
DEFINE HSER_BAUD 9600 '9600 baud
DEFINE HSER_SPBRG 25 'No estaba

' Registros timer
RCIF VAR PIR1.5 ' Alias RCIF (USART Receive Interrupt Flag)
OERR VAR RCSTA.1 ' Alias OERR (USART Overrun Error Flag)
CREN VAR RCSTA.4 ' Alias CREN (USART Continuous Receive Enable)
T0CS VAR OPTION_REG.5
PSA VAR OPTION_REG.3
PS0 VAR OPTION_REG.0
PS1 VAR OPTION_REG.1
PS2 VAR OPTION_REG.2

' Declaracion de variables
valor1 VAR WORD ' tiempos Timer
valor2 VAR WORD
valor3 VAR WORD
estado VAR BYTE ' variable para disparar timer
char0 VAR BYTE ' b0 dato a decodificar
char1 VAR BYTE ' b1 dato a decodificar
char2 VAR BYTE ' b2 dato a decodificar
char3 VAR BYTE
i VAR BYTE ' Contador
string VAR BYTE[20] ' Paquete Recepcion
TMR0Count VAR WORD
c VAR BYTE






' Configuracion de puertos
TRISB= %00100111
' Configuracion inerrupciones
INTCON = %11111000 ' Registro para habilitar las interrupciones
ON INTERRUPT GoTo serialin ' AL realizarse interrupcion va ahi
PIE1.5 = 1 ' Habilitar interrupcion en USART

' Defines
RBO VAR PORTB.0
RX VAR PORTB.1
TX VAR PORTB.2
interruption VAR PORTB.3
led VAR PORTB.4
RB5 VAR PORTB.5
salida1 VAR PORTB.6
salida2 VAR PORTB.7

' Inicio del programa

i=0
c=0
char0=0
char1=0
char2=0
string[0]=0
string[1]=0
string[2]=0
string[3]=0
string[4]=0
string[5]=0
string[6]=0
string[7]=0
string[8]=0
string[9]=0
string[10]=0
string[11]=0
PORTB=0
Pause 1

HSerout ["Port has Started Ok!!"]
High interruption
'Deparcing

INICIO:

IF i=255 Then
High salida2

For i = 0 TO 20
IF string[i]=$52 Then
char0=string[i]
i=i+1
char1=string[i]
i=i+1
char2=string[i]
i=19
EndIF
Next i
EndIF
IF char0="R" AND char1="1" AND char2="1" Then 'R11
High salida1
char0=0
char1=0
char2=0
string[0]=0
string[1]=0
string[2]=0
string[3]=0
string[4]=0
string[5]=0
string[6]=0
string[7]=0
string[8]=0
string[9]=0
string[10]=0
string[11]=0
Pause 2000
i=0
Low salida1
Low salida2

EndIF

GoTo INICIO









Disable interrupt ' Don't check for interrupts in this section

serialin:

HSerin [HEX2 b0]


IF b0 = $7C Then
GoTo jump
EndIF

string[c]=b0
c=c+1
RCIF=0
Resume

jump: RCIF=0
c=0
i=255
Resume

Enable interrupt

End

skimask
- 4th May 2007, 21:12
HSerIn doesn't need to be used in an interrupt.
If you've got going what I think you've got going...
When your interrupt trips, you've got a character in the receive register. When you get into your interrupt routine, the HSerIn line will wait for the next character, not get the one that's already in the receive register.

And besides that, you're ON INTERRUPT doesn't get enabled until the end of the program (3rd line from the end of your code), which it will never reach.

mister_e
- 4th May 2007, 23:12
errr... HEX2 wait for two character, RCIF=0 is is a read only. This bit is cleared when you read RCREG untill the USART buffer is empty (HSERIN should take care of it)

if this program work with Hyperterminal and not on another software, we need to know what's the other software. Could be handy to have a LCD attach to your PIC and display the incoming data.


And besides that, you're ON INTERRUPT doesn't get enabled until the end of the program (3rd line from the end of your code), which it will never reach.

mmm... really sure of it???

skimask
- 5th May 2007, 08:30
mmm... really sure of it???

I guess I really never paid attention, but section 9 says they aren't enabled by default...I suppose I could be wrong...