Exemple #1
0
/*writing function*/
void f3d_gyro_write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite) {
  /****************************************************************************/
  /************** CODE HERE *********************************************/

  //CHECK TO SEE HOW MANY BYTES AND HANDLE THAT CORRECTLY
  if (NumByteToWrite > 1) {
    WriteAddr |= (uint8_t)(0x40);
  }//by default WriteAddr uses single byte mode, or so i was told

  //SET THE CS
  //set CS to low
  GYRO_CS_LOW();

  //SEND THE FIRST BYTE
  f3d_gyro_sendbyte(WriteAddr);

  //IF MULTIPLE, SEND THE ADDITIONAL
  while(NumByteToWrite > 0x00){
    f3d_gyro_sendbyte(*pBuffer);
    NumByteToWrite--;
    pBuffer++;
  }

  //set chip to high, done talking
  GYRO_CS_HIGH();

  /***************************************************************************/
}
/*writing function*/
void f3d_gyro_write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite) {
	if(NumByteToWrite > 1)
		WriteAddr |= 0x40;
	GYRO_CS_LOW();
	f3d_gyro_sendbyte(WriteAddr);
	while(NumByteToWrite > 0){
		f3d_gyro_sendbyte(*pBuffer);
		NumByteToWrite--;
		pBuffer++;
	}
	GYRO_CS_HIGH();
}
void f3d_gyro_write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite) {
  if(NumByteToWrite > 0x01) {
    WriteAddr |= (uint8_t) ((uint8_t)0x40);  // Set bit 6 if multibyte command
  }
  GYRO_CS_LOW();
  f3d_gyro_sendbyte(WriteAddr);
  while(NumByteToWrite >= 0x01) {
    f3d_gyro_sendbyte(*pBuffer);
    NumByteToWrite--;
    pBuffer++;
  }
  /* Set chip select High at the end of the transmission */ 
  GYRO_CS_HIGH();
}
Exemple #4
0
void f3d_gyro_read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead){
  if (NumByteToRead > 1) {
    ReadAddr |= (uint8_t)(0x80 | 0x40); // If sending more that one byte set multibyte commands
  }
  else {
    ReadAddr |= (uint8_t) (0x80); // Else just set the read mode 
  }

  GYRO_CS_LOW();
  f3d_gyro_sendbyte(ReadAddr);

  while(NumByteToRead > 0x00) {
    *pBuffer = f3d_gyro_sendbyte(((uint8_t)0x00));
    NumByteToRead--;
    pBuffer++;
  }
  GYRO_CS_HIGH();
}
Exemple #5
0
void f3d_gyro_write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite) {
  if (NumByteToWrite > 0x01) {
    WriteAddr |= (uint8_t)(0x40); // If sending more that one byte set multibyte commands 
    // 0100 0000 || 0010 0000 = 0110 0000
  }
  //else {
  //  WriteAddr |= (uint8_t) (0x80); // Else just set the read mode 
  //}

  GYRO_CS_LOW();
  f3d_gyro_sendbyte(WriteAddr);
  
  while(NumByteToWrite > 0) {
    NumByteToWrite = NumByteToWrite - 1;
    
    // NumByteToWrite--;
    f3d_gyro_sendbyte(*pBuffer); //POSSIBLY BAD STUFF
    //WriteAddr++;
    pBuffer++;
  }
  GYRO_CS_HIGH();
}
void f3d_gyro_read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead) {
  if (NumByteToRead > 0x01) {
    ReadAddr |= (uint8_t)(0x80 | 0x40); // If sending more that one byte set multibyte commands
  }
  else {
    ReadAddr |= (uint8_t) (0x80); // Else just set the read mode 
  }
  /* Set chip select Low at the start of the transmission */
  GYRO_CS_LOW();
  
  /* Send the Address of the indexed register */
  f3d_gyro_sendbyte(ReadAddr);
  
  /* Receive the data that will be read from the device (MSB First) */
  while(NumByteToRead > 0x00) {
    /* Send dummy byte (0x00) to generate the SPI clock to L3GD20 (Slave device) */
    *pBuffer = f3d_gyro_sendbyte(((uint8_t)0x00));
    NumByteToRead--;
    pBuffer++;
  }
  /* Set chip select High at the end of the transmission */ 
  GYRO_CS_HIGH();
}
Exemple #7
0
//to read from it
void f3d_gyro_read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead) {
  //are we reading one byte or more than one byte???
  if (NumByteToRead > 1) {
    ReadAddr |= (uint8_t)(0x80 | 0x40); // sets to multibyte mode
  }
  else {
    ReadAddr |= (uint8_t) (0x80); // sets to read mode (first bit 1)
  }
  //setting chip select to low (LETS TALK!)
  GYRO_CS_LOW();
  //sending address byte
  f3d_gyro_sendbyte(ReadAddr);  
  while(NumByteToRead > 0x00) {
    //WE are now sending dummy data so we can read the valuable!
    //remember we must write to read!
    //putting the information in the buffer
    *pBuffer = f3d_gyro_sendbyte(((uint8_t)0x00));
    NumByteToRead--;
    pBuffer++;
  }
  //setting chip select to high (DONE TALKING)
  GYRO_CS_HIGH();//setting chip select to high (DONE TALKING)
}
Exemple #8
0
/*writing function*/
void f3d_gyro_write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite) {
  /****************************************************************************/
  /************** CODE HERE *********************************************/

  //CHECK TO SEE HOW MANY BYTES AND HANDLE THAT CORRECTLY
  if (NumByteToWrite > 1) {
    WriteAddr |= (uint8_t)(0x40); // sets to multibyte mode
  }
  //SET THE CS
  GYRO_CS_LOW();
  //SEND THE FIRST BYTE
  
  f3d_gyro_sendbyte(WriteAddr); 
  //IF MULTIPLE, SEND THE ADDITIONAL
  while(NumByteToWrite > 0x00) {
    f3d_gyro_sendbyte((uint8_t)(*pBuffer));
    //*pBuffer = f3d_gyro_sendbyte(((uint8_t)0x00));
    NumByteToWrite--;
    pBuffer++;
  }
  GYRO_CS_HIGH();
  /***************************************************************************/
}