Пример #1
0
/******************************************************************************
* @brief Writes to an ADXL362 Register.
*
* @param addr - register address.
* @param data - data to be written
*
* @return None.
******************************************************************************/
void ADXL362_WriteReg(char addr, char data)
{
	char txBuffer[3] = {0x0A, addr, data};
	char rxBuffer[3] = {0x00, 0x00, 0x00};

	SPI_TransferData(SPI_BASEADDR, 3, txBuffer, 3, rxBuffer, 1);
}
Пример #2
0
/******************************************************************************
* @brief Reads from an ADXL362 Register.
*
* @param addr - register address.
*
* @return rx - data read from register.
******************************************************************************/
char ADXL362_ReadReg(char addr)
{
	char txBuffer[3] = {0x0B, addr, 0x00};
	char rxBuffer[3] = {0x00, 0x00, 0x00};
	char rx = 0x00;

	SPI_TransferData(SPI_BASEADDR, 3, txBuffer, 3, rxBuffer, 1);

	rx = rxBuffer[2];

	return(rx);
}
Пример #3
0
/******************************************************************************
* @brief Sets the internal reference off.
*
* @param None.
*
* @return None.
******************************************************************************/
void AD5628_RefOFF(void)
{
	int  txData      = 0;
	char txBuffer[4] = {0, 0, 0, 0};
	char rxBuffer[4] = {0, 0, 0, 0};

	txData = (SetUpRefReg << CommandDef) |
			 (0 << 0);

	txBuffer[0] = (txData & 0xFF000000) >> 24;
	txBuffer[1] = (txData & 0x00FF0000) >> 16;
	txBuffer[2] = (txData & 0x0000FF00) >> 8;
	txBuffer[3] = (txData & 0x000000FF);

	SPI_TransferData(SPI_BASEADDR, 4, txBuffer, 4, rxBuffer, 1);
}
Пример #4
0
/**************************************************************************//**
* @brief Writes data into a register.
*
* @param regAddr - The address of the register to be written.
* @param regVal  - The value to be written into the register.
*
* @return Returns 0 in case of success or negative error code.
******************************************************************************/
int32_t ad9467_write(uint16_t regAddr, uint8_t regVal)
{
	int32_t ret;
	uint8_t	write_buffer[3];

    regAddr += AD9467_WRITE;

	write_buffer[0] = (uint8_t)((regAddr & 0xFF00) >> 8);
	write_buffer[1] = (uint8_t)(regAddr & 0x00FF);
	write_buffer[2] = regVal;

	ret = SPI_TransferData(spiBaseAddress, 3, (char*)write_buffer, 0, NULL, 
			spiSlaveSelect);

    return ret;
}
Пример #5
0
/******************************************************************************
* @brief Updates the DAC.
*
* @param n - Select which DAC to Update.
*
* @param data - Value to be updated
*
* @return None.
******************************************************************************/
void AD5628_WriteUpdateDac(int n, int data)
{
	int  txData      = 0;
	char txBuffer[4] = {0, 0, 0, 0};
	char rxBuffer[4] = {0, 0, 0, 0};

	txData = (WriteUpdateDACn << CommandDef) |
			 (n << AddressCom) |
			 (data << DataBits);

	txBuffer[0] = (txData & 0xFF000000) >> 24;
	txBuffer[1] = (txData & 0x00FF0000) >> 16;
	txBuffer[2] = (txData & 0x0000FF00) >> 8;
	txBuffer[3] = (txData & 0x000000FF);

	SPI_TransferData(SPI_BASEADDR, 4, txBuffer, 4, rxBuffer, 1);
}
Пример #6
0
/**************************************************************************//**
* @brief Reads data from a register.
*
* @param regAddr - The address of the register to be read.
*
* @return Returns the read data or negative error code.
******************************************************************************/
int32_t ad9467_read(uint16_t regAddr)
{
	int32_t ret;
	uint8_t	write_buffer[3];
	uint8_t	read_buffer[3] = {0, 0, 0};

	regAddr += AD9467_READ;

	write_buffer[0] = (uint8_t)((regAddr & 0xFF00) >> 8);
	write_buffer[1] = (uint8_t)(regAddr & 0x00FF);
	write_buffer[2] = 0;

	ret = SPI_TransferData(spiBaseAddress, 3, (char*)write_buffer, 3, (char*)read_buffer, 
			spiSlaveSelect);
	if(ret < 0)
	{
		return ret;
	}

	return (int32_t)read_buffer[2];
}