TER Atienza Pongnot 2019 / 7366_lib

Dependents:   Carte_Moteur_test_asservissement_1M identification Carte_Moteur_test_asservissement_3M

Revision:
7:ea991921ae55
Parent:
6:fafe7c5a4b2f
Child:
8:e849d7188c41
--- a/7366_lib.cpp	Tue Jan 29 12:32:32 2019 +0000
+++ b/7366_lib.cpp	Wed Jan 30 18:47:25 2019 +0000
@@ -27,13 +27,23 @@
 	this->write(txBuffer, txLength, rxBuffer, rxLength);
 	this->select = 1;
 	this->unlock();
+	
+	IR = CLR|CNTR;
+	txBuffer[0] = IR;
+	txLength = 1;
+	this->lock();
+	this->select = 0;
+	this->write(txBuffer, txLength, rxBuffer, rxLength);
+	this->select = 1;
+	this->unlock();
+	
 	return;
 	}
 
 
 int32_t SPI_7366::read_value(){
-	char rxBuffer[5] = {0,0,0,0,0};
-	char rxLength = 5;
+	char rxBuffer[6] = {0,0,0,0,0,0};
+	char rxLength = 0;
 	char IR = LOAD|OTR;
 	char txBuffer[1] = {IR};
 	int txLength = 1;
@@ -46,11 +56,12 @@
 	IR = RD|OTR;
 	txBuffer[0] = IR;
 	txLength = 1;
+	rxLength = 5;
 	this->lock();
 	this->select = 0;
 	this->write(txBuffer, txLength, rxBuffer, rxLength);
 	this->select = 1;
 	this->unlock();
-	
-	return (int32_t) (rxBuffer[1])|(rxBuffer[2]<<4)|(rxBuffer[3]<<8)|(rxBuffer[4]<<12);
+	int32_t resultat = (rxBuffer[1]<<24) + (rxBuffer[2]<<16) + (rxBuffer[3]<<8) + (rxBuffer[4]<<0);
+	return resultat;
 	}
\ No newline at end of file