コード例 #1
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
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;
		}
	}

}
コード例 #2
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
// 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);
		}
    }
}
コード例 #3
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
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.");
	}
}
コード例 #4
0
ファイル: Tune.cpp プロジェクト: Snootlab/Tune
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
}
コード例 #5
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
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");
	}
}
コード例 #6
0
ファイル: SPI_TWO.c プロジェクト: milspect18/STM32F401_Code
/********************************************************
 * 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 */
コード例 #7
0
ファイル: Tune.cpp プロジェクト: Snootlab/Tune
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;
}
コード例 #8
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
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;
		}
	}
}
コード例 #9
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
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
}
コード例 #10
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
void ADS1299::SDATAC() {
    csLow();
    xfer(_SDATAC);
    csHigh();
	delayMicroseconds(3);   //must wait 4 tCLK cycles after executing this command (Datasheet, pg. 37)
}
コード例 #11
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
void ADS1299::RDATAC() {
    csLow();
    xfer(_RDATAC);
    csHigh();
	delayMicroseconds(3);   
}
コード例 #12
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
void ADS1299::STOP() {			//stop data conversion
    csLow();
    xfer(_STOP);
    csHigh();
}
コード例 #13
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
void ADS1299::START() {			//start data conversion 
    csLow();
    xfer(_START);
    csHigh();
}
コード例 #14
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
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();
}
コード例 #15
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
void ADS1299::STANDBY() {		// only allowed to send WAKEUP after sending STANDBY
    csLow();
    xfer(_STANDBY);
    csHigh();
}
コード例 #16
0
ファイル: ADS1299.cpp プロジェクト: BornTomorrow/EEGHacker
//System Commands
void ADS1299::WAKEUP() {
    csLow(); 
    xfer(_WAKEUP);
    csHigh(); 
    delayMicroseconds(3);  		//must wait 4 tCLK cycles before sending another command (Datasheet, pg. 35)
}