SERIAL PIC TRAVANDO SEM MAIS NEM MENOS

Software e Hardware para uC PIC

Moderadores: andre_luis, 51, guest2003, Renie

SERIAL PIC TRAVANDO SEM MAIS NEM MENOS

Mensagempor raphaelgaspar » 12 Mar 2008 15:05

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
raphaelgaspar
 
Mensagens: 1
Registrado em: 05 Mar 2007 14:19

Mensagempor RobL » 12 Mar 2008 21:46

Possivelmente, esqueceu de limpar alguma interrupção, mais provavelmente na UART.
RobL
Dword
 
Mensagens: 1546
Registrado em: 20 Fev 2007 17:56

Mensagempor caduhitec » 13 Mar 2008 21:41

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.
caduhitec
Bit
 
Mensagens: 17
Registrado em: 27 Out 2006 15:39
Localização: Rio de Janeiro - RJ

Mensagempor Renie » 14 Mar 2008 00:52

Cadu,

3, três bytes!

Rapha, dê uma olhada no meu Remoto Serial, talvez ajude!
[]'s
Renie
-------------------------------------------------------------------------------------------------------------
Meu velho site com eletrônica praticamente parado http://www.reniemarquet.com
Nosso Blog http://artemadeiraevida.blogspot.com.br
Renie
Word
 
Mensagens: 732
Registrado em: 11 Out 2006 22:35
Localização: RJ - Niterói - Brasil

Mensagempor caduhitec » 15 Mar 2008 08:30

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
caduhitec
Bit
 
Mensagens: 17
Registrado em: 27 Out 2006 15:39
Localização: Rio de Janeiro - RJ

Mensagempor Renie » 15 Mar 2008 13:30

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.
[]'s
Renie
-------------------------------------------------------------------------------------------------------------
Meu velho site com eletrônica praticamente parado http://www.reniemarquet.com
Nosso Blog http://artemadeiraevida.blogspot.com.br
Renie
Word
 
Mensagens: 732
Registrado em: 11 Out 2006 22:35
Localização: RJ - Niterói - Brasil

Mensagempor alexhnunes » 17 Mar 2008 09:13

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)
alexhnunes
Nibble
 
Mensagens: 59
Registrado em: 28 Mai 2007 10:04
Localização: Campinas - SP

Mensagempor Renie » 19 Mar 2008 00:54

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.
[]'s
Renie
-------------------------------------------------------------------------------------------------------------
Meu velho site com eletrônica praticamente parado http://www.reniemarquet.com
Nosso Blog http://artemadeiraevida.blogspot.com.br
Renie
Word
 
Mensagens: 732
Registrado em: 11 Out 2006 22:35
Localização: RJ - Niterói - Brasil

Mensagempor alexhnunes » 19 Mar 2008 09:32

Respondido no outro tópico...
Alexandre Nunes
alexhnunes
Nibble
 
Mensagens: 59
Registrado em: 28 Mai 2007 10:04
Localização: Campinas - SP


Voltar para PIC

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x