Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Carte_Moteur_test_asservissement_1M identification Carte_Moteur_test_asservissement_3M
7366_lib.cpp
00001 #include "mbed.h" 00002 #include "7366_lib.h" 00003 00004 SPI_7366::SPI_7366(PinName SPI_MOSI, PinName SPI_MISO, PinName SPI_SCLK, PinName SPI_SSEL):SPI(SPI_MOSI,SPI_MISO, SPI_SCLK),select(SPI_SSEL, 1){ 00005 this->sens=1; 00006 } 00007 00008 void SPI_7366::setup(void){ 00009 char rxBuffer[2]; 00010 int rxLength = 0; 00011 int txLength = 2; 00012 char IR = WR|MDR0; 00013 char data = QUADRATURE_X1|FREE_RUN; 00014 char txBuffer[2] = {IR,data}; 00015 this->lock(); 00016 this->select = 0; 00017 this->write(txBuffer, txLength, rxBuffer, rxLength); 00018 this->select = 1; 00019 this->unlock(); 00020 00021 00022 IR = WR|MDR1; 00023 data = CONFIG_4BYTES|CPT_ENABLE; 00024 txBuffer[0] = IR; 00025 txBuffer[1] = data; 00026 this->lock(); 00027 this->select = 0; 00028 this->write(txBuffer, txLength, rxBuffer, rxLength); 00029 this->select = 1; 00030 this->unlock(); 00031 00032 IR = CLR|CNTR; 00033 txBuffer[0] = IR; 00034 txLength = 1; 00035 this->lock(); 00036 this->select = 0; 00037 this->write(txBuffer, txLength, rxBuffer, rxLength); 00038 this->select = 1; 00039 this->unlock(); 00040 00041 return; 00042 } 00043 void SPI_7366::set_as_inverted(void){ 00044 this->sens = -1; 00045 return; 00046 } 00047 00048 int32_t SPI_7366::read_value(){ 00049 char rxBuffer[6] = {0,0,0,0,0,0}; 00050 char rxLength = 0; 00051 char IR = LOAD|OTR; 00052 char txBuffer[1] = {IR}; 00053 int txLength = 1; 00054 this->lock(); 00055 this->select = 0; 00056 this->write(txBuffer, txLength, rxBuffer, rxLength); 00057 this->select = 1; 00058 this->unlock(); 00059 00060 IR = RD|OTR; 00061 txBuffer[0] = IR; 00062 txLength = 1; 00063 rxLength = 5; 00064 this->lock(); 00065 this->select = 0; 00066 this->write(txBuffer, txLength, rxBuffer, rxLength); 00067 this->select = 1; 00068 this->unlock(); 00069 int32_t resultat = (rxBuffer[1]<<24) + (rxBuffer[2]<<16) + (rxBuffer[3]<<8) + (rxBuffer[4]<<0); 00070 return sens*resultat; 00071 }
Generated on Sat Aug 27 2022 05:01:04 by
1.7.2