Unable to read SPI1DR

Started by marc...@gmail.com April 13, 2010
Hi,

I have a function that returns that value of the SPI data register (SPI1DR). I expect this function to return 0xFF if there is no other data coming in from the slave device. However, I only ever see 0x00 in this register even though I see the correct bit pattern on the MOSI pin. Does anyone have any thoughts? The receive function and my initialization are below. Also, I am using an MC9S12DG128 micro.

void InitSPI1()
{
char temp;
SPI1BR |= 7;
SPI1CR1 |= SPI1CR1_MSTR_MASK | SPI1CR1_SPE_MASK;
SPI1CR1 &= ~SPI1CR1_CPHA_MASK;
DDRP |= 0x08;
PTP |= 0x08;
DDRP &= ~0x10;
PPSP &= ~0x10;
PERP |= 0x10;
temp = SPI1DR;
}

static BYTE rcvr_spi (void)
{

while(!(SPI1SR & SPI1SR_SPTEF_MASK) )
;
SPI1DR =0xff;
while(!(SPI1SR & SPI1SR_SPIF_MASK) )
;
SPI_Response = SPI1DR;
return SPI_Response;

}

Thanks!
Why do you expect to read 0xFF from SPI1DR? To read 0xFF from SPI1DR, either
slave device should reply with 0xFF, or MISO should be pulled up or driven
high permanently.

Edward

----- Original Message -----
From:
To: <6...>
Sent: Tuesday, April 13, 2010 11:02 PM
Subject: [68HC12] Unable to read SPI1DR
> Hi,
>
> I have a function that returns that value of the SPI data register
> (SPI1DR). I expect this function to return 0xFF if there is no other data
> coming in from the slave device. However, I only ever see 0x00 in this
> register even though I see the correct bit pattern on the MOSI pin. Does
> anyone have any thoughts? The receive function and my initialization are
> below. Also, I am using an MC9S12DG128 micro.
>
> void InitSPI1()
> {
> char temp;
> SPI1BR |= 7;
> SPI1CR1 |= SPI1CR1_MSTR_MASK | SPI1CR1_SPE_MASK;
> SPI1CR1 &= ~SPI1CR1_CPHA_MASK;
> DDRP |= 0x08;
> PTP |= 0x08;
> DDRP &= ~0x10;
> PPSP &= ~0x10;
> PERP |= 0x10;
> temp = SPI1DR;
> }
>
> static BYTE rcvr_spi (void)
> {
>
> while(!(SPI1SR & SPI1SR_SPTEF_MASK) )
> ;
> SPI1DR =0xff;
> while(!(SPI1SR & SPI1SR_SPIF_MASK) )
> ;
> SPI_Response = SPI1DR;
> return SPI_Response;
>
> }
>
> Thanks!
>
I agree, it seems like a strange approach and isn't necessary per se. I've looked into the problem more and have come to the conclusion that it is purely a hardware issue - because some boards I have will work and others won't despite them apparently being identical. I haven't determined why this is yet, but in boards that do work I am able to read back values from SPI1DR that I have written in my user program (with our without a slave present) and, more importantly, read back data from the slave on MISO.

Anyways, I'm more concerned with pushing this forward from a firmware side than dealing with this unusual hardware issue. I've stripped everything that could possibly be an issue on a non-working board and left just the micro and I'm still unable to read back from SPI1DR. Since I inherited this project I'm not convinced these boards may not have been damaged in some way...

Thanks for your help!
--- In 6..., "Edward Karpicz" wrote:
>
> Why do you expect to read 0xFF from SPI1DR? To read 0xFF from SPI1DR, either
> slave device should reply with 0xFF, or MISO should be pulled up or driven
> high permanently.
>
> Edward
>
> ----- Original Message -----
> From:
> To: <6...>
> Sent: Tuesday, April 13, 2010 11:02 PM
> Subject: [68HC12] Unable to read SPI1DR
> > Hi,
> >
> > I have a function that returns that value of the SPI data register
> > (SPI1DR). I expect this function to return 0xFF if there is no other data
> > coming in from the slave device. However, I only ever see 0x00 in this
> > register even though I see the correct bit pattern on the MOSI pin. Does
> > anyone have any thoughts? The receive function and my initialization are
> > below. Also, I am using an MC9S12DG128 micro.
> >
> > void InitSPI1()
> > {
> > char temp;
> > SPI1BR |= 7;
> > SPI1CR1 |= SPI1CR1_MSTR_MASK | SPI1CR1_SPE_MASK;
> > SPI1CR1 &= ~SPI1CR1_CPHA_MASK;
> > DDRP |= 0x08;
> > PTP |= 0x08;
> > DDRP &= ~0x10;
> > PPSP &= ~0x10;
> > PERP |= 0x10;
> > temp = SPI1DR;
> > }
> >
> > static BYTE rcvr_spi (void)
> > {
> >
> > while(!(SPI1SR & SPI1SR_SPTEF_MASK) )
> > ;
> > SPI1DR =0xff;
> > while(!(SPI1SR & SPI1SR_SPIF_MASK) )
> > ;
> > SPI_Response = SPI1DR;
> > return SPI_Response;
> >
> > }
> >
> > Thanks!
> >
> >
> >
> >
> >