SPI on S12E128

Started by Andrew Lohmann's New Email Server March 12, 2004
Hi,

My SPI interface hooks up waiting for (SPI.spisr.byte & SPIF) to clear. The software I am trying to run a very simple spi interface base on:-
// File: S12_SPI.C - V1.00
// Rem.: The ACPRD Project Page on the Web -> http://hc12web.de/acprd

I think that was from the Motorola alarm control pannel, And it is not interrupt driven. Can anyone suggest a solution? Andrew Lohmann AIIE
Design Engineer

PLEASE NOTE NEW EMAIL ADDRESS IS: Bellingham + Stanley Ltd.
Longfield Road, Tunbridge Wells, Kent, TN2 3EY, England.
Tel: +44 (0) 1892 500400
Fax: +44 (0) 1892 543115
Website: www.bs-ltd.com




This is small routine I wrote for the E128 SPI. It does not fully
utilize the SPI but it is interrupt driven.

;Spi initialization variables
spi_mask1 equ %01011100 ;SPE,MSTR=1, SWOM=0,
CPOL,CPHA=1
spi_mask2 equ %11100000 ;Bit 7,6,5=1 the rest=0

spi_baud1 equ %00000000 ;4.0 Mhz
spi_baud2 equ %00000001 ;2.0 Mhz
spi_baud3 equ %00000010 ;1.0 Mhz
spi_baud4 equ %00000011 ;0.5 Mhz
spi_baud5 equ %00000100 ;250 kHz
spi_baud6 equ %00000101 ;125 kHz
spi_baud7 equ %00000110 ;62.5 kHz
spi_baud8 equ %00000111 ;31.3 kHz

spi_baud9 equ %00100010 ;1 Mhz
spi_baud10 equ %00100011 ;

SPIF equ %10000000 ;flag after the 8th clock
SPIE equ %10000000 ;Spi interrupt enable
LSBF equ %00000001 ;SPI LSB First enable
;slave_select equ %10000000 ;Chip select for the sound
chip

SSPIN equ %10000000 ;Chip select for the sound
chip

disp_delay
bset DDRM,%11 ;Initialize Port M

bset PORTS,SSPIN ;inititalize port to 1
movb #spi_mask2,DDRS
movb #spi_mask1,SPI0CR1 ;SPE,MSTR=1, SWOM=0,
CPOL,CPHA=1
bclr SPI0CR2,%01 ;SPC0=0, Normal mode

movb #spi_baud7,SPI0BR ;set clock to 1 Mhz

ldaa SPI0SR ;clear flag and buffer
ldaa SPI0DR

clr spi_int_flag
rts

dump_spi_data
pshb

ldab SPI0SR ;clear flag and buffer
ldab SPI0DR

clr spi_int_flag ;clear for next spi dump
bset SPI0CR1,SPIE ;Enable spi interrupt
staa SPI0DR ;dump to spi to start playback

brclr spi_int_flag,$01,* ;wait here for spi int
bclr SPI0CR1,SPIE ;Disable spi interrutp
clr spi_int_flag ;clear for next spi dump

pulb
rts spi_int
bset spi_int_flag,%00000001 ;Set flag

ldaa SPI0SR
ldaa SPI0DR

rti

--- In , "Andrew Lohmann's New Email Server"
<andrew.lohmann@b...> wrote:
> Hi,
>
> My SPI interface hooks up waiting for (SPI.spisr.byte & SPIF) to
clear. The software I am trying to run a very simple spi interface
base on:-
> // File: S12_SPI.C - V1.00
> // Rem.: The ACPRD Project Page on the Web ->
http://hc12web.de/acprd
>
> I think that was from the Motorola alarm control pannel, And it is
not interrupt driven. Can anyone suggest a solution?
>
>
> Andrew Lohmann AIIE
> Design Engineer
>
> PLEASE NOTE NEW EMAIL ADDRESS IS:
> andrew.lohmann@b...
>
> Bellingham + Stanley Ltd.
> Longfield Road, Tunbridge Wells, Kent, TN2 3EY, England.
> Tel: +44 (0) 1892 500400
> Fax: +44 (0) 1892 543115
> Website: www.bs-ltd.com




Correction:
Hi,

My SPI interface hooks up waiting for (SPI.spisr.byte & SPIF) to become true. The software I am trying to run a very simple spi interface base on:-
// File: S12_SPI.C - V1.00
// Rem.: The ACPRD Project Page on the Web -> http://hc12web.de/acprd

I think that was from the Motorola alarm control pannel, And it is not interrupt driven. Can anyone suggest a solution? Andrew Lohmann AIIE
Design Engineer

PLEASE NOTE NEW EMAIL ADDRESS IS: Bellingham + Stanley Ltd.
Longfield Road, Tunbridge Wells, Kent, TN2 3EY, England.
Tel: +44 (0) 1892 500400
Fax: +44 (0) 1892 543115
Website: www.bs-ltd.com --------------------To learn more about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu
o learn more about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu
--------

Yahoo! Groups Links

a.. To




Try this code in your init routine...
LDAA SPI0SR ;ensure MODF flag cleared
LDAA SPI0DR ;ensure SPRF flag cleared

bruce
_________________
--- In , "Andrew Lohmann's New Email Server"
<andrew.lohmann@b...> wrote:
> Correction:
> Hi,
>
> My SPI interface hooks up waiting for (SPI.spisr.byte & SPIF) to
become true. The software I am trying to run a very simple spi
interface base on:-
> // File: S12_SPI.C - V1.00
> // Rem.: The ACPRD Project Page on the Web -> http://hc12web.de/acprd
>
> I think that was from the Motorola alarm control pannel, And it is
not interrupt driven. Can anyone suggest a solution?
>
>
> Andrew Lohmann AIIE
> Design Engineer
>
> PLEASE NOTE NEW EMAIL ADDRESS IS:
> andrew.lohmann@b...
>
> Bellingham + Stanley Ltd.
> Longfield Road, Tunbridge Wells, Kent, TN2 3EY, England.
> Tel: +44 (0) 1892 500400
> Fax: +44 (0) 1892 543115
> Website: www.bs-ltd.com > --------------------To learn
more about Motorola Microcontrollers, please visit
> http://www.motorola.com/mcu
> o learn more about Motorola Microcontrollers, please visit
> http://www.motorola.com/mcu >
>
--------
>
> Yahoo! Groups Links
>
> a.. To >
>




If you check at those registers with a debugger it might hang the
program, sence SPIF is cleared by reading it, followed by a read
access to SPIDR.

--- In , "Andrew Lohmann's New Email Server"
<andrew.lohmann@b...> wrote:
> Hi,
>
> My SPI interface hooks up waiting for (SPI.spisr.byte & SPIF) to
clear. The software I am trying to run a very simple spi interface
base on:-
> // File: S12_SPI.C - V1.00
> // Rem.: The ACPRD Project Page on the Web -> http://hc12web.
de/acprd
>
> I think that was from the Motorola alarm control pannel, And it is
not interrupt driven. Can anyone suggest a solution?
>
>
> Andrew Lohmann AIIE
> Design Engineer
>
> PLEASE NOTE NEW EMAIL ADDRESS IS:
> andrew.lohmann@b...
>
> Bellingham + Stanley Ltd.
> Longfield Road, Tunbridge Wells, Kent, TN2 3EY, England.
> Tel: +44 (0) 1892 500400
> Fax: +44 (0) 1892 543115
> Website: www.bs-ltd.com




Thanks all, //Try this code in your init routine... AL 15-03-04
Dummy = SPI.spisr.byte; // ensure MODF flag cleared
Dummy = SPI.spidr.byte; // ensure SPRF flag cleared

did it!

Andrew Lohmann AIIE
Design Engineer

PLEASE NOTE NEW EMAIL ADDRESS IS: Bellingham + Stanley Ltd.
Longfield Road, Tunbridge Wells, Kent, TN2 3EY, England.
Tel: +44 (0) 1892 500400
Fax: +44 (0) 1892 543115
Website: www.bs-ltd.com

----- Original Message -----
From: Daniel Lundin
To:
Sent: Monday, March 15, 2004 7:22 AM
Subject: [68HC12] Re: SPI on S12E128 If you check at those registers with a debugger it might hang the
program, sence SPIF is cleared by reading it, followed by a read
access to SPIDR.

--- In , "Andrew Lohmann's New Email Server"
<andrew.lohmann@b...> wrote:
> Hi,
>
> My SPI interface hooks up waiting for (SPI.spisr.byte & SPIF) to
clear. The software I am trying to run a very simple spi interface
base on:-
> // File: S12_SPI.C - V1.00
> // Rem.: The ACPRD Project Page on the Web -> http://hc12web.
de/acprd
>
> I think that was from the Motorola alarm control pannel, And it is
not interrupt driven. Can anyone suggest a solution?
>
>
> Andrew Lohmann AIIE
> Design Engineer
>
> PLEASE NOTE NEW EMAIL ADDRESS IS:
> andrew.lohmann@b...
>
> Bellingham + Stanley Ltd.
> Longfield Road, Tunbridge Wells, Kent, TN2 3EY, England.
> Tel: +44 (0) 1892 500400
> Fax: +44 (0) 1892 543115
> Website: www.bs-ltd.com
--------------------To learn more about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu
o learn more about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu

------
Yahoo! Groups Links

a.. To