Esempio n. 1
0
void ADS1299::updateChannelData(){
	byte inByte;
  int byteCounter = 0;
	csLow();				//  open SPI
    for(int i=0; i<3; i++){
	     inByte = xfer(0x00);		        //  read status register (1100 + LOFF_STATP + LOFF_STATN + GPIO[7:4])
	     stat = (stat << 8) | inByte;
    }
    for(int i = 0; i<8; i++){
  	  for(int j=0; j<3; j++){		//  read 24 bits of channel data in 8 3 byte chunks
  	    inByte = xfer(0x00);
        rawChannelData[byteCounter] = inByte;
        byteCounter++;
  	    channelData[i] = (channelData[i]<<8) | inByte;
  	  }
	  }
	csHigh();				//  close SPI
	
	for(int i=0; i<8; i++){			// convert 3 byte 2's compliment to 4 byte 2's compliment	
		if(bitRead(channelData[i],23) == 1){	
			channelData[i] |= 0xFF000000;
		}else{
			channelData[i] &= 0x00FFFFFF;
		}
	}

}
Esempio n. 2
0
// Read more than one register starting at _address
void ADS1299::RREGS(byte _address, byte _numRegistersMinusOne) {
//	for(byte i = 0; i < 0x17; i++){
//		regData[i] = 0;					//  reset the regData array
//	}
    byte opcode1 = _address + 0x20; 	//  RREG expects 001rrrrr where rrrrr = _address
    csLow(); 				//  open SPI
    xfer(opcode1); 					//  opcode1
    xfer(_numRegistersMinusOne);	//  opcode2
    for(int i = 0; i <= _numRegistersMinusOne; i++){
        regData[_address + i] = xfer(0x00); 	//  add register byte to mirror array
		}
    csHigh(); 			//  close SPI
	if(verbosity){						//  verbosity output
		for(int i = 0; i<= _numRegistersMinusOne; i++){
			printRegisterName(_address + i);
			printHex(_address + i);
			Serial.print(", ");
			printHex(regData[_address + i]);
			Serial.print(", ");
			for(int j = 0; j<8; j++){
				Serial.print(bitRead(regData[_address + i], 7-j));
				if(j!=7) Serial.print(", ");
			}
			Serial.println();
			delay(30);
		}
    }
}
Esempio n. 3
0
void ADS1299::WREG(byte _address, byte _value) {	//  Write ONE register at _address
    byte opcode1 = _address + 0x40; 	//  WREG expects 010rrrrr where rrrrr = _address
    csLow(); 				//  open SPI
    xfer(opcode1);					//  Send WREG command & address
    xfer(0x00);						//	Send number of registers to read -1
    xfer(_value);					//  Write the value to the register
    csHigh(); 			//  close SPI
	regData[_address] = _value;			//  update the mirror array
	if(verbosity){						//  verbosity output
		Serial.print("Register ");
		printHex(_address);
		Serial.println(" modified.");
	}
}
Esempio n. 4
0
void Tune::writeSCI(byte registerAddress, byte highbyte, byte lowbyte)
{
	while (!digitalRead(DREQ)); // DREQ high <-> VS1011 available
	csLow(); // Select control

	SPI.transfer(VS_WRITE); // Write instruction
	SPI.transfer(registerAddress);
	
	// MSB first
	SPI.transfer(highbyte); 
	while (!digitalRead(DREQ)); // wait 'til cmd is complete
	SPI.transfer(lowbyte);
	while (!digitalRead(DREQ));
	
	csHigh(); // Deselect control
}
Esempio n. 5
0
void ADS1299::WREGS(byte _address, byte _numRegistersMinusOne) {
    byte opcode1 = _address + 0x40;		//  WREG expects 010rrrrr where rrrrr = _address
    csLow(); 				//  open SPI
    xfer(opcode1);					//  Send WREG command & address
    xfer(_numRegistersMinusOne);	//	Send number of registers to read -1	
	for (int i=_address; i <=(_address + _numRegistersMinusOne); i++){
		xfer(regData[i]);			//  Write to the registers
	}	
	digitalWrite(CS,HIGH);				//  close SPI
	if(verbosity){
		Serial.print("Registers ");
		printHex(_address); Serial.print(" to ");
		printHex(_address + _numRegistersMinusOne);
		Serial.println(" modified");
	}
}
Esempio n. 6
0
/********************************************************
 * spiTwoTransfer
 *
 * Inputs------------------------------------------------
 * 	  data (unsigned char*)  	Pointer to data buffer.
 * 							   	(Data to be output)
 * 	  recData (unsigned char*)	Pointer to receive data
 * 	  							data buffer
 * 	  numBytes (uint8_t)		The number of bytes to
 * 	  							be transfered in/out
 *
 * This routine will transfer out a specified number of
 * bytes.
 ********************************************************/
void spiTwoTransfer(unsigned char *data, unsigned char *recData, uint8_t numBytes)
{
	uint8_t index = 0;

	csLow();	// Set the chip select low to start transmission

	while(numBytes > 0)	// More data to transfer
	{
		if (SPI2->SR & SPI_SR_TXE)					// SPI2 TX buffer empty
		{
			SPI2->DR = data[index];					// Fill the data register with current byte
			while((SPI2->SR & SPI_SR_RXNE) == 0);	// Wait for end of frame
			recData[index] = SPI2->DR;				// Read available data (also clears RXNE bit)
			numBytes--;								// Decrement number of bytes left to send
			index++;								// Increment data buffer index
		}
	}

	csHigh();	// All data sent/received, return chip select to high
} /* END spiTwoTransfer */
Esempio n. 7
0
unsigned int Tune::readSCI(byte registerAddress)
{
	byte hiByte, loByte;
	
	while (!digitalRead(DREQ)); // DREQ high <-> VS1011 available
	csLow(); // Select control
  
	SPI.transfer(VS_READ); // Read instruction
	SPI.transfer(registerAddress);
	
	// MSB first
	hiByte = SPI.transfer(0x00); 
	while (!digitalRead(DREQ)); // wait 'til cmd is complete
	loByte = SPI.transfer(0x00);
	while (!digitalRead(DREQ));

	csHigh(); // Deselect control
  
	unsigned int response = word(hiByte, loByte);
	return response;
}
Esempio n. 8
0
void ADS1299::RDATA() {					//  use in Stop Read Continuous mode when DRDY goes low
	byte inByte;						//  to read in one sample of the channels
    csLow();				//  open SPI
    xfer(_RDATA);					//  send the RDATA command
	stat = xfer(0x00);				//  read status register (1100 + LOFF_STATP + LOFF_STATN + GPIO[7:4])
	for(int i = 0; i<8; i++){
		for(int j=0; j<3; j++){		//  read in the status register and new channel data
			inByte = xfer(0x00);
			channelData[i] = (channelData[i]<<8) | inByte;
		}
	}
	csHigh();				//  close SPI
	
	for(int i=0; i<8; i++){
		if(bitRead(channelData[i],23) == 1){	// convert 3 byte 2's compliment to 4 byte 2's compliment
			channelData[i] |= 0xFF000000;
		}else{
			channelData[i] &= 0x00FFFFFF;
		}
	}
}
Esempio n. 9
0
byte ADS1299::RREG(byte _address) {		//  reads ONE register at _address
    byte opcode1 = _address + 0x20; 	//  RREG expects 001rrrrr where rrrrr = _address
    csLow(); 				//  open SPI
    xfer(opcode1); 					//  opcode1
    xfer(0x00); 					//  opcode2
    regData[_address] = xfer(0x00);//  update mirror location with returned byte
    csHigh(); 			//  close SPI	
	if (verbosity){						//  verbosity output
		printRegisterName(_address);
		printHex(_address);
		Serial.print(", ");
		printHex(regData[_address]);
		Serial.print(", ");
		for(byte j = 0; j<8; j++){
			Serial.print(bitRead(regData[_address], 7-j));
			if(j!=7) Serial.print(", ");
		}
		
		Serial.println();
	}
	return regData[_address];			// return requested register value
}
Esempio n. 10
0
void ADS1299::SDATAC() {
    csLow();
    xfer(_SDATAC);
    csHigh();
	delayMicroseconds(3);   //must wait 4 tCLK cycles after executing this command (Datasheet, pg. 37)
}
Esempio n. 11
0
void ADS1299::RDATAC() {
    csLow();
    xfer(_RDATAC);
    csHigh();
	delayMicroseconds(3);   
}
Esempio n. 12
0
void ADS1299::STOP() {			//stop data conversion
    csLow();
    xfer(_STOP);
    csHigh();
}
Esempio n. 13
0
void ADS1299::START() {			//start data conversion 
    csLow();
    xfer(_START);
    csHigh();
}
Esempio n. 14
0
void ADS1299::RESET() {			// reset all the registers to default settings
    csLow();
    xfer(_RESET);
    delayMicroseconds(12);   	//must wait 18 tCLK cycles to execute this command (Datasheet, pg. 35)
    csHigh();
}
Esempio n. 15
0
void ADS1299::STANDBY() {		// only allowed to send WAKEUP after sending STANDBY
    csLow();
    xfer(_STANDBY);
    csHigh();
}
Esempio n. 16
0
//System Commands
void ADS1299::WAKEUP() {
    csLow(); 
    xfer(_WAKEUP);
    csHigh(); 
    delayMicroseconds(3);  		//must wait 4 tCLK cycles before sending another command (Datasheet, pg. 35)
}