PDA

View Full Version : Hserin



egberttheone
- 9th November 2004, 20:41
1ste post!

hello all. I seem to have a problem with serial receive.


this is the code that I use for sending the data, I already used +10 because it seems that it doesn't do any thing when sending a zero



HSerout [day + 10]
HSerout [month + 10]
HSerout [year + 10]
HSerout [hour + 10]
HSerout [minute + 10]
HSerout [second + 10]




and this is the code that I use for receiving




HSerin 3000,TimeOut, [CurrendDate(0)]
HSerin 100,TimeOut, [CurrendDate(1)]

HSerin 100,TimeOut, [CurrendDate(2)] '?
HSerin 100,TimeOut, [CurrendTime(0)] '?

HSerin 100,TimeOut, [CurrendTime(1)]
HSerin 100,TimeOut, [CurrendTime(2)]





the problem is that if I send "10,11,12,13,14,15" I'll receive "10,11,13,13,14,15" any explanation for this? I tryed every thing :(

Bruce
- 10th November 2004, 03:48
Welcome to the forum.

Here's a few suggestions you may find useful for synchronizing serial communications, and shrinking your code size in the process.

1. Try using the STR modifier with HSEROUT/HSERIN to send/receive strings of data rather than using multiple HSEROUT/HSERIN lines to send/receive.

2. Use some type of synchronization character to lock onto the first byte or "synch up" with the 1st character.

Note: This is just a simple example. Change whatever you need to like the TimeOut value, label, array size, baud rate, etc,,.

DEFINE OSC 20
DEFINE HSER_BAUD 9600 ' Use 9600 baud
DEFINE HSER_CLROERR 1 ' Auto clear over-run errors
RCSTA = $90 ' SPEN & CREN = 1
TXSTA = $24 ' TXEN & BRGH = 1
TimeDate VAR BYTE[6]

Main
HSERIN 5000,TimeOut,[WAIT("A"),STR TimeDate\6]
HSEROUT ["Rcvd string: ", STR TimeDate\6,13,10]
GOTO Main

TimeOut:
HSEROUT ["Nada",13,10]
GOTO Main
Use a terminal program to send A369621 to your PIC. If all's well, you'll see;

Rcvd string: 369621

If all's not well, you'll see;

Nada

This will save you a TON of code space, and it's much easier to manage.

egberttheone
- 15th November 2004, 16:35
well it seems to work now but i already got a other problem:

if i try to put a value of a variable into the array, then the interrupt routine(timer) stops working!



TimeDate(1) = DayREC
TimeDate(2) = MonthREC
TimeDate(3) = yearREC
TimeDate(4) = HourREC
TimeDate(5) = MinuteREC
TimeDate(6) = SecondREC


i don't understand why it does :( the variables are bove byte's accept that the other varaible is in a array

mister_e
- 15th November 2004, 19:26
For array you must use bracket instead of parenthesis but it's maybe a typing error...

if not, can you post your whole code ?

EShatara
- 27th November 2004, 04:15
What is the "5000" used for in the following statement



Main
HSERIN 5000,TimeOut,[WAIT("A"),STR TimeDate\6]
HSEROUT ["Rcvd string: ", STR TimeDate\6,13,10]
GOTO Main


Looking all through the PBP manual doesn't shed light on this question.

thanks...chris

EShatara
- 27th November 2004, 12:07
After rereading the discription of the HERIN command, it would appear that the syntax:

Herin 5000, Timeout, [.....]

indicates that parity is turned on and that the parity error routine is at address "5000".

Is this corrrect?

/chris

egberttheone
- 27th November 2004, 15:42
Thx for your help all, i changed some things and it works !