PDA

View Full Version : To Melanie, Dave and Ingvar!!How to reset USART module in PicBasic?



fbestepe
- 30th November 2004, 17:41
Hi Everyone,

I asked a question about MCLR reset before, now I would like to ask how to reset USART module? The problem is not changed, it is the same before, but I understood that my problem is related with USART module. The infrastructure is like that, I am connecting to 16F877 using hyper terminal with dial up connection over 2 external modems. The connection between remote modem and 16F877 is fullfiled via USART. The problem is that, after the dial up connection is established, the device (16F877) is needed to be MCLR reset in order to receive and/or transmit characters properly. (That is, Hserout/Hserin does not work until MCLR)
Interestingly, if the connection between remote modem and 16F877 is fullfiled over PortB.0, PortB.1 with inverted logic, everything is OK, there is no need any reset. (Serin2/Serout2 works perfect.)
I have to use USART module for this connection and I need your help very much. In my opinion, if I can only reset USART module, I will be able to solve this problem.
I am waiting for your recommendations.
Thanks and Regards,
Firat

electronicsuk
- 30th November 2004, 17:45
Perhaps you just need to clear the serial port enable bit SPEN, can't remember the exact register it is located on but it should say so in the datasheet. The problem could be because you are receiving invalid data and causing a framing error or overrun when connecting up, so you just need to clear it by disabling and then re-enabling the UART.

Matthew

Ingvar
- 1st December 2004, 10:13
Hi Firat,

The more recent versions of PBP has the ability to automatically clear an overrun error. Just add "DEFINE HSER_CLROERR 1" in your program. If this doesn't help you'll need to post your code, details about your hardware(serial), PBP version , etc. Too little information makes it impossible to help.

/Ingvar

fbestepe
- 1st December 2004, 11:07
Thanks Ingvar (good Swedish guy),

"DEFINE HSER_CLROERR 1" statement solved the problem, as you said. That is very fine. Thanks .

Note: I was in Visby in September, I liked very much Swedish people.

Firat.

Dave
- 1st December 2004, 12:22
Firat, In the past I have had problems with the usart in an 16F628 and found that before using the internal usart if I sent the commands:
IF RCSTA.1 = 1 THEN 'if overrun error bit is set
RCSTA.4 = 0 'clear CREN continous receive enable bit
RCSTA.4 = 1 'set CREN continous enable receive bit
ENDIF
What this does is to reset the internal overrun error latch that when set inhibits any received data bytes, effectively disabling the usart. Adding these lines of code just before the usart use will make sure the usart will receive the data. This had to be used before the PBP compiler was updated with the added command of: DEFINE HSER_CLROERR 1 which does this function in the background.

Dave Purola,

Ingvar
- 1st December 2004, 12:49
A good friend of mine used to say "Flattering will get you everywhere"(or was it anything), it works :-)

Never been to Visby myself, yet. I hear that it's really nice in the summer, but that's true for most parts of Sweden.

Cheers
/Ingvar