TER Atienza Pongnot 2019 / 7366_lib

Dependents:   Carte_Moteur_test_asservissement_1M identification Carte_Moteur_test_asservissement_3M

7366_lib.cpp

Committer:
natienza
Date:
2019-01-22
Revision:
2:f678a256adc8
Parent:
1:53a1b0bdffb7
Child:
3:acc9c682ceb9

File content as of revision 2:f678a256adc8:

#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, SPI_SSEL){
	}

void SPI_7366::setup(void){
	char rxBuffer[2];
	int rxLength = 0;
	int txLength = 2;
	char IR = WR|MDR0;
	char data = QUADRATURE_X1|FREE_RUN;
	char txBuffer[2] = {IR,data};
	
	this->lock();
	this->write(txBuffer, txLength, rxBuffer, rxLength);
	this->unlock();
	
	IR = WR|MDR1;
	data = CONFIG_4BYTES|CPT_ENABLE;
	txBuffer[0] = IR;
	txBuffer[1] = data;
	this->lock();
	this->write(txBuffer, txLength, rxBuffer, rxLength);
	this->unlock();
	return;
	}


void SPI_7366::read_value(char* rxBuffer, int rxLength ){
	char IR = RD|CNTR;
	char txBuffer[1] = {IR};
	int txLength = 1;
	this->lock();
	this->write(txBuffer, txLength, rxBuffer, rxLength);
	this->unlock();
	return;
	}