00001
00002
00003
00004
00005
00006
00007
00008
00009
00015 #include "LPC214x.h"
00016 #include "type.h"
00017 #include "ssp.h"
00018
00019
00020 #define SSP_PINMASK 0x000003fc
00021 #define SSP_PINSEL 0x000002a8
00022
00023
00024
00025
00026
00027
00028
00029 void ssp_init(void)
00030 {
00031
00032
00033
00034 PINSEL1 = (PINSEL1 & ~SSP_PINMASK) | SSP_PINSEL;
00035
00036
00037 SSPCPSR = 2;
00038
00039
00040
00041
00042 SSPCR0 = (SSP_DATA_SIZE(8) | SSP_FRAME_FORMAT_SPI);
00043 SSPCR1 = SSP_SSE;
00044 }
00045
00046
00047 static unsigned char dummyReader;
00048
00049 void ssp_put_byte(uint8 ch)
00050 {
00051
00052 SSPDR = (REG16) ch;
00053 while (SSPSR & SSP_BSY);
00054
00055 dummyReader = (uint8) SSPDR;
00056 }
00057
00058
00059 uint8 ssp_get_byte(void)
00060 {
00061
00062 SSPDR = (REG16) 0xff;
00063 while (SSPSR & SSP_BSY);
00064 return (uint8) SSPDR;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 void ssp_send(const uint8 *p_data, long data_size)
00076 {
00077 uint8 dummy;
00078 if (data_size==0) return;
00079 while (data_size!=0)
00080 {
00081
00082 while ((SSPSR&0x02)==0);
00083 SSPDR = *p_data;
00084
00085 while ((SSPSR&0x04)==0);
00086 dummy = SSPDR;
00087 data_size--;
00088 p_data++;
00089 }
00090 return;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 void ssp_read(uint8 *p_data, long data_size)
00102 {
00103 for (int i=0; i<data_size; i++)
00104 {
00105 SSPDR = (REG16) 0xff;
00106 while (SSPSR & SSP_BSY);
00107 p_data[i] = SSPDR;
00108 }
00109 }