Sungwoo Kim
/
HydraulicControlBoard_LIGHT
For LIGHT
Diff: SPI_EEP_ENC/SPI_EEP_ENC.cpp
- Revision:
- 16:903b5a4433b4
- Parent:
- 0:51c43836c1d7
diff -r bd0d12728506 -r 903b5a4433b4 SPI_EEP_ENC/SPI_EEP_ENC.cpp --- a/SPI_EEP_ENC/SPI_EEP_ENC.cpp Fri Aug 30 02:26:11 2019 +0000 +++ b/SPI_EEP_ENC/SPI_EEP_ENC.cpp Mon Sep 02 13:32:33 2019 +0000 @@ -3,46 +3,48 @@ #include "SPI_EEP_ENC.h" // EEPROM -void spi_eeprom_ready(void){ - int temp1, temp2; - do{ - eeprom_cs=0; - eeprom.write(0x06); //write enable - eeprom_cs=1; - - eeprom_cs=0; - temp1 = eeprom.write(0x05); - temp2 = eeprom.write(0x00); - eeprom_cs=1; - temp2=(temp2&(0x03))!= 0x02; - } while(temp2); // before writing or reading - } - - void spi_eeprom_write(unsigned short int add, unsigned int data){ - eeprom_cs=0; - eeprom.write(0x02); - eeprom.write(0xff&(add>>8)); - eeprom.write(0xff&add); - eeprom.write(0xff&data); - eeprom.write(0xff&(data>>8)); - eeprom.write(0xff&(data>>16)); - eeprom.write(0xff&(data>>24)); - eeprom_cs=1; -} - -unsigned int spi_eeprom_read(unsigned short int add){ - eeprom_cs=0; - eeprom.write(0x03); - eeprom.write(0xff&(add>>8)); - eeprom.write(0xff&add); - int a1 = eeprom.write(0x00); - int a2 = eeprom.write(0x00); - int a3 = eeprom.write(0x00); - int a4 = eeprom.write(0x00); - eeprom_cs=1; - unsigned int final = (a4<<24)+(a3<<16) + (a2<<8) + a1; - return final; - } +//void spi_eeprom_ready(void){ +// int temp1, temp2; +// do{ +// eeprom_cs=0; +// eeprom.write(0x06); //write enable +// eeprom_cs=1; +// +// eeprom_cs=0; +// temp1 = eeprom.write(0x05); +// temp2 = eeprom.write(0x00); +// eeprom_cs=1; +// temp2=(temp2&(0x03))!= 0x02; +// } while(temp2); // before writing or reading +// } +// +// void spi_eeprom_write(unsigned short add, unsigned int data){ +// eeprom_cs=0; +// eeprom.write(0x02); +// eeprom.write(0xff&(add>>8)); +// eeprom.write(0xff&add); +// eeprom.write(0xff&data); +// eeprom.write(0xff&(data>>8)); +// eeprom.write(0xff&(data>>16)); +// eeprom.write(0xff&(data>>24)); +// eeprom_cs=1; +//} +// +//unsigned int spi_eeprom_read(unsigned short add){ +// eeprom_cs=0; +// eeprom.write(0x03); +// eeprom.write(0xff&(add>>8)); +// eeprom.write(0xff&add); +// +// int a1 = eeprom.write(0x00); +// int a2 = eeprom.write(0x00); +// int a3 = eeprom.write(0x00); +// int a4 = eeprom.write(0x00); +// eeprom_cs=1; +// //unsigned int final = (a4<<24)+(a3<<16) + (a2<<8) + a1; +// unsigned int final = (int32_t) (a1 | a2 << 8 | a3 << 16 | a4 << 24); +// return final; +// } // ENCODER