/*
 * I2C read called by cmd_i2c when doing 'i2c read' and by cmd_eeprom.c
 * Begin write, send address byte(s), begin read, receive data bytes, end.
 *
 * NOTE: some EEPROMS want a stop right before the second start, while
 * some will choke if it is there. Deciding which we should do is eeprom
 * stuff, not i2c, but at the moment the APIs won't let us put it in
 * cmd_eeprom, so we have to choose here, and for the moment that'll be
 * a repeated start without a preceding stop.
 */
int i2c_read(u8 dev, uint addr, int alen, u8 *data, int length)
{
	int status;

	/* begin i2c write to send the address bytes */
	status = i2c_begin(MVTWSI_STATUS_START, (dev << 1));
	/* send addr bytes */
	while ((status == 0) && alen--)
		status = twsi_send(addr >> (8*alen),
			MVTWSI_STATUS_DATA_W_ACK);
	/* begin i2c read to receive eeprom data bytes */
	if (status == 0)
		status = i2c_begin(
			MVTWSI_STATUS_REPEATED_START, (dev << 1) | 1);
	/* prepare ACK if at least one byte must be received */
	if (length > 0)
		twsi_control_flags |= MVTWSI_CONTROL_ACK;
	/* now receive actual bytes */
	while ((status == 0) && length--) {
		/* reset NAK if we if no more to read now */
		if (length == 0)
			twsi_control_flags &= ~MVTWSI_CONTROL_ACK;
		/* read current byte */
		status = twsi_recv(data++);
	}
	/* Stop transaction */
	status = twsi_stop(status);
	/* return 0 or status of first failure */
	return status;
}
int rtc_read_multiple(unsigned char address, unsigned char *buf, int numbytes)
{
    int ret = 0;
    unsigned char obuf[1];
    int i;

    i2c_begin();

    obuf[0] = address;

    /* send read command */
    if (i2c_write(RTC_DEV_READ, obuf, 1) >= 0)
    {
        i2c_start();
        i2c_outb(RTC_DEV_READ);
        if (i2c_getack())
        {
            for(i = 0; i < numbytes-1; i++)
                buf[i] = i2c_inb(0);

            buf[i] = i2c_inb(1);
        }
        else
        {
            ret = -1;
        }
    }

    i2c_stop();

    i2c_end();
    return ret;
}
int rtc_read(unsigned char address)
{
    int value = -1;
    unsigned char buf[1];

    i2c_begin();

    buf[0] = address;

    /* send read command */
    if (i2c_write(RTC_DEV_READ,buf,1) >= 0)
    {
        i2c_start();
        i2c_outb(RTC_DEV_READ);
        if (i2c_getack())
        {
            value = i2c_inb(1);
        }
    }

    i2c_stop();

    i2c_end();
    return value;
}
Beispiel #4
0
int dac_volume(unsigned int left, unsigned int right, bool deemph)
{
    int ret = 0;
    unsigned char buf[3];

    i2c_begin();

    if (left > 0x38)
        left = 0x38;
    if (right > 0x38)
        right = 0x38;

    buf[0] = DAC_REG_WRITE | DAC_AVOL;
    buf[1] = (left & 0x3f) | (deemph ? 0x40 : 0);
    buf[2] = right & 0x3f;

    /* send write command */
    if (i2c_write(DAC_DEV_WRITE,buf,3))
    {
        ret = -1;
    }

    i2c_end();
    return ret;
}
Beispiel #5
0
void i2c_begin_address(uint8_t address)
{
	twi_setAddress(address);
	/*
	 * TODO: NEED TO RESEARCH INTERRUPTS
	twi_attachSlaveTxEvent(onRequestService);
	twi_attachSlaveRxEvent(onReceiveService);
	*/
	i2c_begin();
}
Beispiel #6
0
void dac_init(void)
{
    unsigned char buf[2];

    i2c_begin();

    buf[0] = DAC_REG_WRITE | DAC_SR_REG;
    buf[1] = 0x07;

    /* send write command */
    i2c_write(DAC_DEV_WRITE,buf,2);
    i2c_end();
}
Beispiel #7
0
void setup()
{
   i2c_begin(); 

   standbyMode(); //register settings must be made in standby mode
   regWrite(REG_XYZ_DATA_CFG, FULL_SCALE_RANGE_2g);
   hiResMode(); //this is the default setting and can be omitted.
   //lowResMode(); //set to low res (fast mode), must use getAccXYZ(,,,false) to retrieve readings.
   activeMode(); 

   byte b;
   //regRead(REG_WHO_AM_I, &b);
}
int nmi_i2c_write(unsigned char adr, unsigned char *b, unsigned long sz)
{
	int i;

	i2c_begin();

	i2c_write_byte((adr << 1));
	for(i = 0; i < sz; i++) {
		i2c_write_byte(b[i]);
	}

	i2c_end();
	return 1;
}
/*
 * I2C probe called by cmd_i2c when doing 'i2c probe'.
 * Begin read, nak data byte, end.
 */
int i2c_probe(uchar chip)
{
	u8 dummy_byte;
	int status;

	/* begin i2c read */
	status = i2c_begin(MVTWSI_STATUS_START, (chip << 1) | 1);
	/* dummy read was accepted: receive byte but NAK it. */
	if (status == 0)
		status = twsi_recv(&dummy_byte);
	/* Stop transaction */
	twsi_stop(0);
	/* return 0 or status of first failure */
	return status;
}
void tcs34725::clearInterrupt(void) {
  int res;
  res = i2c_begin(i2c_dev_name);
  
  if (res < 0)
    return;

  if (i2c_smbus_write_byte(fd, 0x66) < 0){
    i2c_end();
    perror(__FUNCTION__);
	 return;
  }

  i2c_end();

}
Beispiel #11
0
int main(int argc, char **argv) {
	uint8_t first = 0x03, last = 0x77;
	uint8_t i, j;
	uint8_t address;

	if (!i2c_begin()) {
		return -1;
	}

	i2c_set_baudrate(I2C_NORMAL_SPEED);

	printf("[V%s] Compiled on %s at %s\n\n", SOFTWARE_VERSION, __DATE__, __TIME__);

	for (address = 0x00; address <= 0x7F; address++) {
		/* Skip unwanted addresses */
		if (address < first || address > last) {
			continue;
		}

		if (i2c_is_connected(address)) {
			printf("0x%.2X : 0x%.2X : %s\n", (unsigned int) address, (unsigned int) (address << 1), i2c_lookup_device(address));
		}
	}

	puts("\n     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f");

	for (i = 0; i < 128; i += 16) {
		printf("%02x: ", (unsigned int) i);
		for (j = 0; j < 16; j++) {
			/* Skip unwanted addresses */
			if (i + j < first || i + j > last) {
				printf("   ");
				continue;
			}

			if (i2c_is_connected((i + j))) {
				printf("%02x ", (unsigned int) (i + j));
			} else {
				printf("-- ");
			}
		}

		puts("");
	}

	return 0;
}
void tcs34725::write8 (uint8_t reg, uint8_t value)
{
  int res;
  res = i2c_begin(i2c_dev_name);
  
  if (res < 0)
    return;

  if (i2c_smbus_write_byte_data(fd, TCS34725_COMMAND_BIT | reg, value) < 0) {
    i2c_end();
    perror(__FUNCTION__);
	 return;
  }

  i2c_end();

}
Beispiel #13
0
/*
 * I2C write called by cmd_i2c when doing 'i2c write' and by cmd_eeprom.c
 * Begin write, send address byte(s), send data bytes, end.
 */
int i2c_write(u8 dev, uint addr, int alen, u8 *data, int length)
{
	int status;

	/* begin i2c write to send the eeprom adress bytes then data bytes */
	status = i2c_begin(MVTWSI_STATUS_START, (dev << 1));
	/* send addr bytes */
	while ((status == 0) && alen--)
		status = twsi_send(addr >> (8*alen),
			MVTWSI_STATUS_DATA_W_ACK);
	/* send data bytes */
	while ((status == 0) && (length-- > 0))
		status = twsi_send(*(data++), MVTWSI_STATUS_DATA_W_ACK);
	/* Stop transaction */
	status = twsi_stop(status);
	/* return 0 or status of first failure */
	return status;
}
Beispiel #14
0
/**
 * @ingroup I2C-RTC
 *
 * @param slave_address
 * @return
 */
uint8_t mcp7941x_start (const uint8_t slave_address) {
#if !defined(BARE_METAL) && !defined(__AVR_ARCH__)
	if (bcm2835_init() != 1)
		return MCP7941X_ERROR;
#endif
	FUNC_PREFIX(i2c_begin());

	if (slave_address <= 0)
		i2c_mcp7941x_slave_address = MCP7941X_DEFAULT_SLAVE_ADDRESS;
	else
		i2c_mcp7941x_slave_address = slave_address;

	mcp7941x_setup();

	if (bcm2835_i2c_write(NULL, 0) == 0)
		return MCP7941X_OK;

	return MCP7941X_ERROR;
}
int nmi_i2c_read(unsigned char adr, unsigned char *b, unsigned long sz)
{
	int i;

	i2c_begin();
	i2c_write_byte((adr << 1)|0x1);

	for(i = 0; i < sz; i++) {
	    b[i] = i2c_read_byte();	    
		
	    if(i == sz-1) 
			i2c_write_ask(1);	
	    else  	           
			i2c_write_ask(0);
	}
 
	i2c_end();
	return 1;
}
int rtc_write(unsigned char address, unsigned char value)
{
    int ret = 0;
    unsigned char buf[2];

    i2c_begin();

    buf[0] = address;
    buf[1] = value;

    /* send run command */
    if (i2c_write(RTC_DEV_WRITE,buf,2))
    {
        ret = -1;
    }

    i2c_end();
    return ret;
}
Beispiel #17
0
int main(void)
{
	uint8_t			data = 0x55;
	uint32_t		prevms = 0;
	PCF8574_STATUS	st;

	sei();
	i2c_begin();

	TCCR2A = 0;						//t2: stop
	TCCR2B = 0;
	GTCCR = _BV(PSRASY);			//t2: prescaler reset
	TCNT2 = 0;						//t2: reset counter

	TCCR2A = _BV(WGM21);			//t2: CTC mode
	OCR2A = 124;					//t2: 62.5*128*125 = 1000000 ns = 1 ms
	TIMSK2 = _BV(OCIE2A);			//t2 enable Timer2 Interrupt

	TCCR2B = _BV(CS20) | _BV(CS22);	//t2: prescaler 128 (start)

//	pcf8574_init(&st, 0x20, 0xff);

	_delay_ms(500);  //Initiaize LCD
	lcd_init();
	_delay_ms(200);
	lcd_clear();
	lcd_setcursor(1, 0);
	display("Hi");
	display(" There....");
	lcd_setcursor(0, 1);
	display("Circuits4You.com");


	while(1)
	{
//		pcf8574_write8(&st, data);
//		pcf8574_read8(&st, &data);
//		data ^= 0xff;
//		while(millis() - prevms < 1000 );
//		prevms += 1000;
	}
}
Beispiel #18
0
/* dac_config is called once to initialize it. we will apply
   our static settings because of the init flow.
   dac_init -> dac_line_in -> mpeg_init -> dac_config
*/
static int dac_config(void)
{
    int ret = 0;
    unsigned char buf[2];

    i2c_begin();

    buf[0] = DAC_REG_WRITE | DAC_GCFG;
    buf[1] = (dac_enabled ? 0x04 : 0) |
        (line_in_enabled ? 0x08 : 0);

    /* send write command */
    if (i2c_write(DAC_DEV_WRITE,buf,2))
    {
        ret = -1;
    }

    i2c_end();
    return ret;
}
Beispiel #19
0
bool Tc1602::Start(void) {
	i2c_begin();

	Setup();

	if (!i2c_is_connected(m_nSlaveAddress)) {
		return false;
	}

	WriteCmd((uint8_t) 0x33);	///< 110011 Initialize
	WriteCmd((uint8_t) 0x32);	///< 110010 Initialize

	WriteCmd((uint8_t) (TC1602_IC_FUNC | TC1602_IC_FUNC_4BIT | TC1602_IC_FUNC_2LINE | TC1602_IC_FUNC_5x8DOTS)); ///< Data length, number of lines, font size
	WriteCmd((uint8_t) (TC1602_IC_DISPLAY | TC1602_IC_DISPLAY_ON | TC1602_IC_DISPLAY_CURSOR_OFF | TC1602_IC_DISPLAY_BLINK_OFF));	///< Display On,Cursor Off, Blink Off
	WriteCmd((uint8_t) TC1602_IC_CLS);
	udelay(EXEC_TIME_CLS - EXEC_TIME_CMD);
	WriteCmd((uint8_t) (TC1602_IC_ENTRY_MODE | TC1602_IC_ENTRY_MODE_INC));	///< Cursor move direction

	return true;
}
Beispiel #20
0
int i2c_write(unsigned short address, const unsigned char *buf, int count)
{
    int i;
    int ret=0;
    i2c_begin();
    IO_I2C_TXDATA = ( (address << 1) & 0xFF ) | (address>0x7F ? 0 : 1 ) | I2C_TX_ACK;
    IO_I2C_SCS &= ~0x3; //clear conditions
    IO_I2C_SCS |= I2C_SCS_COND_START; // write 'start condition'
    i2c_start();
    WAIT_FOR_I2C;
    /* experimental */
    if(address>0x7F){ // check if it is 10-bit instead of 7-bit
        IO_I2C_TXDATA = ( (address >> 7) & 0xFF) | I2C_TX_ACK;
        IO_I2C_SCS &= ~0x3; //normal transfer
        i2c_start();
        WAIT_FOR_I2C;
        IO_I2C_TXDATA = ( (address << 1) & 0xFF) | 1 | I2C_TX_ACK;
        IO_I2C_SCS &= ~0x3; //clear conditions
        IO_I2C_SCS |= I2C_SCS_COND_START; //write 'start condition'
        i2c_start();
        WAIT_FOR_I2C;
    }
uint8_t tcs34725::read8(uint8_t reg)
{
  int res;

  res = i2c_begin(i2c_dev_name);
  
  if (res < 0)
    return -1;

  /* return neg value if error or byte (0 - 0xff) */
  res = i2c_smbus_read_byte_data(fd, TCS34725_COMMAND_BIT | reg);

  if(res < 0) {
    i2c_end();
    perror(__FUNCTION__);
	 return (uint8_t) -1;
  }else{
    return (uint8_t) res;
  }
  
  i2c_end();

}
Beispiel #22
0
bool baro_begin(void)
{
	pmc_enable_periph_clk(BARO_TWI_ID);
	i2c_init(BARO_TWI);
	i2c_begin();

	memset(baro_buffer, 0, sizeof(baro_buffer));

	uint8_t whoami = read8(MPL3115A2_WHOAMI);

	write8(MPL3115A2_CTRL_REG1,
			MPL3115A2_CTRL_REG1_SBYB |
			MPL3115A2_CTRL_REG1_OS128 |
			MPL3115A2_CTRL_REG1_ALT);

	write8(MPL3115A2_PT_DATA_CFG,
		MPL3115A2_PT_DATA_CFG_TDEFE |
		MPL3115A2_PT_DATA_CFG_PDEFE |
		MPL3115A2_PT_DATA_CFG_DREM);

	return true;

}
Beispiel #23
0
bool ina219_start(device_info_t *device_info) {
	i2c_begin();

	if (device_info->slave_address == (uint8_t) 0) {
		device_info->slave_address = INA219_I2C_DEFAULT_SLAVE_ADDRESS;
	}

	if (device_info->speed_hz == (uint32_t) 0) {
		device_info->fast_mode = true;
	}

	i2c_setup(device_info);

	if (!i2c_is_connected(device_info->slave_address)) {
		return false;
	}

	ina219_configure(device_info, INA219_RANGE_32V, INA219_GAIN_320MV, INA219_BUS_RES_12BIT, INA219_SHUNT_RES_12BIT_1S , INA219_MODE_SHUNT_BUS_CONT);

	ina219_calibrate(device_info, 0.1, 2);

	return true;
}
Beispiel #24
0
i2c_ack i2c_write_2byte(int bus_id, char chip_addr, char *buf, unsigned int size)
{
#ifdef FLY_VIDEO_BOARD_V3
    int ret_send = 0;
    ret_send = SOC_I2C_Send(3, chip_addr, buf, size);
    //lidbg("\n*************i2c_write_2byt ret_send=%d**************\n",ret_send);
    if(ret_send > 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--in-i2c_write_chip_addr(%.2x)----w-----\r\n", chip_addr);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }

    // send message to mm_i2c device to transmite data
    i2c_write(buf[0]) ;//subaddr MSB
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg(" chip_addr devices is not ACK--in-i2c_write(sub[%d])=%.2x-----w----\r\n", 0, buf[0]);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    i2c_write(buf[1]) ;//subaddr
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg("chip_addr devices is not ACK--in-i2c_write(sub[%d])=%.2x--w", 1, buf[1]);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }

    // transmite data
    for(i = 2; i < size; i++)
    {
        i2c_write(buf[i]);
        if( i2c_read_ack()  == NACK)
        {
            i2c_stop();
            i2c_free();
            lidbg(" chip_addr devices is not ACK--in-i2c_write(buf[%d])=%.2x--w----\r\n", (i - 2), buf[i]);
            mutex_unlock(&io_i2c_lock);
            return NACK;
        }
    }

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

    i2c_free();
    mutex_unlock(&io_i2c_lock);
    return ACK;
#endif
}
Beispiel #25
0
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
}
Beispiel #26
0
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
}
Beispiel #27
0
i2c_ack i2c_write_byte(int bus_id, char chip_addr, char *buf, unsigned int size)
{
#ifdef FLY_VIDEO_BOARD_V3
    int ret_send = 0;
    ret_send = SOC_I2C_Send(3,  chip_addr, buf, size);
    // lidbg("\n************i2c_write_byte =%d*******\n",ret_send);
    if(ret_send > 0)
    {
#ifdef  DEBUG_ACK
        return NACK;
#else
        return ACK;
#endif
    }
    else
    {
        return NACK;
    }
#else
    u8 i;
    mutex_lock(&io_i2c_lock);
    //lidbg("i2c:write byte:addr =0x%.2x value=0x%.2x ",buf[0],buf[1]);
    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 write 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(buf[0]) ;
    if (i2c_read_ack() == NACK)
    {
        i2c_stop();

        i2c_free();
        lidbg(" at write funtion:i2c_write(%.2x) ;is not ACK\n", buf[0]);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    // transmite data
    for(i = 1; i < size; i++)
    {
        i2c_write(buf[i]);
        if( i2c_read_ack()  == NACK)
        {
            i2c_stop();
            i2c_free();
            lidbg(" at write funtion:i2c_write(%.2x) ;is not ACK\n", buf[i]);
            mutex_unlock(&io_i2c_lock);
            return NACK;
        }
    }

    // stop transmite
    i2c_stop();

    i2c_free();
    mutex_unlock(&io_i2c_lock);
    return ACK;
#endif
}
Beispiel #28
0
void I2CWire::begin(uint32_t clkHz)
{
	i2c_init(&i2cbuf, i2cx, sclpin, sdapin);
	i2c_begin(&i2cbuf, clkHz);
}
Beispiel #29
0
bool ButtonsBw::Start(void) {
	i2c_begin();

	return true;
}