示例#1
0
文件: 24c01.c 项目: pal73/fat470
//-----------------------------------------------
long _24c01_read_4byte(short adr)
{
long temp;
//char temp1;
long temp_[4];

i2c_Start();
i2c_SendByte(0xa0);
if(i2c_ReadAcknowledge()) goto Stop_label_24c01_read_4byte;
i2c_SendByte((char)adr);
if(i2c_ReadAcknowledge()) goto Stop_label_24c01_read_4byte;
i2c_Restart();
i2c_SendByte(0xa1);
if(i2c_ReadAcknowledge()) goto Stop_label_24c01_read_4byte;
temp_[0]=i2c_ReadByte();
i2c_SendAcknowledge(1);
temp_[1]=i2c_ReadByte();
i2c_SendAcknowledge(1);
temp_[2]=i2c_ReadByte();
i2c_SendAcknowledge(1);
temp_[3]=i2c_ReadByte();
i2c_SendAcknowledge(0);
Stop_label_24c01_read_4byte: 
i2c_Stop();
temp_[0]&=0x000000ff;
temp_[1]<<=8;
temp_[1]&=0x0000ff00;
temp_[2]<<=16;
temp_[2]&=0x00ff0000;
temp_[3]<<=24;
temp_[3]&=0xff000000;
temp=temp_[0]+temp_[1]+temp_[2]+temp_[3];
return temp;
}
示例#2
0
//带自动回复的读一字节
uint8_t i2c_ReadByteA(void)
{
u8 tmp;
	//第一个字节假
	i2c_ReadByte();
	i2c_Ack();
	//真正读
	tmp=i2c_ReadByte();
	i2c_NAck();
	return tmp;
}
示例#3
0
/*
*********************************************************************************************************
*	函 数 名: SI4730_GetRevision
*	功能说明: 读取器件、固件信息。 返回8字节数据
*	形    参:_ReadBuf  返回结果存放在此缓冲区,请保证缓冲区大小大于等于8
*	返 回 值: 0 失败, 1 成功
*********************************************************************************************************
*/
uint8_t SI4730_GetRevision(uint8_t *_ReadBuf)
{
	uint8_t ucCmdBuf[2];
	uint32_t uiTimeOut;
	uint8_t i;

	/* AN223 page = 67 */

	/* 发送 0x10 命令 */
	ucCmdBuf[0] = 0x10;
	SI4730_SendCmd(ucCmdBuf, 1);

	/*
		第1个形参表示最大轮询次数; 如果成功,返回值uiTimeOut > 0 表示实际轮询次数
		第2个形参0表示结束后不发送STOP, 因为还需要读取器件返回数据
	*/
	uiTimeOut = SI4730_WaitStatus80(10, 0);
	if (uiTimeOut == 0)
	{
		return 0;
	}

	/* 连续读取8个字节的器件返回信息 */
	for (i = 0; i < 8; i++)
	{
		i2c_Ack();
		_ReadBuf[i] = i2c_ReadByte();
	}
	i2c_NAck();
	i2c_Stop();
	return 1;
}
示例#4
0
	/*
	*********************************************************************************************************
	*	函 数 名: SI4730_GetRevision
	*	功能说明: 读取器件、固件信息。 返回8字节数据
	*	形    参:_ReadBuf  返回结果存放在此缓冲区,请保证缓冲区大小大于等于8
	*	返 回 值: 0 失败, 1 成功
	*********************************************************************************************************
	*/
	uint8_t SI4730_GetRevision(uint8_t *_ReadBuf)
	{
		uint8_t ack;
		uint8_t status;
		uint32_t i;

		/* AN223 page = 67 */

		/* 发送 0x10 命令 */
		i2c_Start();
		i2c_SendByte(I2C_ADDR_SI4730_W);
		ack = i2c_WaitAck();
		i2c_SendByte(0x10);
		ack = i2c_WaitAck();
		i2c_Stop();

		/* 等待器件状态为 0x80 */
		for (i = 0; i < 50; i++)
		{
			i2c_Start();
			i2c_SendByte(I2C_ADDR_SI4730_R);	/* 读 */
			ack = i2c_WaitAck();
			status = i2c_ReadByte();
			if (status == 0x80)
			{
				break;
			}
		}
		/* 实测 2 次循环应该正常退出 */
		if (i == 50)
		{
			i2c_NAck();
			i2c_Stop();
			return 0;
		}

		/* 连续读取8个字节的器件返回信息 */
		for (i = 0; i < 8; i++)
		{
			i2c_Ack();
			_ReadBuf[i] = i2c_ReadByte();
		}
		i2c_NAck();
		i2c_Stop();
		return 1;
	}
示例#5
0
/*FUNCTION*-------------------------------------------------------------------
*
* Function Name    : max3353_ReadReg
* Returned Value   :
* Comments         : Read data from max3353 register
*    
*
*END*----------------------------------------------------------------------*/
bool max3353_ReadReg
(
    uint8_t     i2c_channel, 
    uint8_t     regAdd, 
    uint8_t*    p_regValue
)
{
    uint8_t result;
    uint32_t j;
    
    /* Send Slave Address */
    i2c_Start(i2c_channel);
    i2c_WriteByte(i2c_channel, (MAX3353_SLAVE_ADDR <<1) | 0);
    i2c_Wait(i2c_channel);
    
    /* Write Register Address */ 
    i2c_WriteByte(i2c_channel, regAdd);
    i2c_Wait(i2c_channel);

    /* Do a repeated start */
    i2c_RepeatedStart(i2c_channel);

    /* Send Slave Address */  
    i2c_WriteByte(i2c_channel, (MAX3353_SLAVE_ADDR << 1) | 0x01); 
    i2c_Wait(i2c_channel);

    /* Put in Rx Mode */
    i2c_SetRXMode(i2c_channel);

    /* Turn off ACK */
    i2c_GiveNACK(i2c_channel);

    /* Dummy read */
    result = i2c_ReadByte(i2c_channel);
    for (j=0; j<5000; j++){};  
    i2c_Wait(i2c_channel);
    
    /* Send stop signal */
    i2c_Stop(i2c_channel);

    result = i2c_ReadByte(i2c_channel);
    Pause();
    *p_regValue = result;
    return TRUE;
}
示例#6
0
文件: kompas.c 项目: deazurain/uni
int main(int argc, char **argv)
{
  int fd = i2c_InitFile(0);
  FILE * fout = fopen("measures.txt", "w");

  if(i2c_BindDevice(fd, SENSOR_COMPASS) < 0) {
    printf("shit");
    return -1;
  }

  int n = 0;
  while(n < 20) {

    /*
    if(i2c_WriteByte(fd, SENSOR_CMDREG, 0x51) < 0) {
      printf("damn");
      return -2;
    }
    */

    sleep(1);

    unsigned char res1 = i2c_ReadByte(fd, 2);
    unsigned char res2 = i2c_ReadByte(fd, 3);

    unsigned short res = (res1 << 8) + res2;

    if(n < 10) {
      printf("meting #0%d: %dcm\n", n, res);
    }
    else {
      printf("meting #%d: %dcm\n", n, res);
    }
    fprintf(fout, "%d\t%d\n", n, res);

    n++;
  }

  return 0;
}
示例#7
0
文件: 24c01.c 项目: pal73/fat470
//-----------------------------------------------
void _24c01_read_nbyte(short adr, char* buff, char n)
{
char i;
i2c_Start();
i2c_SendByte(0xa0);
if(i2c_ReadAcknowledge()) goto Stop_label_24c01_read_nbyte;
i2c_SendByte((char)adr);
if(i2c_ReadAcknowledge()) goto Stop_label_24c01_read_nbyte;
i2c_Restart();
i2c_SendByte(0xa1);
if(i2c_ReadAcknowledge()) goto Stop_label_24c01_read_nbyte;
for(i=0;i<(n-1);i++)
	{
	buff[i]=i2c_ReadByte();
	i2c_SendAcknowledge(1);
	}
buff[i]=i2c_ReadByte();
i2c_SendAcknowledge(0);
Stop_label_24c01_read_nbyte: 
i2c_Stop();

}
示例#8
0
文件: 24c01.c 项目: pal73/fat470
//-----------------------------------------------
short _24c01_read_2byte(short adr)
{
short temp;
char temp1;
i2c_Start();
i2c_SendByte(0xa0);
if(i2c_ReadAcknowledge()) goto Stop_label_24c01_read_2byte;
i2c_SendByte((char)adr);
if(i2c_ReadAcknowledge()) goto Stop_label_24c01_read_2byte;
i2c_Restart();
i2c_SendByte(0xa1);
if(i2c_ReadAcknowledge()) goto Stop_label_24c01_read_2byte;
temp1=i2c_ReadByte();
i2c_SendAcknowledge(1);
temp=i2c_ReadByte();
i2c_SendAcknowledge(0);
Stop_label_24c01_read_2byte: 
i2c_Stop();
temp<<=8;
temp+=temp1;
return temp;
}
示例#9
0
	/*
	*********************************************************************************************************
	*	函 数 名: SI4730_PowerUp_FM_Revice
	*	功能说明: 配置Si4703为FM接收模式, 模拟模式(非数字模式)
	*	形    参:无
	*	返 回 值: 0 失败, 1 成功
	*********************************************************************************************************
	*/
	uint8_t SI4730_PowerUp_FM_Revice(void)
	{
		uint8_t ack;
		uint8_t status;

		/* AN332  page = 277
			Powerup in Analog Mode
			CMD      0x01     POWER_UP
			ARG1     0xC0     Set to FM Receive. Enable interrupts.
			ARG2     0x05     Set to Analog Audio Output
			STATUS   →0x80   Reply Status. Clear-to-send high.
		*/
		i2c_Start();
		i2c_SendByte(I2C_ADDR_SI4730_W);
		ack = i2c_WaitAck();
		i2c_SendByte(0x01);
		ack = i2c_WaitAck();
		i2c_SendByte(0xC0);
		ack = i2c_WaitAck();
		i2c_SendByte(0x05);
		ack = i2c_WaitAck();
		i2c_Stop();

		/* 等待器件返回状态 0x80 */
		{
			uint32_t i;

			for (i = 0; i < 2500; i++)
			{
				i2c_Start();
				i2c_SendByte(I2C_ADDR_SI4730_R);	/* 读 */
				ack = i2c_WaitAck();
				status = i2c_ReadByte();
				i2c_NAck();
				i2c_Stop();

				if (status == 0x80)
				{
					break;
				}
			}

			/* 实测 535 次循环应该正常退出 */
			if (i == 2500)
			{
				return 0;
			}
		}

		return 1;
	}
示例#10
0
/*
*********************************************************************************************************
*	函 数 名: SI4730_WaitStatus80
*	功能说明: 读取Si4730的状态,等于0x80时返回。
*	形    参: _uiTimeOut : 轮询次数
*			  _ucStopEn : 状态0x80检测成功后,是否发送STOP
*	返 回 值: 0 失败(器件无应答), > 1 成功, 数字表示实际轮询次数
*********************************************************************************************************
*/
uint32_t SI4730_WaitStatus80(uint32_t _uiTimeOut, uint8_t _ucStopEn)
{
	uint8_t ack;
	uint8_t status;
	uint32_t i;

	/* 等待器件状态为 0x80 */
	for (i = 0; i < _uiTimeOut; i++)
	{
		i2c_Start();
		i2c_SendByte(I2C_ADDR_SI4730_R);	/* 读 */
		ack = i2c_WaitAck();
		if (ack == 1)
		{
			i2c_NAck();
			i2c_Stop();
			return 0;	/* 器件无应答,失败 */
		}
		status = i2c_ReadByte();
		if ((status == 0x80) || (status == 0x81))	/* 0x81 是为了执行0x23指令 读取信号质量 */
		{
			break;
		}
	}
	if (i == _uiTimeOut)
	{
		i2c_NAck();
		i2c_Stop();
		return 0;	/* 超时了,失败 */
	}

	/* 成功了, 处理一下第1次就成功的情况 */
	if (i == 0)
	{
		i = 1;

	}

	/* 因为有些命令还需要读取返回值,因此此处根据形参决定是否发送STOP */
	if  (_ucStopEn == 1)
	{
		i2c_NAck();
		i2c_Stop();
	}
	return i;
}
uint8_t i2c_Read(uint8_t anbt_dev_addr, uint8_t anbt_reg_addr, uint8_t anbt_i2c_len, uint8_t *anbt_i2c_data_buf)
{
	
		i2c_Start();
		i2c_SendByte(anbt_dev_addr << 1 | I2C_Direction_Transmitter);			//发送陀螺仪写地址
		i2c_SendByte(anbt_reg_addr);  //发送陀螺仪ID地址
		i2c_Start();
		i2c_SendByte(anbt_dev_addr << 1 | I2C_Direction_Receiver);      //发送陀螺仪读地址
		//
    while (anbt_i2c_len)
		{
			if (anbt_i2c_len==1) *anbt_i2c_data_buf =i2c_ReadByte();  
      else *anbt_i2c_data_buf =i2c_ReceiveByte_WithACK();
      anbt_i2c_data_buf++;
      anbt_i2c_len--;
    }
		i2c_Stop();
    return 0x00;
}
示例#12
0
/*
*********************************************************************************************************
*	函 数 名: SI4730_GetFMSignalQuality
*	功能说明: 读取FM接收信号质量
*	形    参: _ReadBuf 返回结果存放在此缓冲区,请保证缓冲区大小大于等于7
*	返 回 值: 0 失败, 1 成功
*********************************************************************************************************
*/
uint8_t SI4730_GetFMSignalQuality(uint8_t *_ReadBuf)
{
	/*
		FM_RSQ_STATUS
		Queries the status of the Received Signal Quality (RSQ) for
		the current channel.

		CMD      0x23    FM_RSQ_STATUS
		ARG1     0x01    Clear RSQINT
		STATUS   ?0x80   Reply Status. Clear-to-send high.
		RESP1    ?0x00   No blend, SNR high, low, RSSI high or low interrupts.
		RESP2    ?0x01   Soft mute is not engaged, no AFC rail, valid frequency.
		RESP3    ?0xD9   Pilot presence, 89% blend
		RESP4    ?0x2D   RSSI = 45 dBμV
		RESP5    ?0x33   SNR = 51 dB
		RESP6    ?0x00
		RESP7    ?0x00   Freq offset = 0 kHz
	*/
	uint8_t ucCmdBuf[32];
	uint32_t uiTimeOut;
	uint32_t i;

	ucCmdBuf[0] = 0x23;
	ucCmdBuf[1] = 0x01;
	SI4730_SendCmd(ucCmdBuf, 2);

	uiTimeOut = SI4730_WaitStatus80(1000, 0);
	if (uiTimeOut == 0)
	{
		return 0;
	}

	/* 连续读取7个字节的器件返回信息 */
	for (i = 0; i < 7; i++)
	{
		i2c_Ack();
		_ReadBuf[i] = i2c_ReadByte();
	}
	i2c_NAck();
	i2c_Stop();
	return 1;
}
示例#13
0
/*
*********************************************************************************************************
*	函 数 名: SI4730_GetAMTuneStatus
*	功能说明: 读取AM调谐状态
*	形    参: 返回结果存放在此缓冲区,请保证缓冲区大小大于等于7
*	返 回 值: 0 失败, 1 成功
*********************************************************************************************************
*/
uint8_t SI4730_GetAMTuneStatus(uint8_t *_ReadBuf)
{
	/*
		CMD       0x42           AM_TUNE_STATUS
		ARG1      0x01           Clear STC interrupt.
		STATUS    ?0x80          Reply Status. Clear-to-send high.

		RESP1     ?0x01          Channel is valid, AFC is not railed, and seek did not wrap at AM band boundary
		RESP2     ?0x03
		RESP3     ?0xE8          Frequency = 0x03E8 = 1000 kHz
		RESP4     ?0x2A          RSSI = 0x2A = 42d = 42 dBμV
		RESP5     ?0x1A          SNR = 0x1A = 26d = 26 dB
		RESP6     ?0x0D          Value the antenna tuning capacitor is set to.
		RESP7     ?0x95          0x0D95 = 3477 dec.
	
		电容计算 The tuning capacitance is 95 fF x READANTCAP + 7 pF	
	*/
	uint8_t ucCmdBuf[32];
	uint32_t uiTimeOut;
	uint32_t i;

	ucCmdBuf[0] = 0x42;
	ucCmdBuf[1] = 0x01;
	SI4730_SendCmd(ucCmdBuf, 2);

	uiTimeOut = SI4730_WaitStatus80(100, 0);
	if (uiTimeOut == 0)
	{
		return 0;
	}

	/* 连续读取7个字节的器件返回信息 */
	for (i = 0; i < 7; i++)
	{
		i2c_Ack();
		_ReadBuf[i] = i2c_ReadByte();
	}
	i2c_NAck();
	i2c_Stop();
	return 1;

}
示例#14
0
/*
*********************************************************************************************************
*	函 数 名: MPU6050_ReadByte
*	功能说明: 读取 MPU-6050 寄存器的数据
*	形    参: _ucRegAddr : 寄存器地址
*	返 回 值: 无
*********************************************************************************************************
*/
uint8_t MPU6050_ReadByte(uint8_t _ucRegAddr)
{
	uint8_t ucData;

	i2c_Start();                  			/* 总线开始信号 */
	i2c_SendByte(MPU6050_SLAVE_ADDRESS);	/* 发送设备地址+写信号 */
	i2c_WaitAck();
	i2c_SendByte(_ucRegAddr);     			/* 发送存储单元地址 */
	i2c_WaitAck();

	i2c_Start();                  			/* 总线开始信号 */

	i2c_SendByte(MPU6050_SLAVE_ADDRESS+1); 	/* 发送设备地址+读信号 */
	i2c_WaitAck();

	ucData = i2c_ReadByte();       			/* 读出寄存器数据 */
	i2c_NAck();
	i2c_Stop();                  			/* 总线停止信号 */
	return ucData;
}
示例#15
0
/*
*********************************************************************************************************
*	函 数 名: SI4730_GetAMSignalQuality
*	功能说明: 读取AM接收信号质量
*	形    参: _ReadBuf 返回结果存放在此缓冲区,请保证缓冲区大小大于等于5
*	返 回 值: 0 失败, 1 成功
*********************************************************************************************************
*/
uint8_t SI4730_GetAMSignalQuality(uint8_t *_ReadBuf)
{
	/*
		AM_RSQ_STATUS
		Queries the status of the Received Signal Quality (RSQ) for
		the current channel.

		CMD        0x43      AM_RSQ_STATUS
		ARG1       0x01      Clear STC interrupt.
		STATUS     ?0x80     Reply Status. Clear-to-send high.

		RESP1      ?0x00     No SNR high, low, RSSI high, or low interrupts.
		RESP2      ?0x01     Channel is valid, soft mute is not activated, and AFC is not railed
		RESP3      ?0x00
		RESP4      ?0x2A     RSSI = 0x2A = 42d = 42 dBμV
		RESP5      ?0x1A     SNR = 0x1A = 26d = 26 dB
	*/
	uint8_t ucCmdBuf[32];
	uint32_t uiTimeOut;
	uint32_t i;

	ucCmdBuf[0] = 0x43;
	ucCmdBuf[1] = 0x01;
	SI4730_SendCmd(ucCmdBuf, 2);

	uiTimeOut = SI4730_WaitStatus80(100, 0);
	if (uiTimeOut == 0)
	{
		return 0;
	}

	/* 连续读取5个字节的器件返回信息 */
	for (i = 0; i < 5; i++)
	{
		i2c_Ack();
		_ReadBuf[i] = i2c_ReadByte();
	}
	i2c_NAck();
	i2c_Stop();
	return 1;
}
示例#16
0
/*
*********************************************************************************************************
*	函 数 名: SI4730_GetFMTuneStatus
*	功能说明: 读取FM调谐状态
*	形    参: 返回结果存放在此缓冲区,请保证缓冲区大小大于等于7
*	返 回 值: 0 失败, 1 成功
*********************************************************************************************************
*/
uint8_t SI4730_GetFMTuneStatus(uint8_t *_ReadBuf)
{
	/*
		CMD      0x22     FM_TUNE_STATUS
		ARG1     0x01     Clear STC interrupt.
		STATUS   ?0x80    Reply Status. Clear-to-send high.

		RESP1    ?0x01    Valid Frequency.
		RESP2    ?0x27    Frequency = 0x27F6 = 102.3 MHz
		RESP3    ?0xF6
		RESP4    ?0x2D    RSSI = 45 dBμV
		RESP5    ?0x33    SNR = 51 dB
		RESP6    ?0x00    MULT[7:0]
		RESP7    ?0x00    Antenna tuning capacitor = 0 (range = 0–191)  READANTCAP[7:0] (Si4704/05/06/2x only)
	*/
	uint8_t ucCmdBuf[32];
	uint32_t uiTimeOut;
	uint32_t i;

	ucCmdBuf[0] = 0x22;
	ucCmdBuf[1] = 0x01;
	SI4730_SendCmd(ucCmdBuf, 2);

	uiTimeOut = SI4730_WaitStatus80(100, 0);
	if (uiTimeOut == 0)
	{
		return 0;
	}

	/* 连续读取7个字节的器件返回信息 */
	for (i = 0; i < 7; i++)
	{
		i2c_Ack();
		_ReadBuf[i] = i2c_ReadByte();
	}
	i2c_NAck();
	i2c_Stop();
	return 1;

}
示例#17
0
/*
*********************************************************************************************************
*	函 数 名: MPU6050_ReadData
*	功能说明: 读取 MPU-6050 数据寄存器, 结果保存在全局变量 g_tMPU6050.  主程序可以定时调用该程序刷新数据
*	形    参: 无
*	返 回 值: 无
*********************************************************************************************************
*/
void MPU6050_ReadData(void)
{
	uint8_t ucReadBuf[14];
	uint8_t i;
	uint8_t ack;

#if 1 /* 连续读 */
	i2c_Start();                  			/* 总线开始信号 */
	i2c_SendByte(MPU6050_SLAVE_ADDRESS);	/* 发送设备地址+写信号 */
	ack = i2c_WaitAck();
	if (ack != 0)
	{
		i2c_Stop(); 
		return;
	}
	i2c_SendByte(ACCEL_XOUT_H);     		/* 发送存储单元地址  */
	ack = i2c_WaitAck();
	if (ack != 0)
	{
		i2c_Stop(); 
		return;
	}

	i2c_Start();                  			/* 总线开始信号 */

	i2c_SendByte(MPU6050_SLAVE_ADDRESS + 1); /* 发送设备地址+读信号 */
	ack = i2c_WaitAck();
	if (ack != 0)
	{
		i2c_Stop(); 
		return;
	}

	for (i = 0; i < 13; i++)
	{
		ucReadBuf[i] = i2c_ReadByte();       			/* 读出寄存器数据 */
		i2c_Ack();
	}

	/* 读最后一个字节,时给 NAck */
	ucReadBuf[13] = i2c_ReadByte();
	i2c_NAck();

	i2c_Stop();                  			/* 总线停止信号 */

#else	/* 单字节读 */
	for (i = 0 ; i < 14; i++)
	{
		ucReadBuf[i] = MPU6050_ReadByte(ACCEL_XOUT_H + i);
	}
#endif

	/* 将读出的数据保存到全局结构体变量 */
	g_tMPU6050.Accel_X = (ucReadBuf[0] << 8) + ucReadBuf[1];
	g_tMPU6050.Accel_Y = (ucReadBuf[2] << 8) + ucReadBuf[3];
	g_tMPU6050.Accel_Z = (ucReadBuf[4] << 8) + ucReadBuf[5];

	g_tMPU6050.Temp = (int16_t)((ucReadBuf[6] << 8) + ucReadBuf[7]);

	g_tMPU6050.GYRO_X = (ucReadBuf[8] << 8) + ucReadBuf[9];
	g_tMPU6050.GYRO_Y = (ucReadBuf[10] << 8) + ucReadBuf[11];
	g_tMPU6050.GYRO_Z = (ucReadBuf[12] << 8) + ucReadBuf[13];
}
示例#18
0
/*
*********************************************************************************************************
*	函 数 名: SI4730_SetAMFreqCap
*	功能说明: 设置AM调谐频率
*	形    参:_uiFreq : 频率值, 单位 10kHz    _usCap : 调谐电容
*	返 回 值: 0 失败, 1 成功
*********************************************************************************************************
*/
uint8_t SI4730_SetAMFreqCap(uint32_t _uiFreq, uint16_t _usCap)
{
	/* AN332 page = 70 */

	/*
		CMD       0x40        AM_TUNE_FREQ
		ARG1      0x00
		ARG2      0x03        Set frequency to 1000 kHz = 0x03E8
		ARG3      0xE8
		ARG4      0x00        Automatically select tuning capacitor
		ARG5      0x00
		STATUS    ?0x80       Reply Status. Clear-to-send high.
	*/

	/* 64 and 108 MHz in 10 kHz units. */

	uint8_t ucCmdBuf[32];
	uint32_t uiTimeOut;
	uint32_t i;
	uint8_t status;

	ucCmdBuf[0] = 0x40;
	ucCmdBuf[1] = 0x00;
	ucCmdBuf[2] = _uiFreq >> 8;
	ucCmdBuf[3] = _uiFreq;
	ucCmdBuf[4] = _usCap >> 8;
	ucCmdBuf[5] = _usCap;
	SI4730_SendCmd(ucCmdBuf, 6);

	uiTimeOut = SI4730_WaitStatus80(10000, 1);
	if (uiTimeOut == 0)
	{
		return 0;
	}

	/* 等待器件状态为 0x81 */
	for (i = 0; i < 5000; i++)
	{
		/* 0x14. GET_INT_STATUS */
		ucCmdBuf[0] = 0x14;
		SI4730_SendCmd(ucCmdBuf, 1);

		SI4730_Delay(10000);

		i2c_Start();
		i2c_SendByte(I2C_ADDR_SI4730_R);	/* 读 */
		i2c_WaitAck();
		status = i2c_ReadByte();
		i2c_Stop();
		if (status == 0x81)
		{
			break;
		}
	}

	if (i == 5000)
	{
		return 0;	/* 失败 */
	}
	return 1;
}
示例#19
0
/*
 * @brief: Read FIFO ctl register
 * @param[in]: ptr to variable
 * @param[out]: none
 */
void adxl345_ReadFIFOCtl(uint8_t *fifo){
	*fifo = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_FIFO_CTL);
}
示例#20
0
/*
 * @brief: Read FIFO status register
 * @param[in]: ptr to variable
 * @param[out]: none
 */
void adxl345_ReadFIFOStatus(uint8_t *fifost){
	*fifost = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_FIFO_STATUS);
}
示例#21
0
/*
*********************************************************************************************************
*	函 数 名: SI4730_SetFMFreq
*	功能说明: 设置FM调谐频率
*	形    参:_uiFreq : 频率值, 单位 10kHz
*	返 回 值: 0 失败, 1 成功
*********************************************************************************************************
*/
uint8_t SI4730_SetFMFreq(uint32_t _uiFreq)
{
	/* AN332 page = 70 */

	/*
		CMD		 0x20 	FM_TUNE_FREQ
		ARG1     0x00
		ARG2     0x27	Set frequency to 102.3 MHz = 0x27F6
		ARG3     0xF6
		ARG4     0x00   Set antenna tuning capacitor to auto.
		STATUS   ?0x80	Reply Status. Clear-to-send high.
	*/

	/* 64 and 108 MHz in 10 kHz units. */

	uint8_t ucCmdBuf[32];
	uint32_t uiTimeOut;
	uint32_t i;
	uint8_t status;

	ucCmdBuf[0] = 0x20;
	ucCmdBuf[1] = 0x00;
	ucCmdBuf[2] = _uiFreq >> 8;
	ucCmdBuf[3] = _uiFreq;
	ucCmdBuf[4] = 0x00;
	SI4730_SendCmd(ucCmdBuf, 5);

	uiTimeOut = SI4730_WaitStatus80(1000, 1);
	if (uiTimeOut == 0)
	{
		return 0;
	}



	/* 等待器件状态为 0x81 */
	for (i = 0; i < 5000; i++)
	{
		/* 0x14. GET_INT_STATUS */
		ucCmdBuf[0] = 0x14;
		SI4730_SendCmd(ucCmdBuf, 1);

		SI4730_Delay(10000);

		i2c_Start();
		i2c_SendByte(I2C_ADDR_SI4730_R);	/* 读 */
		i2c_WaitAck();
		status = i2c_ReadByte();
		i2c_Stop();
		if (status == 0x81)
		{
			break;
		}
	}

	if (i == 5000)
	{
		return 0;	/* 失败 */
	}
	return 1;
}
示例#22
0
/*
 * @brief: Read Z axis offset
 * @param[in]: ptr to variable
 * @param[out]: none
 */
void adxl345_ReadZOffSet(int8_t *zoff){
	*zoff = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_OFSZ);
}
示例#23
0
/*
 * @brief: Read from the enabled interrupts
 * @param[in]: ptr to variable
 * @param[out]: none
 */
void adxl345_ReadINTEnable(uint8_t *inten){
	*inten = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_INT_ENABLE);
}
示例#24
0
/*
 * @brief: Read X, Y, Z axis offset
 * @param[in]: ptr to variables
 * @param[out]: none
 */
void adxl345_ReadXYZOffSet(int8_t *xoff, int8_t *yoff, int8_t *zoff){
	*xoff = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_OFSX);
	*yoff = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_OFSY);
	*zoff = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_OFSZ);
}
示例#25
0
/*
 * @brief: Read Y axis offset
 * @param[in]: ptr to variable
 * @param[out]: none
 */
void adxl345_ReadYOffSet(int8_t *yoff){
	*yoff = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_OFSY);
}
示例#26
0
/*
 * @brief: Test ADXL345 module address
 * @param[in]: none
 * @param[out]: 1 if successful, 0 if not
 */
uint8_t adxl345_test(void){
	uint8_t temp;
	temp = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_DEVID);
	return temp == 0xE5 ? 1 : 0;
}
示例#27
0
/*
 * @brief: Read from the int source register
 * @param[in]: ptr to variable
 * @param[out]: none
 */
void adxl345_ReadINTSource(uint8_t *intsource){
	*intsource = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_INT_SOURCE);
}
示例#28
0
/*
 * @brief: Read temperature
 * @param[in]: ptr to temp data
 * @param[out]: none
 */
void l3g4200d_ReadTemp(int8_t *temp)
{
	uint8_t b;
	b =  i2c_ReadByte(I2C_ID_L3G4200D, OUT_TEMP);
	*temp = (int8_t)(40 - b);
}
示例#29
0
/*
 * @brief: Test connection for l3g4200d
 * @param[in]: none
 * @param[out]: Test result, 1: Successful, 0: Not
 */
uint8_t l3g4200d_Test(void)
{
	uint8_t temp;
	temp = i2c_ReadByte(I2C_ID_L3G4200D, WHO_AM_I);
	return temp == 0xD3 ? 1 :  0;
}
示例#30
0
/*
 * @brief: Read from the data format register
 * @param[in]: ptr to variable
 * @param[out]: none
 */
void adxl345_ReadDataFormat(uint8_t *data){
	*data = i2c_ReadByte(I2C_ID_ADXL345, ADXL345_RA_DATA_FORMAT);
}