EM4325 is a UHF RFID ASIC that is compliant with ISO/IEC 18000-6 Type C and Type D (TOTAL) as well as EPCTM Class-3 Generation-2 (Gen2). TOTAL is a protocol used for many applications and is an enhanced version of the defacto standard used in apparel item level tagging. EM4325 can be red/write in EEPROM thought RFID (UHF) or SPI protocol, but not at the same time.
EM4325.cpp
00001 /********************************************************************************** 00002 / SPI COMMUNICATION FOR EM4325 * 00003 / * 00004 / Gerald MERCIER * 00005 / 25/04/2012 - NXPLCP1768 * 00006 **********************************************************************************/ 00007 #include "mbed.h" 00008 #include "EM4325.h" 00009 00010 EM4325::EM4325(PinName _mosi, PinName _miso, PinName _sclk, PinName _cs):spi(_mosi, _miso, _sclk), cs(_cs){ 00011 /******************************************************************************* 00012 *******************************************************************************/ 00013 spi.frequency(5000);//Need to be under 2 MHz 00014 spi.format(8, 0);//As the same think in mode(8, 1) or mode(8, 2) 00015 wait(0.5); 00016 } 00017 00018 float EM4325::read_temperature(){ 00019 /******************************************************************************* 00020 *******************************************************************************/ 00021 float temp;//MSW & LSW 00022 uint8_t status_byte = TIME_OUT; 00023 uint8_t data[9]; 00024 00025 Timer timeout;//Timer initialisation 00026 timeout.start();//Start the timer 00027 00028 cs=0; 00029 spi.write(TEMP); 00030 wait(0.5); 00031 00032 timeout.reset(); //Reset the timer to wait for reply for 2 seconds 00033 bool timed_out = false; 00034 00035 while (status_byte == TIME_OUT) { 00036 status_byte = spi.write(0x00); 00037 //Waited too long timeout 00038 if (timeout.read_ms() > 2000) { 00039 timed_out = true; 00040 break; 00041 } 00042 } 00043 00044 if (!timed_out) { 00045 data[0] = status_byte; 00046 //Get the rest of the data 00047 for(int i=1; i<9; ++i){ 00048 data[i] = spi.write(0x00); 00049 } 00050 } 00051 cs =1; 00052 if (data[3] & 0xb1000000 == 0xb10000000){ 00053 temp = ~data[3]+1;//2's complement 00054 }else{ 00055 temp = data[3]; 00056 } 00057 temp = reinterpret_cast<float>(temp);//signed interger 00058 temp = temp*0.25;//(63.75/128);//128 = 2^7 00059 return temp; 00060 } 00061 00062 uint8_t EM4325::read_epc(){ 00063 /******************************************************************************* 00064 *******************************************************************************/ 00065 uint8_t epc;//returned value 00066 uint8_t status_byte = TIME_OUT; 00067 uint8_t data[3]; 00068 00069 Timer timeout;//Timer initialisation 00070 timeout.start();//Start the timer 00071 00072 cs=0; 00073 spi.write(SPI_READ);//Send command byte 00074 spi.write(PERS); 00075 00076 timeout.reset(); //Reset the timer to wait for reply for 2 seconds 00077 bool timed_out = false; 00078 00079 //Wait for the status byte 00080 while (status_byte != IS_OK) { 00081 status_byte = spi.write(0x00); 00082 //Waited too long timeout 00083 if (timeout.read_ms() > 2000) { 00084 timed_out = true; 00085 break; 00086 } 00087 } 00088 00089 if (!timed_out) { 00090 data[0] = status_byte; 00091 //Get the rest of the data 00092 for (uint8_t i=1; i<3; i++) { 00093 data[i] = spi.write(0x00); 00094 epc = data[1]; 00095 } 00096 } 00097 cs = 1; 00098 return epc; 00099 } 00100 00101 uint8_t EM4325::write_epc(uint8_t epc){ 00102 /******************************************************************************* 00103 *******************************************************************************/ 00104 uint8_t status_byte = TIME_OUT; 00105 00106 Timer timeout;//Timer initialisation 00107 timeout.start();//Start the timer 00108 00109 cs = 0; 00110 spi.write(SPI_WRITE);//Send command byte 00111 spi.write(PERS); 00112 spi.write(epc); 00113 //spi.write(0x88); 00114 00115 timeout.reset(); //Reset the timer to wait for reply for 2 seconds 00116 //bool timed_out = false; 00117 00118 //Wait for the status byte 00119 while (status_byte != IS_OK) { 00120 status_byte = spi.write(0x00); 00121 //Waited too long timeout 00122 if (timeout.read_ms() > 2000) { 00123 //Timed_out = true; 00124 break; 00125 } 00126 } 00127 cs = 1; // must raise cs between commands but after the reply 00128 return status_byte; 00129 } 00130 00131 uint8_t EM4325::RF(char STATE){ 00132 uint8_t status_byte=TIME_OUT; 00133 00134 Timer timeout;//Timer initialisation 00135 timeout.start();//Start the timer 00136 00137 cs=0; 00138 00139 if(STATE=='O'){ 00140 spi.write(RF_ENABLE); 00141 }else if(STATE=='F'){ 00142 spi.write(0xE2); 00143 } 00144 00145 timeout.reset(); //Reset the timer to wait for reply for 2 seconds 00146 00147 //Wait for the status byte 00148 while (status_byte != IS_OK) { 00149 status_byte = spi.write(0x00); 00150 //Waited too long timeout 00151 if (timeout.read_ms() > 2000) { 00152 break; 00153 } 00154 } 00155 cs = 1; 00156 return status_byte; 00157 }
Generated on Tue Jul 12 2022 17:47:56 by
1.7.2