00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00013 00014 /* Copyright (c) 2007, 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 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED 00030 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00031 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND 00032 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, 00033 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00034 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00035 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00036 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00037 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00038 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 */ 00040 00041 /*_____ I N C L U D E S ____________________________________________________*/ 00042 #include "config.h" 00043 //#include "lib_mem/spi\spi_lib.h" 00044 #include "lib_mcu/spi/spi_lib.h" 00045 00046 00047 /*_____ G L O B A L D E F I N I T I O N _________________________________*/ 00048 00049 /*_____ D E F I N I T I O N ________________________________________________*/ 00050 00051 /*_____ M A C R O S ________________________________________________________*/ 00052 00053 bit spi_test_hit (void) 00054 { 00055 return Spi_rx_ready(); 00056 } 00057 00058 00059 bit spi_init (spi_cf_t config) 00060 { 00061 Spi_init_bus(); 00062 if(config == SPI_MASTER){Spi_select_master_mode();} 00063 else {Spi_select_slave_mode();} 00064 00065 Spi_hw_init(SPI_CONFIG); 00066 Spi_set_doublespeed();/*to delete if wished*/ 00067 Spi_enable(); 00068 return TRUE; 00069 } 00070 00071 00072 char spi_putchar (char ch) 00073 { 00074 Spi_send_byte(ch); 00075 while(!Spi_tx_ready()); 00076 return ch; 00077 } 00078 00079 00080 00081 char spi_getchar (void) 00082 { 00083 00084 register char c; 00085 00086 while(!Spi_rx_ready()); 00087 c = Spi_get_byte(); 00088 return c; 00089 } 00090 00091 void SPI_Transmit_Master(char cData) 00092 { 00093 /* Wait for transmission complete */ 00094 Spi_wait_eot(); 00095 /* Start new transmission */ 00096 Spi_send_byte(cData); 00097 00098 } 00099 00100 char spi_rw(char tx) 00101 { 00102 Spi_send_byte(tx); 00103 return Spi_read_data(); 00104 } 00105 00106 00107