pic24_spi.c

00001 /*
00002  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
00003  * All rights reserved.
00004  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
00005  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
00006  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
00007  *
00008  * Permission to use, copy, modify, and distribute this software and its
00009  * documentation for any purpose, without fee, and without written agreement is
00010  * hereby granted, provided that the above copyright notice, the following
00011  * two paragraphs and the authors appear in all copies of this software.
00012  *
00013  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
00014  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00015  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
00016  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00017  *
00018  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00019  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00020  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00021  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
00022  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
00023  *
00024  * Please maintain this header in its entirety when copying/modifying
00025  * these files.
00026  *
00027  *
00028  */
00029 
00030 #include "pic24_all.h"
00031 
00032 // Only include if this UART exists.
00033 #if (NUM_SPI_MODS >= 1)
00034 
00035 // Documentation for this file. If the \file tag is not present,
00036 // this file will not be documented.
00037 // Note: place this comment below the #if NUM_I2C_MODS so Doxygen
00038 // will only see it once.
00047 //SPI Receive Overflow freezes the SPI module
00048 void checkRxErrorSPI1() {
00049   if (SPI1STATbits.SPIROV) {
00050     //clear the error
00051     SPI1STATbits.SPIROV = 0;
00052     reportError("SPI1 Receive Overflow\n");
00053   }
00054 }
00055 
00066 uint16 ioMasterSPI1(uint16 u16_c) {
00067   checkRxErrorSPI1();
00068   _SPI1IF = 0;      //clear interrupt flag since we are about to write new value
00069   SPI1BUF = u16_c;
00070   while (!_SPI1IF) { //wait for operation to complete
00071     doHeartbeat();
00072   };
00073   return(SPI1BUF);
00074 }
00075 
00076 #endif // #if (NUM_SPI_MODS >= 1)
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 /*
00087  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
00088  * All rights reserved.
00089  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
00090  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
00091  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
00092  *
00093  * Permission to use, copy, modify, and distribute this software and its
00094  * documentation for any purpose, without fee, and without written agreement is
00095  * hereby granted, provided that the above copyright notice, the following
00096  * two paragraphs and the authors appear in all copies of this software.
00097  *
00098  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
00099  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
00100  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
00101  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00102  *
00103  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
00104  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00105  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
00106  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
00107  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
00108  *
00109  * Please maintain this header in its entirety when copying/modifying
00110  * these files.
00111  *
00112  *
00113  */
00114 
00115 #include "pic24_all.h"
00116 
00117 // Only include if this UART exists.
00118 #if (NUM_SPI_MODS >= 2)
00119 
00120 // Documentation for this file. If the \file tag is not present,
00121 // this file will not be documented.
00122 // Note: place this comment below the #if NUM_I2C_MODS so Doxygen
00123 // will only see it once.
00132 //SPI Receive Overflow freezes the SPI module
00133 void checkRxErrorSPI2() {
00134   if (SPI2STATbits.SPIROV) {
00135     //clear the error
00136     SPI2STATbits.SPIROV = 0;
00137     reportError("SPI2 Receive Overflow\n");
00138   }
00139 }
00140 
00151 uint16 ioMasterSPI2(uint16 u16_c) {
00152   checkRxErrorSPI2();
00153   _SPI2IF = 0;      //clear interrupt flag since we are about to write new value
00154   SPI2BUF = u16_c;
00155   while (!_SPI2IF) { //wait for operation to complete
00156     doHeartbeat();
00157   };
00158   return(SPI2BUF);
00159 }
00160 
00161 #endif // #if (NUM_SPI_MODS >= 2)
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 

Generated on Mon Oct 18 07:40:46 2010 for Python-on-a-chip by  doxygen 1.5.9