本文整理汇总了C++中i2c_write_byte函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_write_byte函数的具体用法?C++ i2c_write_byte怎么用?C++ i2c_write_byte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i2c_write_byte函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: i2c_disp_init
void i2c_disp_init (void)
{
__u16 val;
omap_i2c_outw(0x2, I2C_SYSC);
udelay(1000);
omap_i2c_outw(0x0, I2C_SYSC);
val = omap_i2c_inw(I2C_CON);
if (val & I2C_CON_EN) {
omap_i2c_outw(0, I2C_CON);
udelay (50000);
}
omap_i2c_outw(0, I2C_PSC);
val = 0xfff9;
omap_i2c_outw(val, I2C_SCLL);
omap_i2c_outw(val, I2C_SCLH);
omap_i2c_outw(1, I2C_OA);
omap_i2c_outw(I2C_CON_EN, I2C_CON);
omap_i2c_outw(0x1F, I2C_IE);
i2c_flush();
omap_i2c_outw(0xFFFF, I2C_STAT);
omap_i2c_outw(0, I2C_CNT);
// init disp
i2c_write_byte (0x49, 0x9B, 0x80);
i2c_write_byte (0x49, 0x9E, 0x80);
}
示例2: MPU_9050_init
void MPU_9050_init (void)
{
// Configure Pins for I2C
P1SEL0 |= BIT6 | BIT7; // I2C pins
__enable_interrupt();
NVIC_ISER0 = 1 << ((INT_EUSCIB0 - 16) & 31); // Enable eUSCIB0 interrupt in NVIC module
// Configure USCI_B0 for I2C mode
UCB0CTLW0 |= UCSWRST; // put eUSCI_B in reset state
UCB0CTLW0 |= UCMODE_3 | UCMST; // I2C master mode, SMCLK
UCB0BRW = 0x0018; // baudrate = SMCLK /24
UCB0CTLW0 &=~ UCSWRST; // clear reset register
UCB0IE |= UCTXIE0 | UCNACKIE; // transmit and NACK interrupt enable
UCB0I2CSA = MPU_dir; // Adress
while (UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent (channel empty)
i2c_write_byte(MPU_START,MPU_PWR_MGMT_1);
i2c_write_byte(MPU_START,MPU_PWR_MGMT_1);
i2c_write_byte(MPU_LPFIL,MPU_CONFIG_GLOBAL);
i2c_write_byte(0x00,MPU_CONFIG_G);
}
示例3: send_data
//------------------------------------------------------------------------
static void send_data ( unsigned int data )
{
//PUT32(GPSET0,1<<25); //D/C = 1 for data
//spi_one_byte(data);
i2c_start();
if(i2c_write_byte(PADDR))
{
i2c_stop();
hexstring(0xBADBAD00);
return;
}
//not continuing
//want D/C a one
if(i2c_write_byte(0x40))
{
//i2c_stop();
//hexstring(0xBADBAD00);
//return;
}
if(i2c_write_byte(data))
{
//i2c_stop();
//hexstring(0xBADBAD00);
//return;
}
i2c_stop();
}
示例4: I2C_ReadOneByte
uint8_t I2C_ReadOneByte(uint8_t SlaveAddr, uint8_t RegAddr)
{
uint8_t result;
i2c_start(I2C0_B);
i2c_write_byte(I2C0_B, (SlaveAddr<<1) | I2C_WRITE);
i2c_wait(I2C0_B);
i2c_get_ack(I2C0_B);
i2c_write_byte(I2C0_B, RegAddr);
i2c_wait(I2C0_B);
i2c_get_ack(I2C0_B);
i2c_repeated_start(I2C0_B);
i2c_write_byte(I2C0_B, (SlaveAddr<<1) | I2C_READ);
i2c_wait(I2C0_B);
i2c_get_ack(I2C0_B);
i2c_set_rx_mode(I2C0_B);
i2c_give_nack(I2C0_B);
result = i2c_read_byte(I2C0_B);
i2c_wait(I2C0_B);
i2c_stop(I2C0_B);
result = i2c_read_byte(I2C0_B);
pause(40);
return result;
}
示例5: imu_g_read_data_raw
void imu_g_read_data_raw(vector *v)
{
unsigned char xl,xh,yl,yh,zl,zh;
i2c_start();
i2c_write_byte(0xD0);
i2c_write_byte(0x1d);
i2c_start();
i2c_write_byte(0xD1);
xh = i2c_read_byte();
xl = i2c_read_byte();
yh = i2c_read_byte();
yl = i2c_read_byte();
zh = i2c_read_byte();
zl = i2c_read_last_byte();
i2c_stop();
v->x = xh << 8 | xl;
v->y = yh << 8 | yl;
v->z = zh << 8 | zl;
}
示例6: i2c_read_reg
/*!
* @brief 读取I2C设备指定地址寄存器的数据
* @param I2Cn_e I2C模块(I2C0、I2C1)
* @param SlaveID 从机地址(7位地址)
* @param reg 从机寄存器地址
* @return 读取的寄存器值
* @since v5.0
* Sample usage: uint8 value = i2c_read_reg(I2C0, 0x1D, 1);
*/
uint8 i2c_read_reg(I2Cn_e i2cn, uint8 SlaveID, uint8 reg)
{
//先写入寄存器地址,再读取数据,因此此过程是 I2C 的复合格式,改变数据方向时需要重新启动
uint8 result;
ASSERT((SlaveID & 0x80) == 0); //断言,我们要求的7位地址的值仅仅是7bit,不是通信时要求的高7位
//有些手册,给出的7位地址指的是8bit里的高7位
//有些手册,给出的7位地址指的是7bit
//请自行确认,可以尝试是否通信正常来确认
i2c_Start(i2cn); //发送启动信号
i2c_write_byte(i2cn, ( SlaveID << 1 ) | MWSR); //发送从机地址和写位
i2c_write_byte(i2cn, reg); //发送从机里的寄存器地址
i2c_RepeatedStart(i2cn); //复合格式,发送重新启动信号
i2c_write_byte(i2cn, ( SlaveID << 1) | MRSW ); //发送从机地址和读位
i2c_PutinRxMode(i2cn); //进入接收模式(不应答,只接收一个字节)
result = I2C_D_REG(I2CN[i2cn]); //虚假读取一次,启动接收数据
i2c_Wait(i2cn); //等待接收完成
i2c_Stop(i2cn); //发送停止信号
result = I2C_D_REG(I2CN[i2cn]); //读取数据
Pause(); //必须延时一下,否则出错
return result;
}
示例7: hal_dev_mag3110_read_reg
uint8 hal_dev_mag3110_read_reg(uint8 addr)
{
uint8 result;
i2c_start(I2C_MAG);
i2c_write_byte(I2C_MAG, MAG3110_I2C_ADDRESS | I2C_WRITE);
i2c_wait(I2C_MAG);
i2c_get_ack(I2C_MAG);
i2c_write_byte(I2C_MAG, addr);
i2c_wait(I2C_MAG);
i2c_get_ack(I2C_MAG);
i2c_repeated_start(I2C_MAG);
i2c_write_byte(I2C_MAG, MAG3110_I2C_ADDRESS | I2C_READ);
i2c_wait(I2C_MAG);
i2c_get_ack(I2C_MAG);
i2c_set_rx_mode(I2C_MAG);
i2c_give_nack(I2C_MAG);
result = i2c_read_byte(I2C_MAG);
i2c_wait(I2C_MAG);
i2c_stop(I2C_MAG);
result = i2c_read_byte(I2C_MAG);
pause();
return result;
}
示例8: bh1750fvi_sample
uint16_t bh1750fvi_sample(const bh1750fvi_t *dev)
{
uint32_t tmp;
uint8_t raw[2];
/* power on the device and send single H-mode measurement command */
DEBUG("[bh1750fvi] sample: triggering a conversion\n");
i2c_acquire(dev->i2c);
i2c_write_byte(dev->i2c, dev->addr, OP_POWER_ON, 0);
i2c_write_byte(dev->i2c, dev->addr, OP_SINGLE_HRES1, 0);
i2c_release(dev->i2c);
/* wait for measurement to complete */
xtimer_usleep(DELAY_HMODE);
/* read the results */
DEBUG("[bh1750fvi] sample: reading the results\n");
i2c_acquire(dev->i2c);
i2c_read_bytes(dev->i2c, dev->addr, raw, 2, 0);
i2c_release(dev->i2c);
/* and finally we calculate the actual LUX value */
tmp = ((uint32_t)raw[0] << 24) | ((uint32_t)raw[1] << 16);
tmp /= RES_DIV;
return (uint16_t)(tmp);
}
示例9: i2c_read
int i2c_read (uint8_t chip_id, uint8_t reg_addr, uint8_t* buffer, uint16_t len)
{
int status = 0;
/* send chip internal register address (pointer register) */
if (status == 0) i2c_send_start ();
if (status == 0) status = i2c_write_byte (chip_id << 1 | I2C_WRITE_OPER);
if (status == 0) status = i2c_write_byte (reg_addr);
if (status == 0) i2c_send_repeated_start ();
/* send again chip id before to switch to read mode */
if (status == 0) status = i2c_write_byte ((chip_id << 1) | I2C_READ_OPER);
if (status == 0) i2c_switch_to_read_operation(len > 1);
/* read specified number of bytes */
if (status == 0) {
while (len > 1) {
*buffer++ = i2c_read_byte (--len > 1);
}
}
i2c_send_stop ();
if (status == 0) *buffer++ = i2c_read_byte (false);
return status;
}
示例10: I2C_GPIO_Write_iM205
unsigned char I2C_GPIO_Write_iM205 (unsigned char addr, unsigned char reg, unsigned char val )
{
unsigned char state, data;
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
APP_TRACE_INFO(("\r\nI2C_GPIO_Write_iM205(0x%0X,0x%0X, 0x%0X)", addr, reg, val));
OS_ENTER_CRITICAL();
i2c_start(); //起始条件,开始数据通信
//发送地址和数据读写方向
data = (addr << 1) | 0; //低位为0,表示写数据
state = i2c_write_byte(data);
if(state != 0) {
i2c_stop();
OS_EXIT_CRITICAL();
//APP_TRACE_INFO(("\r\n write byte err1!"));
return 1;
}
//写入数据
state = i2c_write_byte( reg );
if(state != 0) {
i2c_stop();
OS_EXIT_CRITICAL();
//APP_TRACE_INFO(("\r\n write byte err2!"));
return 1;
}
i2c_restart();
//发送地址和数据读写方向
data = (addr << 1) | 0; //低位为0,表示写数据
state = i2c_write_byte(data);
if(state != 0) {
i2c_stop();
OS_EXIT_CRITICAL();
//APP_TRACE_INFO(("\r\n write byte err3!"));
return 1;
}
//写入数据
state = i2c_write_byte( val );
if(state != 0) {
i2c_stop();
OS_EXIT_CRITICAL();
//APP_TRACE_INFO(("\r\n write byte err4!"));
return 1;
}
i2c_stop(); //终止条件,结束数据通信
OS_EXIT_CRITICAL();
return 0;
}
示例11: pcf8536_read
/*************************************************************************
** 函数名称: pcf8536_read(uint8 addr,uint8 *p,uint8 num)
** 功能描述: 读pcf8563
** 输 入: uint8 addr :高八位为器件地址,低八位为内部寄存器地址
uint8 *p :读出的数据存放地址的起始地址
uint8 num :读出数据的个数
**************************************************************************/
void pcf8536_read(uint8 addr,uint8 *p,uint8 num)
{
uint8 *pbuf = p;
i2c_start();
if(i2c_write_byte(WR_ADDR_CMD)==SLA_W)
{
i2c_write_byte(addr);
}
else
{
syserr=ERR_SLA_W;
}
i2c_start();
if(i2c_write_byte(RD_ADDR_CMD)==SLA_W)
{
i2c_write_byte(addr);
}
else
{
syserr=ERR_SLA_W;
}
for(; num > 0; num--)
{
*pbuf = i2c_read_byte();
pbuf++;
}
}
示例12: send_command
//------------------------------------------------------------------------
//static unsigned int i2c_read_byte ( unsigned int *b )
//{
//unsigned int ra;
//unsigned int rb;
//i2c_delay();
//sda_input();
//rb=0;
//for(ra=0;ra<9;ra++)
//{
//i2c_delay();
//scl_high();
//i2c_delay();
//rb<<=1;
//if(sda_read()) rb|=1;
//i2c_delay();
//scl_low();
//i2c_delay();
//}
//sda_output();
//i2c_delay();
//ra=rb&1;
//*b=rb>>1;
//return(ra);
//}
//------------------------------------------------------------------------
static void send_command ( unsigned int cmd )
{
// PUT32(GPCLR0,1<<25); //D/C = 0 for command
//spi_one_byte(cmd);
i2c_start();
if(i2c_write_byte(PADDR))
{
i2c_stop();
hexstring(0xBADBAD00);
return;
}
//not continuing
//want D/C a zero
if(i2c_write_byte(0x00))
{
//i2c_stop();
//hexstring(0xBADBAD00);
//return;
}
if(i2c_write_byte(cmd))
{
//i2c_stop();
//hexstring(0xBADBAD00);
//return;
}
i2c_stop();
}
示例13: i2c_write_bytes
static int
i2c_write_bytes(wm_i2c *i2c, int reg, uint8_t *data, int datasize)
{
int retry = 60;
int i;
do {
if (reg >= 0) {
if (!i2c_write_byte(i2c, reg))
return false;
}
for (i = 0; i < datasize; i++)
if (!i2c_write_byte(i2c, data[i]))
return false;
if (!(i2c->reg->RAW_INTR_STAT.WORDVAL & 0x40 /* TX ABRT */))
break;
os_thread_sleep(os_msec_to_ticks(10));
#if I2C_VERBOSE > 1
mc_log_debug("I2C: xmit aborted [%d]: cause = 0x%x.\n", retry, i2c_get_abort_cause(i2c));
#endif
i2c_clear_abort(i2c);
} while (--retry >= 0);
#if I2C_VERBOSE
if (retry < 0)
mc_log_debug("I2C: xmit aborted!\n");
#endif
return (retry >= 0);
}
示例14: ewtsa_system_restart
static int ewtsa_system_restart(struct i2c_client *client)
{
int err;
char reg;
char smpl , dlpf;
err = i2c_write_byte(client, ( unsigned char)REG_SELF_O_C, ( unsigned char)SELF_O_C_DISABLE);
if (err < 0) {
return err;
}
///Set SMPL register
if (EWTSA_delay <= ( unsigned char)DELAY_THRES_2) {
smpl = ( unsigned char)DELAY_INTMIN_THRES;
}else{
smpl = ( unsigned char)(EWTSA_delay - ( unsigned char)1);
}
err = i2c_write_byte(client, ( unsigned char)REG_SMPL, ( unsigned char)smpl);
if (err < 0) {
return err;
}
///Set DLPF register
if (EWTSA_delay >= ( unsigned char)DELAY_THRES_6){
dlpf = ( unsigned char)DELAY_DLPF_6;
}else if (EWTSA_delay >= ( unsigned char)DELAY_THRES_5) {
dlpf = ( unsigned char)DELAY_DLPF_5;
}else if (EWTSA_delay >= ( unsigned char)DELAY_THRES_4){
dlpf = ( unsigned char)DELAY_DLPF_4;
}else if (EWTSA_delay >= ( unsigned char)DELAY_THRES_3) {
dlpf = ( unsigned char)DELAY_DLPF_3;
}else{
dlpf = ( unsigned char)DELAY_DLPF_2;
}
reg = ( unsigned char)(( unsigned char)(EWTSA_range << 3) | dlpf | ( unsigned char)0x80 ) ;
err = i2c_write_byte(client, REG_FS_DLPF, reg);
if (err < 0) {
return err;
}
if (EWTSA_calib== EWTSA_ON) {
printk("EWTSA_set_calibration() start \n");
err = i2c_write_byte(client,( unsigned char)REG_SELF_O_C, ( unsigned char)SELF_O_C_ENABLE);
if (err < 0) {
return err;
}
mdelay(500);
printk("EWTSA_set_calibration() end \n");
}
return 0;
}
示例15: adxl346_read_x
int16_t adxl346_read_x(void) {
uint8_t acceleration[2];
int16_t x;
i2c_write_byte(ADXL346_ADDRESS, ADXL346_DATAX0_ADDR);
i2c_read_byte(ADXL346_ADDRESS, &acceleration[0]);
i2c_write_byte(ADXL346_ADDRESS, ADXL346_DATAX1_ADDR);
i2c_read_byte(ADXL346_ADDRESS, &acceleration[1]);
x = (acceleration[1] << 8) | acceleration[0];
return x;
}