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

- File List
- Globals

# spi_lib.c

Go to the documentation of this file.

    00001 /*This file is prepared for Doxygen automatic documentation generation.*/
    00013
    00014 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
    00015  *
    00016  * Redistribution and use in source and binary forms, with or without
    00017  * modification, are permitted provided that the following conditions are met:
    00018  *
    00019  * 1. Redistributions of source code must retain the above copyright notice,
    00020  * this list of conditions and the following disclaimer.
    00021  *
    00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
    00023  * this list of conditions and the following disclaimer in the documentation
    00024  * and/or other materials provided with the distribution.
    00025  *
    00026  * 3. The name of Atmel may not be used to endorse or promote products derived
    00027  * from this software without specific prior written permission.
    00028  *
    00029  * 4. This software may only be redistributed and used in connection with an Atmel
    00030  * AVR product.
    00031  *
    00032  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
    00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
    00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00042  */
    00043
    00044 //_____ I N C L U D E S ____________________________________________________
    00045
    00046 #include "config.h"
    00047 #include "spi_lib.h"
    00048
    00049
    00050 //_____ D E F I N I T I O N ________________________________________________
    00051
    00052
    00062 bit spi_init_master( U8 mode, U8 rate, Bool b_msb_first )
    00063 {
    00064    Spi_select_master();
    00065    Spi_set_mode(mode);
    00066    Spi_set_rate(rate);
    00067    if( b_msb_first )
    00068    {
    00069       Spi_set_msbfirst();
    00070    }else{
    00071       Spi_set_lsbfirst();
    00072    }
    00073    Spi_init_bus();
    00074    Spi_enable();
    00075    return TRUE;
    00076 }
    00077
    00078
    00088 bit spi_init_slave( U8 mode, U8 rate, Bool b_msb_first )
    00089 {
    00090    Spi_select_slave();
    00091    Spi_set_mode(mode);
    00092    Spi_set_rate(rate);
    00093    if( b_msb_first )
    00094    {
    00095       Spi_set_msbfirst();
    00096    }else{
    00097       Spi_set_lsbfirst();
    00098    }
    00099    Spi_init_bus();
    00100    Spi_enable();
    00101    return TRUE;
    00102 }
    00103
    00104
    00111 char spi_putchar (char ch)
    00112 {
    00113    Spi_write_data(ch);
    00114    while(!Spi_tx_ready());
    00115    return ch;
    00116 }
    00117
    00118
    00123 bit spi_test_hit (void)
    00124 {
    00125    return Spi_rx_ready();
    00126 }
    00127
    00128
    00133 char spi_getchar (void)
    00134 {
    00135    register char c;
    00136    while(!Spi_rx_ready());
    00137    c = Spi_read_data();
    00138    return c;
    00139 }
    00140
    00141
    00146 void  spi_transmit_master(char cData)
    00147 {
    00148    // Wait for transmission complete
    00149    Spi_wait_eot();
    00150    // Start new transmission
    00151    Spi_write_data(cData);
    00152 }
    00153
    00154
    00161 char spi_rw(char tx)
    00162 {
    00163    Spi_write_data(tx);
    00164    return Spi_read_data();
    00165 }
    00166