Página 1 de 1

SERIAL PIC TRAVANDO SEM MAIS NEM MENOS

MensagemEnviado: 12 Mar 2008 15:05
por raphaelgaspar
Estou com um problema na comunicção serial entre o pc e o pic16f877.
Vou tentar explicar o que acontece:
Quando uso a serial o programa do pic so funciona se eu estiver com uma sessão serial aberta com o pic, entao faço essa sessão através do Hyper Terminal espero uns 2 segungos e começo a mandar as msg, até ai tudo bem. Após fazer teste percebi quando eu fecho a sessão e depois abro novamente o pic parece que renicia, verifico isso com o lcd voltando para o cursor home ( Normal isso? ). Mas o maior problema e quando eu abro e logo em seguida mando as msg o pic parece que trava pois nao escreve mais nada no LCD.

Pegando o ganjo, verifiquei tmb se ponho um delay no programa o pic trava tambem.

Se alguem tiver alguma solução ou alguma coisa que posso consultar para corrigir meu problema agradeço desde de já
Raphael Gaspar

MensagemEnviado: 12 Mar 2008 21:46
por RobL
Possivelmente, esqueceu de limpar alguma interrupção, mais provavelmente na UART.

MensagemEnviado: 13 Mar 2008 21:41
por caduhitec
A usart do pic tem um buffer de somente 2 bytes, se chegarem os dois bytes e não forem tratados (lidos) a usart trava mesmo.

MensagemEnviado: 14 Mar 2008 00:52
por Renie
Cadu,

3, três bytes!

Rapha, dê uma olhada no meu Remoto Serial, talvez ajude!

MensagemEnviado: 15 Mar 2008 08:30
por caduhitec
10.2.2 USART ASYNCHRONOUS
RECEIVER

The receiver block diagram is shown in Figure 10-4.
The data is received on the RC7/RX/DT pin and drives
the data recovery block. The data recovery block is
actually a high-speed shifter, operating at x16 times the
baud rate; whereas the main receive serial shifter
operates at the bit rate or at FOSC.
Once Asynchronous mode is selected, reception is
enabled by setting bit CREN (RCSTA<4>).
The heart of the receiver is the Receive (Serial) Shift
Register (RSR). After sampling the Stop bit, the
received data in the RSR is transferred to the RCREG
register (if it is empty). If the transfer is complete, flag
bit, RCIF (PIR1<5>), is set. The actual interrupt can be
enabled/disabled by setting/clearing enable bit, RCIE
(PIE1<5>). Flag bit RCIF is a read-only bit which is
cleared by the hardware. It is cleared when the RCREG
register has been read and is empty. The RCREG is a
double-buffered register (i.e., it is a two-deep FIFO). It
is possible for two bytes of data to be received and
transferred to the RCREG FIFO and a third byte to
begin shifting to the RSR register. On the detection of
the Stop bit of the third byte, if the RCREG register is
still full, the Overrun Error bit, OERR (RCSTA<1>), will
be set
. The word in the RSR will be lost. The RCREG
register can be read twice to retrieve the two bytes in
the FIFO. Overrun bit OERR has to be cleared in software.
This is done by resetting the receive logic (CREN
is cleared and then set). If bit OERR is set, transfers
from the RSR register to the RCREG register are inhibited
and no further data will be received. It is, therefore,
essential to clear error bit OERR if it is set. Framing
error bit, FERR (RCSTA<2>), is set if a Stop bit is
detected as clear. Bit FERR and the 9th receive bit are
buffered the same way as the receive data. Reading
the RCREG will load bits RX9D and FERR with new
values, therefore, it is essential for the user to read the
RCSTA register before reading the RCREG register in
order not to lose the old FERR and RX9D information.

Renie, pelo que entendí, qdo é detectado o stop bit do terceiro byte o bit de erro (OERR) será setado, é isso mesmo??

[]´s

Cadu

MensagemEnviado: 15 Mar 2008 13:30
por Renie
Cadu,

Sim, se você não ler o registro antes da chegada do stop bit do 3o byte,
vai travar indicando que encheu o buffer.

MensagemEnviado: 17 Mar 2008 09:13
por alexhnunes
Renie, pegando um gancho na sua resposta, será que não seria esse o meu problema? (http://asm51.eng.br/phpBB/viewtopic.php?t=4833)

MensagemEnviado: 19 Mar 2008 00:54
por Renie
Olá Alex,

Desculpe, o tópico não apareceu aqui como não lido e não tinha visto sua
pergunta!

Eu não uso C, mas, é bem provável que sim, o código gerado pode não
ter velocidade suficiente para recolher os dados.

Existem algumas opções e testes a fazer:

- tente usar uma taxa de transmissão mais baixa (baudrate) ou

- use um clock mais alto.

- use a interrupção para receber os dados e coloque-os em um buffer
SEU (isso só vai funcionar se seus pacotes não forem muito grandes
e tiver ram livre para isso) ou

- se os pacotes forem muito grandes, mude seu código para "quebrar"
em pacotes menores.

- tente optimizar o código, como é em C, fica um pouco mais difícil,
talvez tenha que mudar algumas rotinas na unha para ASM.

MensagemEnviado: 19 Mar 2008 09:32
por alexhnunes
Respondido no outro tópico...