TER Atienza Pongnot 2019 / 7366_lib

Dependents:   Carte_Moteur_test_asservissement_1M identification Carte_Moteur_test_asservissement_3M

Revision:
1:53a1b0bdffb7
Child:
2:f678a256adc8
diff -r df071a35f4aa -r 53a1b0bdffb7 7366_lib.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/7366_lib.cpp	Tue Jan 22 11:00:13 2019 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+#include "7366_lib.h"
+
+SPI_7366::SPI_7366(PinName SPI_MOSI, PinName SPI_MISO, PinName SPI_SCLK, PinName SPI_SSEL):SPI(SPI_MOSI,SPI_MISO, SPI_SCLK, ssel=SPI_SSEL){
+	}
+
+void SPI_7366::setup(void){
+	uint8_t rxBuffer[2];
+	int rxLength = 0;
+	int txLength = 2;
+	uint8_t IR = WR|MDR0;
+	uint8_t data = QUADRATURE_X1|FREE_RUN;
+	uint8_t txBuffer[2] = {IR,data};
+	
+	self.lock();
+	self.write(txBuffer, txLength, rxBuffer, rxLength);
+	self.unlock();
+	
+	IR = WR|MDR1;
+	data = 4BYTES_CONFIG|CPT_ENABLE;
+	txBuffer = {IR,data};
+	self.lock();
+	self.write(txBuffer, txLength, rxBuffer, rxLength);
+	self.unlock();
+	return;
+	}
+
+
+void SPI_7366::read_value(uint8_t* rxBuffer, int rxLength ){
+	uint8_t IR = RD|CNTR;
+	uint8_t txBuffer[1] = {IR};
+	int txLength = 1;
+	self.lock();
+	self.write(txBuffer, txLength, rxBuffer, rxLength);
+	self.unlock();
+	return;
+	}
\ No newline at end of file