当前位置: 首页>>代码示例>>C++>>正文


C++ i2c_write函数代码示例

本文整理汇总了C++中i2c_write函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_write函数的具体用法?C++ i2c_write怎么用?C++ i2c_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了i2c_write函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: hyt271_get_measurements

HYT271_ERROR_t hyt271_get_measurements(double* humidity, double* temperature) {
  uint8_t buffer[HYT271_BUFFER_LEN];

  // 1. Request measurement.
  // start communication with HYT271
  if (i2c_start(HYT271_ADDR + I2C_WRITE)) {
    uart_puts_P("I2C: Failed to write-access hyt271 device.\r\n");
    i2c_stop();
    return HYT271_BUS_ERROR;
  } else {
    i2c_write(0x00);
  }
  i2c_stop();

  // 2. Wayt for some time 
  _delay_ms(HYT271_CONV_DELAY);

  // 3. Gather measurement.
  if (i2c_start(HYT271_ADDR+I2C_READ) ) {
    uart_puts_P("I2C: Failed to read-access hyt271 device.\r\n");
    i2c_stop();
    return HYT271_BUS_ERROR;
  } else {
    for(uint8_t i=0; i<HYT271_BUFFER_LEN-1; i++) {
      buffer[i]=i2c_readAck();
    }
    buffer[HYT271_BUFFER_LEN-1] = i2c_readNak();
  }
  i2c_stop();

  // 4. convert data. From the reference implementation of hygrosens:
  /*++++++++++++++++++++++++++++++++++++++++++++++++++++++
   *	GENERAL SENSOR INFORMATION
   *-------------------------------
   *	
   *	sensor abilities:
   *		/ humidity
   *			> 0x0000	- 	0x3FFF	hex
   *			> 0			- 	16383	dec
   *			> 0			- 	100		%	relative humidity
   *
   *		/ temperature
   *			> 0x0000	-	0x3FFF	hex
   *			> 0			-	16383	dec
   *			> -40		-	+125	°C
   *			> -40		-	+257	°F
   *			> +233.15	-	+398.15	K
   *
   *	raw value format:
   *
   *		|	1.byte	|	2.byte	|	3.byte	|	4.byte	|
   *		|-----------------------|-----------------------|
   *		|		Humidity		|		Temperature		|
   *		|-----------------------|-----------------------|
   *		|	2 bit	|	14 bit	|	14 bit	|	2 bit 	|
   *		|-----------|-----------|-----------|-----------|
   *		|	state	|	data	|	data	|	state	|
   *
   *
   *++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

  uint16_t rawhum = ((buffer[0]<<8 | buffer[1]) & 0x3FFF);
  *humidity = (100.0/16384.0*rawhum);
  uint16_t rawtemp = buffer[2]<<6 | (buffer[3]&0x3F);
  *temperature = (165.0/16384.0*rawtemp)-40.0;

  return HYT271_ERROR_NONE;
}
开发者ID:mysmartgrid,项目名称:hexasense,代码行数:68,代码来源:hyt271.c

示例2: isp1301_vbus_on

static inline void isp1301_vbus_on(void)
{
	i2c_write(OTG1_VBUS_DRV, ISP1301_I2C_OTG_CONTROL_1);
}
开发者ID:ArthySundaram,项目名称:firstrepo,代码行数:4,代码来源:ohci-pnx4008.c

示例3: pci_mpc83xx_init

void
pci_mpc83xx_init(volatile struct pci_controller *hose)
{
	volatile immap_t *	immr;
	volatile clk8349_t *	clk;
	volatile law8349_t *	pci_law;
	volatile pot8349_t *	pci_pot;
	volatile pcictrl8349_t *	pci_ctrl;
	volatile pciconf8349_t *	pci_conf;

	u8 val8,tmp8,ret;
	u16 reg16,tmp16;
	u32 val32,tmp32;

	immr = (immap_t *)CFG_IMMRBAR;
	clk = (clk8349_t *)&immr->clk;
	pci_law = immr->sysconf.pcilaw;
	pci_pot = immr->ios.pot;
	pci_ctrl = immr->pci_ctrl;
	pci_conf = immr->pci_conf;

	/*
	 * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
	 */
	val32 = clk->occr;
	udelay(2000);
	clk->occr = 0xff000000;
	udelay(2000);

	/*
	 * Configure PCI Local Access Windows
	 */
	pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
	pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
	pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
	pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_32M;

	/*
	 * Configure PCI Outbound Translation Windows
	 */
	pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
	pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
	pci_pot[0].pocmr = POCMR_EN | (POCMR_CM_512M & POCMR_CM_MASK);

	/* mapped to PCI1 IO space 0x0 to local 0xe2000000  */
	pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
	pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
	pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_16M & POCMR_CM_MASK);

	pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
	pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
	pci_pot[3].pocmr = POCMR_EN | POCMR_DST | (POCMR_CM_512M & POCMR_CM_MASK);

	/* mapped to PCI2 IO space 0x0 to local 0xe3000000  */
	pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
	pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
	pci_pot[4].pocmr = POCMR_EN | POCMR_DST | POCMR_IO | (POCMR_CM_16M & POCMR_CM_MASK);

	/*
	 * Configure PCI Inbound Translation Windows
	 */
	pci_ctrl[0].pitar1 = 0x0;
	pci_ctrl[0].pibar1 = 0x0;
	pci_ctrl[0].piebar1 = 0x0;
	pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_2G;

	pci_ctrl[1].pitar1 = 0x0;
	pci_ctrl[1].pibar1 = 0x0;
	pci_ctrl[1].piebar1 = 0x0;
	pci_ctrl[1].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_2G;
	/*
	 * Assign PIB PMC slot to desired PCI bus
	 */
#ifdef CONFIG_MPC8349ADS
	mpc8349_i2c = (i2c_t*)(CFG_IMMRBAR + CFG_I2C2_OFFSET);
	i2c_init(CFG_I2C_SPEED,CFG_I2C_SLAVE);
#endif
	val8 = 0;
	ret = i2c_write(0x23,0x6,1,&val8,1);
	ret = i2c_write(0x23,0x7,1,&val8,1);
	val8 = 0xff;
	ret = i2c_write(0x23,0x2,1,&val8,1);
	ret = i2c_write(0x23,0x3,1,&val8,1);

	val8 = 0;
	ret = i2c_write(0x26,0x6,1,&val8,1);
	val8 = 0x34;
	ret = i2c_write(0x26,0x7,1,&val8,1);
#if defined(PCI_64BIT)
	val8 = 0xf4;	/* PMC2<->PCI1  64bit */
#elif defined(PCI_ALL_PCI1)
	val8 = 0xf3;	/* PMC1<->PCI1,PMC2<->PCI1,PMC3<->PCI1  32bit */
#elif defined(PCI_ONE_PCI1)
	val8 = 0xf9;	/* PMC1<->PCI1,PMC2<->PCI2,PMC3<->PCI2  32bit */
#elif defined(PCI_TWO_PCI1)
	val8 = 0xf5;	/* PMC1<->PCI1,PMC2<->PCI1,PMC3<->PCI2 32bit */
#else
	val8 = 0xf5;
#endif
	ret = i2c_write(0x26,0x2,1,&val8,1);
//.........这里部分代码省略.........
开发者ID:qwerty1023,项目名称:wive-rtnl-firmware,代码行数:101,代码来源:pci.c

示例4: sy8106a_set_vout1

int sy8106a_set_vout1(unsigned int mvolt)
{
	u8 data = sy8106a_mvolt_to_cfg(mvolt, 680, 1950, 10) | SY8106A_VOUT1_SEL_ENABLE;
	return i2c_write(SY8106A_I2C_ADDR, SY8106A_VOUT1_SEL, 1, &data, 1);
}
开发者ID:OpenNoah,项目名称:u-boot,代码行数:5,代码来源:sy8106a.c

示例5: display_init

void display_init()
{
	i2c_start(0x4E, 0x00, TW_WRITE);
	
	i2c_write(0x30);
	i2c_write(0x30);
	i2c_write(0x30);
	
	i2c_write(0x20);
	i2c_write(0x20);
	i2c_write(0xF0);
	
	i2c_write(0x00);
	i2c_write(0xF0);
	
	i2c_write(0x00);
	i2c_write(0x10);
	
	i2c_write(0x00);
	i2c_write(0x60);
	
	i2c_stop();	
}
开发者ID:mcostabr,项目名称:avr-projects,代码行数:23,代码来源:hd44780-i2c.c

示例6: i2c_read_2byte

i2c_ack i2c_read_2byte(int bus_id, char chip_addr, unsigned int sub_addr, char *buf, unsigned int size)
{
#ifdef FLY_VIDEO_BOARD_V3
    int ret_rec = 0;
    ret_rec = SOC_I2C_Rec_2B_SubAddr(3, TC358746_I2C_ChipAdd, sub_addr, buf, size);
    //lidbg("\n************i2c_read_2byte  ret_rec=%d *****************\n",ret_rec);
    if(ret_rec > 0)
    {
        return ACK;
    }
    else
    {
        return NACK;
    }
#else
    u8 i;
    mutex_lock(&io_i2c_lock);
    i2c_init();
    // start transmite
    i2c_begin();//msg 0>>
    i2c_write_chip_addr(chip_addr, hkj_WRITE) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg(" chip_addr devices is not ACK------i2c_write_chip_addr----r--\r\n");
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }

    //i2c_stop();
    // restart transmite


    // send message to mm_i2c device to transmite data
    i2c_write(sub_addr >> 8) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg(" chip_addr devices is not ACK-----subadder1-------\r\n");
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    i2c_write(sub_addr) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg(" chip_addr devices is not ACK------subadder0------\r\n");
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    i2c_stop();//msg 0<<

    // start transmite
    i2c_begin();//msg 1>>
    i2c_write_chip_addr(chip_addr, hkj_READ) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();

        i2c_free();
        lidbg(" chip_addr devices is not ACK----- i2c_write_chip_addr-------\r\n");
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    // transmite data
    for(i = 0; i < size; i++)
    {
        buf[i] = i2c_read();
        ( i == (size - 1) ) ? i2c_write_ask(NACK) : i2c_write_ask(ACK);
    }

    // stop transmite
    i2c_stop();//msg 1<<

    i2c_free();
    mutex_unlock(&io_i2c_lock);
    return ACK;
#endif
}
开发者ID:kongan,项目名称:input--,代码行数:82,代码来源:i2c_io.c

示例7: getSRF

uint8_t getSRF(void)
{
    uint8_t lsb_srf = 0;
    uint8_t msb_srf = 0;

    switch(srf[srf_sm_manage].state)
    {
        case 0:
                if((i2c_start(pgm_read_byte(&srf_i2c_addresses[srf_sm_manage])) == 0) &&
                   (i2c_write(0x00) == 0) &&
                   (i2c_write(I2C_REG_SRF10_MEASERUEMENT_S) == 0) &&
                   (i2c_stop() == 0))
                {
                    srf[srf_sm_manage].state = 1; //Messung ok, nächster Schritt
                    getSRF_returnvar &= ~(1<<srf_sm_manage);
                }
                else
                {
                    srf[srf_sm_manage].state = 0; //Beim nächsten Durchlauf nochmal
                    getSRF_returnvar |= (1<<srf_sm_manage); //etwas hat nicht funktioniert

                    srf_sm_manage ++; //nächster Sensor
                    if(srf_sm_manage >= NUMBER_OF_SRF)
                        srf_sm_manage = 0;
                }
            break;

        case 1:
                if((i2c_start(pgm_read_byte(&srf_i2c_addresses[srf_sm_manage])) != 0) || //Abfragen: Ist die Messung beendet?
                   (i2c_write(0x00) != 0) ||
                   (i2c_rep_start(pgm_read_byte(&srf_i2c_addresses[srf_sm_manage])+I2C_READ) != 0) ||
                   (i2c_readNak() == 255) ||
                   (i2c_stop() != 0))
                {
                    srf[srf_sm_manage].state = 0;
                    getSRF_returnvar |= (1<<srf_sm_manage);

                    srf_sm_manage ++; //nächster Sensor
                    if(srf_sm_manage >= NUMBER_OF_SRF)
                        srf_sm_manage = 0;
                }
                else
                {
                    srf[srf_sm_manage].state = 2;
                }
            break;

        case 2:

                if((i2c_start(pgm_read_byte(&srf_i2c_addresses[srf_sm_manage])) == 0) && //Auslesen der ENtfernung
                   (i2c_write(0x02) == 0) &&
                   (i2c_rep_start(pgm_read_byte(&srf_i2c_addresses[srf_sm_manage])+I2C_READ) == 0))
                {
                    lsb_srf = i2c_readAck();
                    msb_srf = i2c_readNak();
                    srf[srf_sm_manage].dist = (((uint16_t)lsb_srf << 8) | msb_srf);// * SRF10_US_TO_MM;
                    if(i2c_stop() != 0)
                        getSRF_returnvar |= (1<<srf_sm_manage);
                }
                else
                {
                    getSRF_returnvar |= (1<<srf_sm_manage);
                }

                srf[srf_sm_manage].state = 0;

                srf_sm_manage ++; //nächster Sensor
                if(srf_sm_manage >= NUMBER_OF_SRF)
                    srf_sm_manage = 0;
            break;
    }

    return getSRF_returnvar;
}
开发者ID:janblumenkamp,项目名称:rcj2015,代码行数:74,代码来源:i2cdev.c

示例8: drv_l2_audiocodec_wm8988_rx_init

int drv_l2_audiocodec_wm8988_rx_init(void)
{
	INT32U R, boost = 0x3, mic_pga_l = 0x20, mic_pga_r = 0x7;
	INT32U alc_max = 0x7, alc_target = 0xB;
	
	// RX Register
	pack.info = i2c_wolfson_WM8988(67,0x0);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(24,0x0);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(25,0xEC);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(26,0x1F8);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(7,0x2);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(8,0x18);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);	
	pack.info = i2c_wolfson_WM8988(31,0x100);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(32,0xC0|(boost<<4));
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(33,0xC0|(boost<<4));
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	{
		R = 0x97;
		R &= ~0x3F;
		R &= ~0x80; 		//Disable Mute
		R |= 0x100;
		R |= mic_pga_l; 	
		pack.info = i2c_wolfson_WM8988(0,R);
		i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	}
	{
		R = 0x97;
		R &= ~0x3F;
		R &= ~0x80; 	 //Disable Mute
		R |= 0x100;
		R |= mic_pga_r;
		pack.info = i2c_wolfson_WM8988(1,R);
		i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	}
	{
		R  = 0x7B;
		R &= ~0x7;
		R |= alc_max << 4;
		R |= alc_target;
		//R |= 0x180; //turn on ALC	
		pack.info = i2c_wolfson_WM8988(17,R);
		i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	}
	pack.info = i2c_wolfson_WM8988(21,0x1D0);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(22,0x1D0);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	return 0;
}
开发者ID:ZhaGoo,项目名称:gp720,代码行数:57,代码来源:drv_l2_audiocodec_wm8988.c

示例9: drv_l2_audiocodec_wm8988_tx_init

int drv_l2_audiocodec_wm8988_tx_init(void)
{
	// TX register	
	pack.info = i2c_wolfson_WM8988(67,0x0);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(24,0x0);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(25,0xEC);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(26,0x1F8);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(2,0x179);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(3,0x179);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(40,0x179);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(41,0x179);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(5,0x0);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(7,0x2);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(34,0x150);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	pack.info = i2c_wolfson_WM8988(35,0x50);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);		
	pack.info = i2c_wolfson_WM8988(36,0x50);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);		
	pack.info = i2c_wolfson_WM8988(37,0x150);
	i2c_write(&i2c_handle,pack.data[0] ,pack.data[1]);
	return 0;
}
开发者ID:ZhaGoo,项目名称:gp720,代码行数:33,代码来源:drv_l2_audiocodec_wm8988.c

示例10: do_i2c_mw

/* Write (fill) memory
 *
 * Syntax:
 *	imw {i2c_chip} {addr}{.0, .1, .2} {data} [{count}]
 */
int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	uchar	chip;
	ulong	addr;
	uint	alen;
	uchar	byte;
	int	count;
	int	j;

	if ((argc < 4) || (argc > 5)) {
		printf ("Usage:\n%s\n", cmdtp->usage);
		return 1;
	}

	/*
 	 * Chip is always specified.
 	 */
	chip = simple_strtoul(argv[1], NULL, 16);

	/*
	 * Address is always specified.
	 */
	addr = simple_strtoul(argv[2], NULL, 16);
	alen = 1;
	for(j = 0; j < 8; j++) {
		if (argv[2][j] == '.') {
			alen = argv[2][j+1] - '0';
			if(alen > 4) {
				printf ("Usage:\n%s\n", cmdtp->usage);
				return 1;
			}
			break;
		} else if (argv[2][j] == '\0') {
			break;
		}
	}

	/*
	 * Value to write is always specified.
	 */
	byte = simple_strtoul(argv[3], NULL, 16);

	/*
	 * Optional count
	 */
	if(argc == 5) {
		count = simple_strtoul(argv[4], NULL, 16);
	} else {
		count = 1;
	}

	while (count-- > 0) {
		if(i2c_write(chip, addr++, alen, &byte, 1) != 0) {
			puts ("Error writing the chip.\n");
		}
		/*
		 * Wait for the write to complete.  The write can take
		 * up to 10mSec (we allow a little more time).
		 *
		 * On some chips, while the write is in progress, the
		 * chip doesn't respond.  This apparently isn't a
		 * universal feature so we don't take advantage of it.
		 */
/*
 * No write delay with FRAM devices.
 */
#if !defined(CFG_I2C_FRAM)
		udelay(11000);
#endif

#if 0
		for(timeout = 0; timeout < 10; timeout++) {
			udelay(2000);
			if(i2c_probe(chip) == 0)
				break;
		}
#endif
	}

	return (0);
}
开发者ID:WhitePatches,项目名称:snake-os,代码行数:86,代码来源:cmd_i2c.c

示例11: mcp4651_init

void mcp4651_init(void) {
	i2c_start_wait(MCP4651+I2C_WRITE);     	// set device address and write mode
   	i2c_write(0x40);	                   	// write pointer address to TCON, disable general call
   	i2c_write(0xFF);
  	i2c_stop();
}
开发者ID:tomtrath,项目名称:firmware,代码行数:6,代码来源:mcp4651.c

示例12: main

void main (void)
{
    io_init();
    servo_init();
    timers_init();
    i2c_init();
    wdt_enable(WDTO_15MS);
    sei();
    start_timers();

    flags.new_buf_ready = 0;
    flags.i2c_first_byte = 0;
    flags.servo_pd_changed = 0;
    flags.servo_minmaxpd_cnahged = 0;

#ifdef MEGADEBUG
    struct {
        uint8_t sw1 : 1;
        uint8_t sw2 : 1;
    } ss;

    UTILS_DDR_CLR(I2CSCL_PORT, I2CSCL_PIN);
    UTILS_DDR_CLR(I2CSDA_PORT, I2CSDA_PIN);
    UTILS_PORT_SET(I2CSCL_PORT, I2CSCL_PIN);
    UTILS_PORT_SET(I2CSDA_PORT, I2CSDA_PIN);
#endif

    for (;;)
    {
#ifdef MEGADEBUG
        if (!UTILS_PIN_VALUE(I2CSCL_PORT, I2CSCL_PIN))
        {
            if (!ss.sw1)
            {
                servo[0].target += 16;
            }
            ss.sw1 = 1;
        }
        else
        {
            ss.sw1 = 0;
        }

        if (!UTILS_PIN_VALUE(I2CSDA_PORT, I2CSDA_PIN))
        {
            if (!ss.sw2)
            {
                servo[0].target -= 16;
            }
            ss.sw2 = 1;
        }
        else
        {
            ss.sw2 = 0;
        }
#endif

#ifndef MEGADEBUG
        // i2c
        if (TWCR & _BV(TWINT))
        {
            // i2c 
            switch (TWSR)
            {
                case TW_SR_SLA_ACK: // i2c start
                    flags.i2c_first_byte = 1;
                    break;
                case TW_SR_DATA_ACK: // i2c byte received
                    if (flags.i2c_first_byte)
                    {
                        i2cMemAddr = TWDR;
                        flags.i2c_first_byte = 0;
                    }
                    else
                    {
                        i2c_read();
                        i2cMemAddr ++;
                    }
                    break;
                case TW_ST_DATA_ACK:
                    i2c_write();
                    i2cMemAddr ++;
                    break;
            }

            TWCR |= _BV(TWINT);
        }
#endif

        // servo.position 
        if (UTILS_AGGL(TIFR, ITIMER) & _BV(UTILS_AGGL2(OCF, ITIMER, A)))
        {
            // Timer ITIMER compare match A
            UTILS_AGGL(TIFR, ITIMER) |= _BV(UTILS_AGGL2(OCF, ITIMER, A)); 

            for (uint8_t i = 0; i < SERVO_NUM; i ++)
            {
                if (servo[i].position != servo[i].target)
                {
                    UTILS_PORT_SET(LED_PORT, LED_PIN);
//.........这里部分代码省略.........
开发者ID:Mehanik,项目名称:i2c-servo-controller,代码行数:101,代码来源:main.c

示例13: setup_i2c

void setup_i2c(){
    // Init sequence for 128x64 OLED module
    i2c_write(0xAE);                    // Display Off
    
    i2c_write(0x00 | 0x0);            // low col = 0
    i2c_write(0x10 | 0x0);           // hi col = 0
    i2c_write(0x40 | 0x0);            // line #0

    i2c_write(0x81);                   // Set Contrast 0x81
    i2c_write(0xCF);
                                        // flips display
    i2c_write(0xA1);                    // Segremap - 0xA1
    i2c_write(0xC8);                    // COMSCAN DEC 0xC8 C0
    i2c_write(0xA6);                    // Normal Display 0xA6 (Invert A7)
    
    i2c_write(0xA4);                // DISPLAY ALL ON RESUME - 0xA4
    i2c_write(0xA8);                    // Set Multiplex 0xA8
    i2c_write(0x3F);                    // 1/64 Duty Cycle 

    i2c_write(0xD3);                    // Set Display Offset 0xD3
    i2c_write(0x0);                     // no offset

    i2c_write(0xD5);                    // Set Display Clk Div 0xD5
    i2c_write(0x80);                    // Recommneded resistor ratio 0x80

    i2c_write(0xD9);                  // Set Precharge 0xd9
    i2c_write(0xF1);

    i2c_write(0xDA);                    // Set COM Pins0xDA
    i2c_write(0x12);

    i2c_write(0xDB);                 // Set VCOM Detect - 0xDB
    i2c_write(0x40);

    i2c_write(0x20);                    // Set Memory Addressing Mode
    i2c_write(0x00);                    // 0x00 - Horizontal

    i2c_write(0x40 | 0x0);              // Set start line at line 0 - 0x40 

    i2c_write(0x8D);                    // Charge Pump -0x8D
    i2c_write(0x14); 


    i2c_write(0xA4);              //--turn on all pixels - A5. Regular mode A4
    i2c_write(0xAF);                //--turn on oled panel - AF
}
开发者ID:umotes,项目名称:avr-clean-new,代码行数:46,代码来源:volt_ssd.c

示例14: i2c_irq_handler

/**
 * @brief IRQ handler for I2C master. Handles transmission/reception.
 * @param dev I2C device
 */
static void i2c_irq_handler(i2c_dev *dev) {
    i2c_msg *msg = dev->msg;

    uint8 read = msg->flags & I2C_MSG_READ;

    uint32 sr1 = dev->regs->SR1;
    uint32 sr2 = dev->regs->SR2;
    I2C_CRUMB(IRQ_ENTRY, sr1, sr2);

    /*
     * Reset timeout counter
     */
    dev->timestamp = systick_uptime();

    /*
     * EV5: Start condition sent
     */
    if (sr1 & I2C_SR1_SB) {
        msg->xferred = 0;
        i2c_enable_irq(dev, I2C_IRQ_BUFFER);

        /*
         * Master receiver
         */
        if (read) {
            i2c_enable_ack(dev);
        }

        i2c_send_slave_addr(dev, msg->addr, read);
        sr1 = sr2 = 0;
    }

    /*
     * EV6: Slave address sent
     */
    if (sr1 & I2C_SR1_ADDR) {
        /*
         * Special case event EV6_1 for master receiver.
         * Generate NACK and restart/stop condition after ADDR
         * is cleared.
         */
        if (read) {
            if (msg->length == 1) {
                i2c_disable_ack(dev);
                if (dev->msgs_left > 1) {
                    i2c_start_condition(dev);
                    I2C_CRUMB(RX_ADDR_START, 0, 0);
                } else {
                    i2c_stop_condition(dev);
                    I2C_CRUMB(RX_ADDR_STOP, 0, 0);
                }
            }
        } else {
            /*
             * Master transmitter: write first byte to fill shift
             * register.  We should get another TXE interrupt
             * immediately to fill DR again.
             */
            if (msg->length != 1) {
                i2c_write(dev, msg->data[msg->xferred++]);
            }
        }
        sr1 = sr2 = 0;
    }

    /*
     * EV8: Master transmitter
     * Transmit buffer empty, but we haven't finished transmitting the last
     * byte written.
     */
    if ((sr1 & I2C_SR1_TXE) && !(sr1 & I2C_SR1_BTF)) {
        I2C_CRUMB(TXE_ONLY, 0, 0);
        if (dev->msgs_left) {
            i2c_write(dev, msg->data[msg->xferred++]);
            if (msg->xferred == msg->length) {
                /*
                 * End of this message. Turn off TXE/RXNE and wait for
                 * BTF to send repeated start or stop condition.
                 */
                i2c_disable_irq(dev, I2C_IRQ_BUFFER);
                dev->msgs_left--;
            }
        } else {
            /*
             * This should be impossible...
             */
            throb();
        }
        sr1 = sr2 = 0;
    }

    /*
     * EV8_2: Master transmitter
     * Last byte sent, program repeated start/stop
     */
    if ((sr1 & I2C_SR1_TXE) && (sr1 & I2C_SR1_BTF)) {
//.........这里部分代码省略.........
开发者ID:CM-9xx,项目名称:cm9xx,代码行数:101,代码来源:i2c.c

示例15: i2c_read_byte

i2c_ack i2c_read_byte(int bus_id, char chip_addr, unsigned int sub_addr, char *buf, unsigned int size)
{
#ifdef FLY_VIDEO_BOARD_V3
    int ret = 0;
    //ret=i2c_api_do_recv(3,chip_addr, sub_addr , buf, size);
    ret = SOC_I2C_Rec(3, chip_addr, sub_addr , buf, size);
    //lidbg("\n************ i2c_read_byte =%d*******\n",ret);
    //if(ret==size){
    if(ret > 0)
    {
#ifdef  DEBUG_ACK
        return NACK;
#else
        return ACK;
#endif

    }
    else
    {
        return NACK;
    }
#else
    u8 i;
    mutex_lock(&io_i2c_lock);
    i2c_init();
    // start transmite
    i2c_begin();
    i2c_write_chip_addr(chip_addr, hkj_WRITE) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg("at read funtion :i2c_write_chip_addr(%.2x, %d) ; is not ACK\n", chip_addr, hkj_WRITE);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }

    //i2c_stop();
    // restart transmite
    //i2c_begin();

    // send message to mm_i2c device to transmite data
    i2c_write(sub_addr) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg("at read funtion :i2c_write (%.2x) is not ACK\n", sub_addr & 0xff);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    i2c_stop();

    // start transmite
    i2c_begin();
    i2c_write_chip_addr(chip_addr, hkj_READ) ;
    if (i2c_read_ack() == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg("at read funtion :i2c_write_chip_addr(%.2x, %d) ; is not ACK\n", sub_addr, hkj_READ);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    // transmite data
    for(i = 0; i < size; i++)
    {
        buf[i] = i2c_read();
        ( i == (size - 1) ) ? i2c_write_ask(NACK) : i2c_write_ask(ACK);
    }

    // stop transmite
    i2c_stop();
    i2c_free();
    mutex_unlock(&io_i2c_lock);
    return ACK;
#endif
}
开发者ID:kongan,项目名称:input--,代码行数:78,代码来源:i2c_io.c


注:本文中的i2c_write函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。