コード例 #1
0
/**
  * @brief  Writes one byte to the GYRO.
  * @param  pBuffer: pointer to the buffer  containing the data to be written to the GYRO.
  * @param  WriteAddr : GYRO's internal address to write to.
  * @param  NumByteToWrite: Number of bytes to write.
  * @retval None
  */
void GYRO_IO_Write(uint8_t* pBuffer, uint8_t WriteAddr, uint16_t NumByteToWrite)
{
  /* Configure the MS bit:
     - When 0, the address will remain unchanged in multiple read/write commands.
     - When 1, the address will be auto incremented in multiple read/write commands.
  */
  if(NumByteToWrite > 0x01)
  {
    WriteAddr |= (uint8_t)MULTIPLEBYTE_CMD;
  }
  /* Set chip select Low at the start of the transmission */
  GYRO_CS_LOW();

  /* Send the Address of the indexed register */
  SPIx_WriteRead(WriteAddr);

  /* Send the data that will be written into the device (MSB First) */
  while(NumByteToWrite >= 0x01)
  {
    SPIx_WriteRead(*pBuffer);
    NumByteToWrite--;
    pBuffer++;
  }

  /* Set chip select High at the end of the transmission */
  GYRO_CS_HIGH();
}
コード例 #2
0
/**
  * @brief  Reads a block of data from the GYRO.
  * @param  pBuffer: pointer to the buffer that receives the data read from the GYRO.
  * @param  ReadAddr: GYRO's internal address to read from.
  * @param  NumByteToRead: Number of bytes to read from the GYRO.
  * @retval None
  */
void GYRO_IO_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead)
{
  if(NumByteToRead > 0x01)
  {
    ReadAddr |= (uint8_t)(READWRITE_CMD | MULTIPLEBYTE_CMD);
  }
  else
  {
    ReadAddr |= (uint8_t)READWRITE_CMD;
  }

  /* Set chip select Low at the start of the transmission */
  GYRO_CS_LOW();

  /* Send the Address of the indexed register */
  SPIx_WriteRead(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 GYRO (Slave device) */
    *pBuffer = SPIx_WriteRead(DUMMY_BYTE);
    NumByteToRead--;
    pBuffer++;
  }

  /* Set chip select High at the end of the transmission */
  GYRO_CS_HIGH();
}
コード例 #3
0
ファイル: f3d_gyro.c プロジェクト: gaoyuu/III_III_V_CS
/*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();

  /***************************************************************************/
}
コード例 #4
0
/**
  * @brief  Reads a block of data from the GYROSCOPE.
  * @param  pBuffer : pointer to the buffer that receives the data read from the GYROSCOPE.
  * @param  ReadAddr : GYROSCOPE's internal address to read from.
  * @param  NumByteToRead : number of bytes to read from the GYROSCOPE.
  * @retval None
  */
HAL_StatusTypeDef GYRO_IO_Read(uint8_t* pBuffer, uint8_t ReadAddr, uint16_t NumByteToRead)
{
  HAL_StatusTypeDef status = HAL_OK;
  uint8_t readByte = 0;

  if(NumByteToRead > 0x01)
  {
    ReadAddr |= (uint8_t)(READWRITE_CMD | MULTIPLEBYTE_CMD);
  }
  else
  {
    ReadAddr |= (uint8_t)READWRITE_CMD;
  }

  /* Set chip select Low at the start of the transmission */
  GYRO_CS_LOW();

  /* Send the Address of the indexed register */
  status = SPIx_WriteRead(ReadAddr, &readByte);

  /* Receive the data that will be read from the device (MSB First) */
  while(NumByteToRead > 0x00 && status == HAL_OK)
  {
    /* Send dummy byte (0x00) to generate the SPI clock to GYROSCOPE (Slave device) */
    status = SPIx_WriteRead(DUMMY_BYTE, pBuffer);
    NumByteToRead--;
    pBuffer++;
  }

  /* Set chip select High at the end of the transmission */
  GYRO_CS_HIGH();

  return status;
}
コード例 #5
0
/*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();
}
コード例 #6
0
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();
}
コード例 #7
0
ファイル: f3d_gyro.c プロジェクト: jlwegene/Bank-Heist-2013
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();
}
コード例 #8
0
ファイル: f3d_gyro.c プロジェクト: jlwegene/Bank-Heist-2013
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();
}
コード例 #9
0
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();
}
コード例 #10
0
ファイル: f3d_gyro.c プロジェクト: leestrin/CSCI-C335
//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)
}
コード例 #11
0
ファイル: f3d_gyro.c プロジェクト: kmfb21/STM32_LabWork
/*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();
  /***************************************************************************/
}