EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

HCS12 SPI Problem

Started by johann_zimmermann June 29, 2005
Hello,

I use 9s12dg256B, CW3.1 pro compiler,

void SPI1_SendChar(unsigned char Chr)
{
while(!SPI1SR_SPTEF);
SPI1DR = Chr;
}

void SPI1_Init(void)
{
SPI1BR = 0;
// CR2 Init
SPI1CR2 = 0;
// CR1 Init
SPI1CR1 = 0;
// SPI 1 Master/Slave Mode Select Bit
SPI1CR1_MSTR = 1;

// SPI 1 System Enable Bit
SPI1CR1_SPE = 1;
}

An idea why it does not work ?

Thank you

Johann


Hi,

Do you really want this

while(!SPI1SR_SPTEF);
SPI1DR = Chr;
Or did you mean

while(!SPI1SR_SPTEF){ SPI1DR = Chr;}

Ron

--
Ron Liechty (MW Ron)
Ombudsman, Manager FOCUS team
ron.liechty@ron....

-----Original Message-----
From: 68HC12@68HC... [mailto:68HC12@68HC...] On Behalf
Of johann_zimmermann
Sent: Wednesday, June 29, 2005 12:30 PM
To: 68HC12@68HC...
Subject: [68HC12] HCS12 SPI Problem

Hello,

I use 9s12dg256B, CW3.1 pro compiler,

void SPI1_SendChar(unsigned char Chr)
{
while(!SPI1SR_SPTEF);
SPI1DR = Chr;
}

void SPI1_Init(void)
{
SPI1BR = 0;
// CR2 Init
SPI1CR2 = 0;
// CR1 Init
SPI1CR1 = 0;
// SPI 1 Master/Slave Mode Select Bit
SPI1CR1_MSTR = 1;

// SPI 1 System Enable Bit
SPI1CR1_SPE = 1;
}

An idea why it does not work ?

Thank you

Johann Yahoo! Groups Links


Johann,

> void SPI1_Init(void)
> {
> SPI1BR = 0;
> // CR2 Init
> SPI1CR2 = 0;
> // CR1 Init
> SPI1CR1 = 0;
> // SPI 1 Master/Slave Mode Select Bit
> SPI1CR1_MSTR = 1;
>
> // SPI 1 System Enable Bit
> SPI1CR1_SPE = 1;
> }

you would at least want to enable your SPI interface
(bit 6 of SPIXCR1; 0x40) if not Master as well (bit 4
of SPIXCR1; 0x10).

Also, what clock are you running at?
Your baudrate divider is set to 2, might be little
too much with a faster clock and slower peripherals.

> void SPI1_SendChar(unsigned char Chr)
> {
> while(!SPI1SR_SPTEF);
> SPI1DR = Chr;
> }

this seems to be ok, though!

hth
-uwe


Thank for your responses...
I have forgotten

// routing to Port H
MODRR_MODRR5 = 1;
----- Original Message -----
From: Uwe Arends
To: 68HC12@68HC...
Sent: Wednesday, June 29, 2005 6:55 PM
Subject: Re: [68HC12] HCS12 SPI Problem Johann,

> void SPI1_Init(void)
> {
> SPI1BR = 0;
> // CR2 Init
> SPI1CR2 = 0;
> // CR1 Init
> SPI1CR1 = 0;
> // SPI 1 Master/Slave Mode Select Bit
> SPI1CR1_MSTR = 1;
>
> // SPI 1 System Enable Bit
> SPI1CR1_SPE = 1;
> }

you would at least want to enable your SPI interface
(bit 6 of SPIXCR1; 0x40) if not Master as well (bit 4
of SPIXCR1; 0x10).

Also, what clock are you running at?
Your baudrate divider is set to 2, might be little
too much with a faster clock and slower peripherals.

> void SPI1_SendChar(unsigned char Chr)
> {
> while(!SPI1SR_SPTEF);
> SPI1DR = Chr;
> }

this seems to be ok, though!

hth
-uwe

------
YAHOO! GROUPS LINKS

a.. ------



Johann et al,
> > void SPI1_Init(void)
> > {
> > SPI1BR = 0;
> > // CR2 Init
> > SPI1CR2 = 0;
> > // CR1 Init
> > SPI1CR1 = 0;
> > // SPI 1 Master/Slave Mode Select Bit
> > SPI1CR1_MSTR = 1;
> >
> > // SPI 1 System Enable Bit
> > SPI1CR1_SPE = 1;
> > }
>
> you would at least want to enable your SPI interface
> (bit 6 of SPIXCR1; 0x40) if not Master as well (bit 4
> of SPIXCR1; 0x10).

Argh, I wish i could blame this on poor eyesight when it indeed
is a limitation of my mind.
Sorry for the noise!

-uwe



The 2024 Embedded Online Conference