Pb with SPI1SR and SPIF

Started by Pascal October 5, 2005


Hello,

I have this code for spi.

BYTE WriteSPI1Byte(BYTE abyte)
{
//Caractere dans le BufCardMem SPI
SPI1DRyte;
//Attend le transfert des donns
while((SPI1SR&SPIF)==0);
//retourne la valeur renvoy par l'esclave
return(SPI1DR);
} My problem is that if i have no spi slave SPI1SR&SPIF is always 0 and my program is frozen.

If i put my slave when SPI1DRyte then SPIF=1 in SPI1SR register.

I don't undersand why because SPIF should be one after 8 clocks cycle. It is not depending of the slave??

Here is the initialization of my spi

//Initialisatin du mode SPI en maitre
void InitSPI1(void)
{
BYTE val;

//assigne le port H en spi
MODRR=0x20;
//Vitesse de la liaison SPI 125 KHz
SPI1BR=5;
//mode maitre CPHA et CPOL=0;
SPI1CR1=MSTR;
SPI1CR2 = BIDIROE|SPISWAI;
//Efface les valeurs dans ces registres
val=SPI1SR;
val=SPI1DR;
//active la spi
SPI1CR1=SPI1CR1|SPE;
}

Thanks for help

Regards


Hi again.

I have solved my problem

Regards
----- Original Message -----
From: Pascal
To: 68HC12@68HC...
Sent: Wednesday, October 05, 2005 6:53 PM
Subject: [68HC12] Pb with SPI1SR and SPIF

Hello,

I have this code for spi.

BYTE WriteSPI1Byte(BYTE abyte)
{
//Caractere dans le BufCardMem SPI
SPI1DRyte;
//Attend le transfert des donns
while((SPI1SR&SPIF)==0);
//retourne la valeur renvoy par l'esclave
return(SPI1DR);
} My problem is that if i have no spi slave SPI1SR&SPIF is always 0 and my program is frozen.

If i put my slave when SPI1DRyte then SPIF=1 in SPI1SR register.

I don't undersand why because SPIF should be one after 8 clocks cycle. It is not depending of the slave??

Here is the initialization of my spi

//Initialisatin du mode SPI en maitre
void InitSPI1(void)
{
BYTE val;

//assigne le port H en spi
MODRR=0x20;
//Vitesse de la liaison SPI 125 KHz
SPI1BR=5;
//mode maitre CPHA et CPOL=0;
SPI1CR1=MSTR;
SPI1CR2 = BIDIROE|SPISWAI;
//Efface les valeurs dans ces registres
val=SPI1SR;
val=SPI1DR;
//active la spi
SPI1CR1=SPI1CR1|SPE;
}

Thanks for help

Regards
------
YAHOO! GROUPS LINKS

a.. ------


Good !
but what was the fix?
PL

At 11:15 AM 6/10/2005 +0200, you wrote:
>Hi again.
>
>I have solved my problem
>
>Regards
> ----- Original Message -----
> From: Pascal
> To: 68HC12@68HC...
> Sent: Wednesday, October 05, 2005 6:53 PM
> Subject: [68HC12] Pb with SPI1SR and SPIF >
>
> Hello,
>
> I have this code for spi.
>
> BYTE WriteSPI1Byte(BYTE abyte)
> {
> //Caractere dans le BufCardMem SPI
> SPI1DRyte;
> //Attend le transfert des donns
> while((SPI1SR&SPIF)==0);
> //retourne la valeur renvoy par l'esclave
> return(SPI1DR);
> } > My problem is that if i have no spi slave SPI1SR&SPIF is always 0 and
> my program is frozen.
>
> If i put my slave when SPI1DRyte then SPIF=1 in SPI1SR register.
>
> I don't undersand why because SPIF should be one after 8 clocks cycle.
> It is not depending of the slave??
>
> Here is the initialization of my spi
>
> //Initialisatin du mode SPI en maitre
> void InitSPI1(void)
> {
> BYTE val;
>
> //assigne le port H en spi
> MODRR=0x20;
> //Vitesse de la liaison SPI 125 KHz
> SPI1BR=5;
> //mode maitre CPHA et CPOL=0;
> SPI1CR1=MSTR;
> SPI1CR2 = BIDIROE|SPISWAI;
> //Efface les valeurs dans ces registres
> val=SPI1SR;
> val=SPI1DR;
> //active la spi
> SPI1CR1=SPI1CR1|SPE;
> }
>
> Thanks for help
>
> Regards >
>------
> YAHOO! GROUPS LINKS
>
> a.. >------ >
>Yahoo! Groups Links >
>




Hi Peter,

I don't know exactly why it has been solved but it works good now.

I have a function initport()
In this function i do DDRJ=0xFF; ... DDRJ=0xFE; ...PIEJ=0x01; PPSJ=0;

PJ0=0 if the slave is here and 1 if not.

So with this code if the slave is not here. I have pb with the spi.

I erase DDRJ=0xFF in initport. And now It works very good.

I don't know really why...

Regards
----- Original Message -----
From: Peter Lissenburg
To: 68HC12@68HC...
Sent: Thursday, October 06, 2005 11:28 AM
Subject: Re: [68HC12] Pb with SPI1SR and SPIF Good !
but what was the fix?
PL

At 11:15 AM 6/10/2005 +0200, you wrote:
>Hi again.
>
>I have solved my problem
>
>Regards
> ----- Original Message -----
> From: Pascal
> To: 68HC12@68HC...
> Sent: Wednesday, October 05, 2005 6:53 PM
> Subject: [68HC12] Pb with SPI1SR and SPIF >
>
> Hello,
>
> I have this code for spi.
>
> BYTE WriteSPI1Byte(BYTE abyte)
> {
> //Caractere dans le BufCardMem SPI
> SPI1DRyte;
> //Attend le transfert des donns
> while((SPI1SR&SPIF)==0);
> //retourne la valeur renvoy par l'esclave
> return(SPI1DR);
> } > My problem is that if i have no spi slave SPI1SR&SPIF is always 0 and
> my program is frozen.
>
> If i put my slave when SPI1DRyte then SPIF=1 in SPI1SR register.
>
> I don't undersand why because SPIF should be one after 8 clocks cycle.
> It is not depending of the slave??
>
> Here is the initialization of my spi
>
> //Initialisatin du mode SPI en maitre
> void InitSPI1(void)
> {
> BYTE val;
>
> //assigne le port H en spi
> MODRR=0x20;
> //Vitesse de la liaison SPI 125 KHz
> SPI1BR=5;
> //mode maitre CPHA et CPOL=0;
> SPI1CR1=MSTR;
> SPI1CR2 = BIDIROE|SPISWAI;
> //Efface les valeurs dans ces registres
> val=SPI1SR;
> val=SPI1DR;
> //active la spi
> SPI1CR1=SPI1CR1|SPE;
> }
>
> Thanks for help
>
> Regards >
>------
> YAHOO! GROUPS LINKS
>
> a.. >------ >
>Yahoo! Groups Links >
>
------
YAHOO! GROUPS LINKS

a.. ------


Thanks.
The reason I asked is that I have also found this to be a problem. And like
you it also "goes away". Usually after much investigation and hair removal.

And I would really like to know why it happens.

Any others experience this?

It seems to be a bug in the chip, as there should not be any impediment, to
the successful completion of the SPI transfer from the master.

Peter L.
At 11:43 AM 6/10/2005 +0200, you wrote:
>Hi Peter,
>
>I don't know exactly why it has been solved but it works good now.
>
>I have a function initport()
>In this function i do DDRJ=0xFF; ... DDRJ=0xFE; ...PIEJ=0x01; PPSJ=0;
>
>PJ0=0 if the slave is here and 1 if not.
>
>So with this code if the slave is not here. I have pb with the spi.
>
>I erase DDRJ=0xFF in initport. And now It works very good.
>
>I don't know really why...
>
>Regards
> ----- Original Message -----
> From: Peter Lissenburg
> To: 68HC12@68HC...
> Sent: Thursday, October 06, 2005 11:28 AM
> Subject: Re: [68HC12] Pb with SPI1SR and SPIF > Good !
> but what was the fix?
> PL
>
> At 11:15 AM 6/10/2005 +0200, you wrote:
> >Hi again.
> >
> >I have solved my problem
> >
> >Regards
> > ----- Original Message -----
> > From: Pascal
> > To: 68HC12@68HC...
> > Sent: Wednesday, October 05, 2005 6:53 PM
> > Subject: [68HC12] Pb with SPI1SR and SPIF
> >
> >
> >
> >
> > Hello,
> >
> > I have this code for spi.
> >
> > BYTE WriteSPI1Byte(BYTE abyte)
> > {
> > //Caractere dans le BufCardMem SPI
> > SPI1DRyte;
> > //Attend le transfert des donns
> > while((SPI1SR&SPIF)==0);
> > //retourne la valeur renvoy par l'esclave
> > return(SPI1DR);
> > }
> >
> >
> > My problem is that if i have no spi slave SPI1SR&SPIF is always 0 and
> > my program is frozen.
> >
> > If i put my slave when SPI1DRyte then SPIF=1 in SPI1SR register.
> >
> > I don't undersand why because SPIF should be one after 8 clocks cycle.
> > It is not depending of the slave??
> >
> > Here is the initialization of my spi
> >
> > //Initialisatin du mode SPI en maitre
> > void InitSPI1(void)
> > {
> > BYTE val;
> >
> > //assigne le port H en spi
> > MODRR=0x20;
> > //Vitesse de la liaison SPI 125 KHz
> > SPI1BR=5;
> > //mode maitre CPHA et CPOL=0;
> > SPI1CR1=MSTR;
> > SPI1CR2 = BIDIROE|SPISWAI;
> > //Efface les valeurs dans ces registres
> > val=SPI1SR;
> > val=SPI1DR;
> > //active la spi
> > SPI1CR1=SPI1CR1|SPE;
> > }
> >
> > Thanks for help
> >
> > Regards
> >
> >
> >
> >
> >
> >
>
> >------
> > YAHOO! GROUPS LINKS
> >
> > a..
> >
> >
>
> >------
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >Yahoo! Groups Links
> >
> >
> >
> >
>------
> YAHOO! GROUPS LINKS
>
> a.. >------ >
>Yahoo! Groups Links >
>




Yes Peter you are right when you say "much investigation and hair removal" lool

Regards
----- Original Message -----
From: Peter Lissenburg
To: 68HC12@68HC...
Sent: Thursday, October 06, 2005 12:02 PM
Subject: Re: [68HC12] Pb with SPI1SR and SPIF Thanks.
The reason I asked is that I have also found this to be a problem. And like
you it also "goes away". Usually after much investigation and hair removal.

And I would really like to know why it happens.

Any others experience this?

It seems to be a bug in the chip, as there should not be any impediment, to
the successful completion of the SPI transfer from the master.

Peter L.
At 11:43 AM 6/10/2005 +0200, you wrote:
>Hi Peter,
>
>I don't know exactly why it has been solved but it works good now.
>
>I have a function initport()
>In this function i do DDRJ=0xFF; ... DDRJ=0xFE; ...PIEJ=0x01; PPSJ=0;
>
>PJ0=0 if the slave is here and 1 if not.
>
>So with this code if the slave is not here. I have pb with the spi.
>
>I erase DDRJ=0xFF in initport. And now It works very good.
>
>I don't know really why...
>
>Regards
> ----- Original Message -----
> From: Peter Lissenburg
> To: 68HC12@68HC...
> Sent: Thursday, October 06, 2005 11:28 AM
> Subject: Re: [68HC12] Pb with SPI1SR and SPIF > Good !
> but what was the fix?
> PL
>
> At 11:15 AM 6/10/2005 +0200, you wrote:
> >Hi again.
> >
> >I have solved my problem
> >
> >Regards
> > ----- Original Message -----
> > From: Pascal
> > To: 68HC12@68HC...
> > Sent: Wednesday, October 05, 2005 6:53 PM
> > Subject: [68HC12] Pb with SPI1SR and SPIF
> >
> >
> >
> >
> > Hello,
> >
> > I have this code for spi.
> >
> > BYTE WriteSPI1Byte(BYTE abyte)
> > {
> > //Caractere dans le BufCardMem SPI
> > SPI1DRyte;
> > //Attend le transfert des donns
> > while((SPI1SR&SPIF)==0);
> > //retourne la valeur renvoy par l'esclave
> > return(SPI1DR);
> > }
> >
> >
> > My problem is that if i have no spi slave SPI1SR&SPIF is always 0 and
> > my program is frozen.
> >
> > If i put my slave when SPI1DRyte then SPIF=1 in SPI1SR register.
> >
> > I don't undersand why because SPIF should be one after 8 clocks cycle.
> > It is not depending of the slave??
> >
> > Here is the initialization of my spi
> >
> > //Initialisatin du mode SPI en maitre
> > void InitSPI1(void)
> > {
> > BYTE val;
> >
> > //assigne le port H en spi
> > MODRR=0x20;
> > //Vitesse de la liaison SPI 125 KHz
> > SPI1BR=5;
> > //mode maitre CPHA et CPOL=0;
> > SPI1CR1=MSTR;
> > SPI1CR2 = BIDIROE|SPISWAI;
> > //Efface les valeurs dans ces registres
> > val=SPI1SR;
> > val=SPI1DR;
> > //active la spi
> > SPI1CR1=SPI1CR1|SPE;
> > }
> >
> > Thanks for help
> >
> > Regards
> >
> >
> >
> >
> >
> >
>
> >------
> > YAHOO! GROUPS LINKS
> >
> > a..
> >
> >
>
> >------
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >Yahoo! Groups Links
> >
> >
> >
> >
>------
> YAHOO! GROUPS LINKS
>
> a.. >------ >
>Yahoo! Groups Links >
>
------
YAHOO! GROUPS LINKS

a.. ------


--- In 68HC12@68HC..., Peter Lissenburg <peter@s...> wrote:
> Thanks.
> The reason I asked is that I have also found this to be a problem.
And like
> you it also "goes away". Usually after much investigation and hair
removal.
>
> And I would really like to know why it happens.
>
> Any others experience this?

I have experience with MC68HC12BC32 and SPI.

I have not, except that sometimes I don't realize what my code is
really doing. The simple theory is plain. In the simple master mode,
there is no difference to the master whether the slave is connected
or not. Just that MISO might be floating, so the input value is
undefined.

There is, however, a condition in some where I caused a MODF (Mode
Fault Flag) error while configuring for the mentioned simple master
mode. Before setting SPE, You need to ensure that SS (Slave Select
input) will not read 0 at any time MSTR is set. Since I don't use SS
as input, I simply set it as output before enabling the master SPI.
I can see how that could be the problem if you are not checking for
MODF, and you have your slave controlling SS. You should also read
any errata as the SPI can seem weird in it's actual function.

One thing I learned is that (at least in my HC12) I could not expect
SPIF to be set after setting SPE until after it sends the first
byte. That seems different than in SCI.