spi_lib.c File Reference

,vThis file provides a minimal funtion set for the SPI More...

#include "config.h"
#include "lib_mcu/spi/spi_lib.h"

Include dependency graph for spi_lib.c:

Go to the source code of this file.

Functions

bit spi_test_hit (void)
 This function checks if a bytes has been received on the SPI.
bit spi_init (spi_cf_t config)
 This function configures the SPI controller:
  1. MASTER or SLAVE
  2. bit timing
  3. enable the controller.

char spi_putchar (char ch)
 This function sends a byte on the SPI.
char spi_getchar (void)
 This function reads a byte on the SPI.
void SPI_Transmit_Master (char cData)
 SPI Make the transmission possible.


Detailed Description

,vThis file provides a minimal funtion set for the SPI

Copyright (c) 2004 Atmel.

Please read file license.txt for copyright notice.

Version:
1.7 at90usb162-cdc-1_0_1
Todo:
Bug:

Definition in file spi_lib.c.


Function Documentation

bit spi_test_hit ( void   ) 

This function checks if a bytes has been received on the SPI.

Returns:
TRUE if byte received

Definition at line 28 of file spi_lib.c.

References Spi_rx_ready.

00029 {
00030 return Spi_rx_ready();
00031 }

bit spi_init ( spi_cf_t  config  ) 

This function configures the SPI controller:

  1. MASTER or SLAVE
  2. bit timing
  3. enable the controller.

Parameters:
configuration of the node (MASTER or SLAVE).
configuration of mode (SPI_MASTER_MODE_0...SPI_MASTER_MODE_3 or SPI_SLAVE_MODE_0...SPI_SLAVE_MODE_3).
Returns:
status of the init:
  1. TRUE
  2. FALSE
Precondition:
before calling this function some declaration must be define in config.h:
  • SPI_CONFIG select the prescaler, CPHA leading, CPOL LOW, LSB first.

Definition at line 34 of file spi_lib.c.

References Spi_enable, Spi_hw_init, Spi_init_bus, SPI_MASTER, Spi_select_master_mode, Spi_select_slave_mode, Spi_set_doublespeed, and TRUE.

00035 {
00036   Spi_init_bus();
00037   if(config == SPI_MASTER){Spi_select_master_mode();}
00038   else                    {Spi_select_slave_mode();}
00039 
00040   Spi_hw_init(SPI_CONFIG);
00041   Spi_set_doublespeed();/*to delete if wished*/
00042   Spi_enable();
00043 
00044 
00045   return TRUE;
00046 }

char spi_putchar ( char  uc_wr_byte  ) 

This function sends a byte on the SPI.

Parameters:
character to send on the SPI.
Returns:
character sent

Definition at line 49 of file spi_lib.c.

References Spi_send_byte, and Spi_tx_ready.

00050 {
00051 Spi_send_byte(ch);
00052 while(!Spi_tx_ready());
00053 return ch;
00054 }

char spi_getchar ( void   ) 

This function reads a byte on the SPI.

Returns:
character read

Definition at line 58 of file spi_lib.c.

References Spi_get_byte, and Spi_rx_ready.

00059 {
00060 
00061 register char c;
00062 
00063 while(!Spi_rx_ready());
00064 c = Spi_get_byte();
00065 return c;
00066 }

void SPI_Transmit_Master ( char  cData  ) 

SPI Make the transmission possible.

Warning:
See SPI section in datasheet
Parameters:
(char cData)
Returns:
nothing.

Definition at line 68 of file spi_lib.c.

References Spi_send_byte, and Spi_wait_eot.

00069 {
00070   /* Wait for transmission complete */
00071 Spi_wait_eot();
00072   /* Start new transmission */
00073 Spi_send_byte(cData);
00074 
00075 }


Generated on Fri Jun 15 14:15:41 2007 for Atmel by  doxygen 1.5.1-p1