PDA

View Full Version : Shiftout/in



BobEdge
- 22nd August 2007, 11:42
I used to send data between 2 cards using serout, but after fitting feedthru caps to help with EMC tests this no longer works, even if I goto 300 baud.
So I have tried to write a slave shiftin routine, which i think should be included in pbp, but anyway I am not having any joy at all. Has anyone rolled their own shiftin routine? I am trying to send/receive word variables at a very slow rate. I have looked at spislave.bas but I dont understand it at all. I wish the pbp manual was complete, there seems to be more missing than is included.

Regards Bob...

keithdoxey
- 22nd August 2007, 12:39
I used to send data between 2 cards using serout, but after fitting feedthru caps to help with EMC tests this no longer works, even if I goto 300 baud.

Do you mean you have feedthrough caps in the actual serial line ?

If so then there is no DC path and the receiving PIC will only see short duration spikes not proper logic levels needed to send data.

BobEdge
- 22nd August 2007, 12:58
yes the feedthru caps are in the serial line. But they do have a dc path. Here is a link to them on the Farnell website.
http://uk.farnell.com/jsp/Passive+Components/Filters/AVX/W3F15C2238AT1A./displayProduct.jsp?sku=669398&_requestid=248319

keithdoxey
- 22nd August 2007, 13:04
yes the feedthru caps are in the serial line. But they do have a dc path. Here is a link to them on the Farnell website.
http://uk.farnell.com/jsp/Passive+Components/Filters/AVX/W3F15C2238AT1A./displayProduct.jsp?sku=669398&_requestid=248319

OK. :)

Was just a thought ..... a wrong thought !

Bruce
- 22nd August 2007, 15:32
If you need total control of data & clock timing, it should be relatively easy to roll your own
synchronous serial routines.

See if something like this works. To adjust data & clock timing just change the constant
delays or even switch to PAUSEUS VS PAUSE.


DEFINE OSC 4 ' 16F877A @ 4MHz sending
DEFINE LOADER_USED 1

SYMBOL DOUT = PORTB.0 ' data output pin
SYMBOL CLOCK = PORTB.1 ' clock output pin

DAT_DLY CON 1 ' data bit rate = DAT_DLY*2 + CLK_DLY + loop overhead
CLK_DLY CON 1 ' clock time

PACKET VAR WORD ' 16-bit data packet
INDEX VAR BYTE ' data packet bit index pointer/loop counter

PORTB = 0 ' pins idle low
TRISB = %11111100 ' RB0, RB1 outputs
PAUSE 3000

MAIN:
PACKET = %1010101010101101 ' load 16-bit data packet (receiving PIC displays $AAAD)

' delay values give around 3.1mS wide data bits with a 1mS clock pulse
' in the center of each data bit.
SEND:
FOR INDEX = 15 TO 0 STEP-1 ' send msb first (lsb first would be 0 to 15)
DOUT = PACKET.0[INDEX] ' place data bit on RB0
PAUSE DAT_DLY ' pause bit time
HIGH CLOCK ' set clock in middle of data bit
PAUSE CLK_DLY ' pause for clock time
LOW CLOCK ' low clock
PAUSE DAT_DLY ' pause for last of data bit
NEXT INDEX ' get next data bit
LOW DOUT ' data out & clock pins idle low
PAUSE 50
GOTO MAIN
END
You may want to work out some type of synchronization between the two. I flipped on
power to the receiving end just before the transmitter to synch-up.


DEFINE OSC 20 ' 18F2431 @ 20MHz receiving
DEFINE LOADER_USED 1

SYMBOL DIN = PORTB.0 ' data input pin
SYMBOL CLOCK = PORTB.1 ' clock output pin

IDLE CON 0 ' idle logic state
ACTIVE CON 1 ' active clock logic state

PACKET VAR WORD ' 16-bit data packet
INDEX VAR BYTE ' data packet bit index pointer/loop counter

TRISB = %11111111 ' data and clock both inputs
PAUSE 3000

MAIN:
PACKET = 0 ' clear data packet

RCV:
FOR INDEX = 15 TO 0 STEP-1 ' receive msb first
WHILE CLOCK = IDLE ' wait for active clock
WEND
PACKET.0[INDEX]=DIN ' place data bit on RB0 in packet
WHILE CLOCK = ACTIVE ' wait for clock to return to idle state
WEND
NEXT INDEX ' get next data bit
HSEROUT [HEX4 PACKET,13,10] ' show value received
GOTO MAIN
END
You could probably use SHIFTOUT and SHIFTIN too, but if you need full control of data and
clock rates, something like this should give you the extra flexibility.

BobEdge
- 23rd August 2007, 11:48
Thanks very much Bruce that worked a treat. Now if I can just get the chip to send the data to the DAC im in busyness.

Regards
Bob...