- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

# spi_lib.h File Reference

,vThis file containsSPI lib header file. More...

`#include "lib_mcu/spi/spi_drv.h"`

Include dependency graph for spi_lib.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Enumerations
enum | spi_cf_t { SPI_MASTER, SPI_SLAVE }
| This enumeration allows to define a MASTER or SLAVE configuration. More...
## Functions
bit | spi_init (spi_cf_t config)
| This function configures the SPI controller: MASTER or SLAVE bit timing enable the controller.
char | spi_putchar (char uc_wr_byte)
| This function sends a byte on the SPI.
bit | spi_test_hit (void)
| This function checks if a bytes has been received 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 containsSPI lib header file.

Copyright (c) 2004 Atmel.

Please read file license.txt for copyright notice.

Version:
  1.5 at90usb162-2enum-mouse_ms-1_0_1

Todo:

Bug:

Definition in file spi_lib.h.

## Enumeration Type Documentation

enum spi_cf_t

This enumeration allows to define a MASTER or SLAVE configuration.

Enumerator:

  SPI_MASTER |
  SPI_SLAVE |

Definition at line 35 of file spi_lib.h.

    00035 {SPI_MASTER, SPI_SLAVE} spi_cf_t;

## Function Documentation

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_CONFIG, 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 }

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 }

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 }