Library for Serial Port Interface module: SPI |
Copyright (c) 2003 Atmel
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();
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
unsigned char spi_get_data ( ) |
Return the content of the spi data register
return: byte received |
This function performs an active wait polling
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 |
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 |
spi_master_init(0,1,1,4); // init spi in mater mode with CPOL=0, CPHA=1, // SSDIS=1 and bitrate=Fper/4
void spi_put_data ( unsigned char to_transmit ) |
Send a data byte to the spi interface
return: none |
This function should be use in spi slave mode to load spi data register with the next data to be transmited in slave mode
bit spi_set_speed ( unsigned char ratio ) |
Configure the baud rate of the spi, set CR2, CR1, CR0
return: bit: status |
This function is use only in spi master mode
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 |
spi_master_init(0,1,1); // init spi in mater mode with CPOL=0, CPHA=1, SSDIS=1
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 |
This function can be used in slave or master mode
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 |
This function performs an active wait polling
unsigned char spi_transmit_byte ( unsigned char tx_data ) |
Send and receive a byte with spi interface
return: byte received |
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