Пример #1
0
/***************************************************************************//**
 * @brief Writes data into a register.
 *
 * @param dev              - The device structure.
 * @param register_address - Address of the register.
 *                          Example:
 *                          AD5755_DREG_WR_DAC
 *                          AD5755_DREG_WR_GAIN
 *                          AD5755_DREG_WR_GAIN_ALL
 *                          AD5755_DREG_WR_OFFSET
 *                          AD5755_DREG_WR_OFFSET_ALL
 *                          AD5755_DREG_WR_CLR_CODE
 *                          AD5755_DREG_WR_CTRL_REG
 *
 * @param channel         -  Channel option.
 *                          Example: AD5755_DAC_A
 *                           AD5755_DAC_B
 *                           AD5755_DAC_C
 *                           AD5755_DAC_D
 * @param register_value - Data value to write.
 *
 * @return None.
*******************************************************************************/
uint16_t ad5755_set_register_value(struct ad5755_dev *dev,
				   uint8_t register_address,
				   uint8_t channel,
				   uint16_t register_value)
{
	uint8_t buff[4] = {0, 0, 0, 0};
	uint32_t command = 0;
	uint16_t status_reg = 0;

	command = AD5755_ISR_WRITE |
		  AD5755_ISR_DUT_AD1(dev->p_ad5755_st->pin_ad1state) |
		  AD5755_ISR_DUT_AD0(dev->p_ad5755_st->pin_ad0state) |
		  AD5755_ISR_DREG(register_address) |
		  AD5755_ISR_DAC_AD(channel)|
		  AD5755_ISR_DATA(register_value);
	buff[0] = (command & 0xFF0000) >> 16;
	buff[1] = (command & 0x00FF00) >> 8;
	buff[2] = (command & 0x0000FF) >> 0;
	if(dev->p_ad5755_st->enable_packet_error_check) {
		buff[3] = ad5755_check_crc(buff, 3);
	}
	if(dev->p_ad5755_st->stat_readbit == 0) {
		spi_write_and_read(dev->spi_desc,
				   buff,
				   3 + dev->p_ad5755_st->enable_packet_error_check);
	} else {
		spi_write_and_read(dev->spi_desc,
				   buff,
				   3 + dev->p_ad5755_st->enable_packet_error_check);
		status_reg = (buff[1] << 8) + buff[2];
	}

	return status_reg;
}
Пример #2
0
/***************************************************************************//**
 * @brief Writes data into a register.
 *
 * @param registerAddress - Address of the register.
 *                          Example:
 *                          AD5755_DREG_WR_DAC
 *                          AD5755_DREG_WR_GAIN
 *                          AD5755_DREG_WR_GAIN_ALL
 *                          AD5755_DREG_WR_OFFSET
 *                          AD5755_DREG_WR_OFFSET_ALL
 *                          AD5755_DREG_WR_CLR_CODE
 *                          AD5755_DREG_WR_CTRL_REG
 *
 * @param channel -  Channel option.
 *                  Example: AD5755_DAC_A
 *                           AD5755_DAC_B
 *                           AD5755_DAC_C
 *                           AD5755_DAC_D
 * @param registerValue - Data value to write.
 *
 * @return None.
*******************************************************************************/
 unsigned short AD5755_SetRegisterValue(unsigned char registerAddress,
                                        unsigned char channel,
                                        unsigned short registerValue)
 {
    unsigned char buff[4] = {0, 0, 0, 0};
    unsigned long command = 0;
    unsigned short statusReg = 0;

    command = AD5755_ISR_WRITE |
              AD5755_ISR_DUT_AD1(AD5755_st.pinAD1state) |
              AD5755_ISR_DUT_AD0(AD5755_st.pinAD0state) |
              AD5755_ISR_DREG(registerAddress) |
              AD5755_ISR_DAC_AD(channel)|
              AD5755_ISR_DATA(registerValue);
    buff[0] = (command & 0xFF0000) >> 16;
    buff[1] = (command & 0x00FF00) >> 8;
    buff[2] = (command & 0x0000FF) >> 0;
    if(AD5755_st.enablePacketErrorCheck)
    {
        buff[3] = AD5755_CheckCrc(buff, 3);
    }
    if(AD5755_st.statReadBit == 0)
    {
        SPI_Write(AD5755_SLAVE_ID,
                  buff,
                  3 + AD5755_st.enablePacketErrorCheck);
    }
    else
    {
        SPI_Read(AD5755_SLAVE_ID,
                 buff,
                 3 + AD5755_st.enablePacketErrorCheck);
        statusReg = (buff[1] << 8) + buff[2];
    }

return statusReg;
}