Header file for use with the 68HC11 Serial Peripheral Interface


/* Header file for use with HC11 Serial Peripheral Interface */

/* Function prototypes for using SPI */

void setup_spi(unsigned int spi_control);
void spi_putchar(unsigned char c);
unsigned char spi_getchar(void);
void spi_put_bytes(unsigned char *s, int n);
void spi_get_byte_bytes(unsigned char *s, int n);


/* Definition of bits in SPCR (SPI Control Register) */
#define SPI_INT_ENABLE_BIT 0x80
#define SPI_ENABLE_BIT     0x40
#define SPI_DWOM_BIT       0x20
#define SPI_MASTER_BIT     0x10
#define SPI_CPOL_BIT       0x08
#define SPI_CPHASE_BIT     0x04
#define SPI_SPR1_BIT       0x02
#define SPI_SPR0_BIT       0x01

/* Definition of bits in SPSR (SPI Status Register) */
#define SPI_FLAG_BIT       0x80
#define SPI_WCOL_BIT       0x40
#define SPI_MODF_BIT       0x10


/* Definition of bits in control word used by spi_setup() */
#define SPI_ENABLE         0x0001
#define SPI_DISABLE        0x0002
#define SPI_INT_ENABLE     0x0004
#define SPI_INT_DISABLE    0x0008
#define SPI_MASTER         0x0010
#define SPI_SLAVE          0x0020
#define SPI_CPOL_ZERO      0x0040
#define SPI_CPOL_ONE       0x0080
#define SPI_CPHASE_ZERO    0x0100
#define SPI_CPHASE_ONE     0x0200
#define SPI_CSPEED_MASK    0xF000
#define SPI_CLOCK_E_DIV2   0x1000
#define SPI_CLOCK_E_DIV4   0x2000
#define SPI_CLOCK_E_DIV16  0x4000
#define SPI_CLOCK_E_DIV32  0x8000

/*
 * To add the above functions (defined in the file spi.c) to libhc11.a:
 *
 *     icc11 -c spi.c
 *     ilib -a libhc11.a spi.o
 *
 * To compile a program which uses the functions (e.g., spi_ex.c), include the
 * header file "spi.h" and give the following command:
 *
 *     icc11 -l spi_ex.c -l libhc11.a -b:text=0x2000 -bdata:0x0100 -d_stack:0x9fff
 *
 */