Library for Serial Port Interface module: SPI

Copyright (c) 2003 Atmel

Library Usage

Package Description

Overview

This package provides low level routines to send and receive data with the SPI hardware controller of ATMEL AT89C51CC03 products.

Configuration

This driver does not need special configuration.

Before using the low level transmission format in master or slave mode, the functions spi_master_init() or spi_slave_init() should be called.

NOTES
-----
In master mode to transmit one or several (n) data bytes, the low level function
spi_transmit_byte(data) should be called n times and all transmission should be closed
with the spi_get_data() function.

Example when for a tree bytes spi transmission: spi_master_init(0,1,1,8); //SPI init CPOL=0, CPHA=1, SSDIS=1 bitrate=Fper/8 spi_transmit_byte(0xAA); spi_transmit_byte(0x55); spi_transmit_byte(0xAA); spi_get_data();

Package Summary

Constants



Global Variables



Macros



Functions

spi_get_data 
spi_interrupt 
spi_master_init 
spi_put_data 
spi_set_speed 
spi_slave_init 
spi_transmit_burst_it 
spi_transmit_burst_polling 
spi_transmit_byte 

Files List

Included Files

Constant Macros

Global Variables

Function Macros

Functions

spi_get_data

unsigned char spi_get_data (  )  

Return the content of the spi data register

return: byte received 

Note

This function performs an active wait polling


spi_interrupt

void spi_interrupt ( void )  interrupt IRQ_SPI 

spi - interruption program for serial transmission ( Master and Slave mode )

*spi_string_ptr: the string which must be send
spi_nb_data: number of data to send
return: none


spi_master_init

void spi_master_init ( bit cpol ,  bit cpha ,  bit ssdis , Uchar speed )  

Initialize the spi module in master mode

cpol: bit CPOL value
cpha: bit CPHA value
ssdis: bit SSDIS value
speed: Uchar spi speed ratio transmission Vs Fper 
return:   none

Example

spi_master_init(0,1,1,4); // init spi in mater mode with CPOL=0, CPHA=1,
// SSDIS=1 and bitrate=Fper/4

spi_put_data

void spi_put_data (  unsigned char to_transmit )  

Send a data byte to the spi interface

return: none

Note

This function should be use in spi slave mode to load spi data register with the next data to be transmited in slave mode


spi_set_speed

bit spi_set_speed  ( unsigned char ratio )  

Configure the baud rate of the spi, set CR2, CR1, CR0

return: bit: status  

Note

This function is use only in spi master mode


spi_slave_init

void spi_slave_init ( bit cpol ,  bit cpha ,  bit ssdis )  

Initialize the spi module in slave mode

cpol: bit CPOL value
cpha: bit CPHA value
ssdis: bit SSDIS value
return:   none

Example

spi_master_init(0,1,1); // init spi in mater mode with CPOL=0, CPHA=1, SSDIS=1

spi_transmit_burst_it

bit spi_transmit_burst_it  ( Uchar  * string_ptr ,  Uchar data_nb )  

Initialize an spi tranfert in interrupt mode Works in interrupt mode If a current transfert is on going, the function returns '0'

*string_ptr: the string which must be send
data_nb: number of data to send
return: bit

Note

This function can be used in slave or master mode


spi_transmit_burst_polling

void spi_transmit_burst_polling (  unsigned char   * ptr_buf ,  unsigned char nb_data )  

Transmit a data string throught the spi interface in polling mode

nb_data: number of data to send
return: none 

Note

This function performs an active wait polling


spi_transmit_byte

unsigned char spi_transmit_byte ( unsigned char tx_data )  

Send and receive a byte with spi interface

return:  byte received 

Note

If a current spi transfert is on going, the function performs an active wait polling on spi event. This function can be used both in slave and master mode