Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SPI, MSB first at pic, how to turn ???

213 views
Skip to first unread message

Ralf Stuber

unread,
Aug 16, 2004, 3:54:24 AM8/16/04
to
Hello,

at the moment I'm trying to connect a sensor via SPI to a PIC16C74.

After 2 days without luck I found my trouble is caused by reversed byte transfere.

PIC: MSB first, LSB last
Sensor: LSB first, MSB last

I must turn all bytes before writing to SSPBUF and after reading SSPBUF.

But this takes to many cycles for execution! (controller only 4MHz)


1. solution

RRL x,1
RRF y,1

RRL x,1
RRF y,1

RRL x,1
RRF y,1

RRL x,1
RRF y,1

RRL x,1
RRF y,1

RRL x,1
RRF y,1

RRL x,1
RRF y,1

RRL x,1
RRF y,1

2. solution

clrf y
btfss x,0
bsf y,7
btfss x,1
bsf y,6
btfss x,2
bsf y,5
btfss x,3
bsf y,4
btfss x,4
bsf y,3
btfss x,5
bsf y,2
btfss x,6
bsf y,1
btfss x,7
bsf y,0

Any idea to solve this problem with less cycles ????
No hidden config bit available to make reverse transmition ???

Thanks in advance.
Ralf

kyle

unread,
Aug 16, 2004, 5:55:36 PM8/16/04
to
Greetings,

r...@fto.de (Ralf Stuber) wrote in message news:<63ad86bb.04081...@posting.google.com>...


> Hello,
>
> at the moment I'm trying to connect a sensor via SPI to a PIC16C74.
>
> After 2 days without luck I found my trouble is caused by reversed byte transfere.
>
> PIC: MSB first, LSB last
> Sensor: LSB first, MSB last
>
> I must turn all bytes before writing to SSPBUF and after reading SSPBUF.

I'm not familiar with that chip, but I suppose you could always do the
SPI in software instead of using the built-in hardware bits. Then you
can control bit order.

Alternately, a lookup table but that's *a lot* of memory and not speed
up that much.

This is only taking 17 cycles, or 4us. How much faster do you expect
to make it?

0 new messages