PDA

View Full Version : Forward Serial Data from pic to pc



Muller
- 2nd September 2008, 20:06
Hello, I have had some trouble trying to do the following:

I need to send 8 bytes, from pic1(16f887) to pic2(18f2550) using hserin/hserout. Then I need to forward those 8 bytes from pic2 to a PC via USB.

What would be a good algorithm to accomplish this? Lets take into account tmr0 Interrupts(dt instant I.) running on both pics. Pic1 has other bussiness to do other than sending the data, and pic2 is just a mediator between pic1 and pc.

If anyone has an idea I would be very grateful. I just need the algorithm to come up with the code. By the way, I know how to use the 2550 to send info via USB.
Thanks a lot in advance!

mackrackit
- 2nd September 2008, 20:28
Receive into pic2 as an array, then forward the array. ?

Muller
- 2nd September 2008, 21:21
wait, sorry. My enter key is messing up, wasn't finished

Muller
- 2nd September 2008, 21:23
OK, I tried that Dave. With bad results, here's my code:

Pic2 code
<code>
RXIn:
if RCIF then

@ INT_DISABLE TMR0_INT
for index = 0 to 3
hserin [serialdata]
dataA(index) = serialdata
next index
usbservice
gosub dousbout
@ INT_ENABLE TMR0_INT

endif
@ INT_RETURN

</code>

pic1 code:

<code>
hserout [var1(0), var1(1), var1(2), var1(3)] 'it only has 4 bytes now
</code>

I tried:
<code>
hserout [STR var1\4]
</code>
but it gave me an error (ERROR: Macro HSEROUTSTRN?W not found in macro file.)

mackrackit
- 2nd September 2008, 21:28
To receive an array you need to HSERIN something like this


[WAIT("A"),STR NUMS\8]

Muller
- 2nd September 2008, 21:33
sorry, again.. I wish I could delete the messages. My enter key, instead of jumping a line, sends the message earlier. sorry :(

Muller
- 2nd September 2008, 21:34
And when I want to send it, why do I get that error?

ERROR: Macro HSEROUTSTRN?W not found in macro file.

Isn't <code> hserout [STR nums\8] </code> right?

mackrackit
- 2nd September 2008, 21:45
We are passing each other:)

Can you post the whole code. Something is missing.

Muller
- 2nd September 2008, 21:45
OK, I found out what I was doing wrong.. THe array I was trying to send was a word, not a byte.. Sorry..

mackrackit
- 2nd September 2008, 21:46
Thats what was missing :D