本文整理汇总了C++中i2c_write函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_write函数的具体用法?C++ i2c_write怎么用?C++ i2c_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i2c_write函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: read_mac_sn
int read_mac_sn(char *buf, ushort len)
{
int i;
uchar num;
ushort addr = 0xE000;
rrb_data_t dat;
uchar i2c_addr = 0x59;
while(1)
{
if (len >= 0x10) num = 0x10;
else num = len;
dat.bytes = 2;
dat.reg = 2;
dat.data[0] = addr & 0xff;
dat.data[1] = (addr >> 8) & 0xff;
for(i = 0; i < dat.bytes; i++)
{
if(i2c_write(i2c_addr, dat.reg + i, 1, &dat.data[i], 1))
{
printf("error sending address\n");
goto out;
}
}
dat.bytes = 1;
dat.reg = 1;
dat.data[0] = num;
for(i = 0; i < dat.bytes; i++)
{
if(i2c_write(i2c_addr, dat.reg + i, 1, &dat.data[i], 1))
{
printf("Error sending byte count\n");
goto out;
}
}
dat.bytes = 1;
dat.reg = 0;
dat.data[0] = 0x0C;
for(i = 0; i < dat.bytes; i++)
{
if(i2c_write(i2c_addr, dat.reg + i, 1, &dat.data[i], 1))
{
printf("Error sending command\n");
goto out;
}
}
dat.bytes = num;
dat.reg = 6;
for(i = 0; i < dat.bytes; i++)
{
i2c_read(i2c_addr, dat.reg + i, 1, &dat.data[i], 1);
}
memcpy(buf, &dat.data[0], num);
buf += num;
addr += num;
len -= num;
if (!len) return 0;
}
out:
return -1;
}
开发者ID:CharlieWood,项目名称:uboot-imx,代码行数:67,代码来源:dv_board.c
示例17: i2c_write_byte
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
}
开发者ID:kongan,项目名称:input--,代码行数:76,代码来源:i2c_io.c
示例18: rmii_hw_init
/**
* rmii_hw_init
*
* DA850/OMAP-L138 EVM can interface to a daughter card for
* additional features. This card has an I2C GPIO Expander TCA6416
* to select the required functions like camera, RMII Ethernet,
* character LCD, video.
*
* Initialization of the expander involves configuring the
* polarity and direction of the ports. P07-P05 are used here.
* These ports are connected to a Mux chip which enables only one
* functionality at a time.
*
* For RMII phy to respond, the MII MDIO clock has to be disabled
* since both the PHY devices have address as zero. The MII MDIO
* clock is controlled via GPIO2[6].
*
* This code is valid for Beta version of the hardware
*/
int rmii_hw_init(void)
{
const struct pinmux_config gpio_pins[] = {
{ pinmux(6), 8, 1 }
};
u_int8_t buf[2];
unsigned int temp;
int ret;
/* PinMux for GPIO */
if (davinci_configure_pin_mux(gpio_pins, ARRAY_SIZE(gpio_pins)) != 0)
return 1;
/* I2C Exapnder configuration */
/* Set polarity to non-inverted */
buf[0] = 0x0;
buf[1] = 0x0;
ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 4, 1, buf, 2);
if (ret) {
printf("\nExpander @ 0x%02x write FAILED!!!\n",
CONFIG_SYS_I2C_EXPANDER_ADDR);
return ret;
}
/* Configure P07-P05 as outputs */
buf[0] = 0x1f;
buf[1] = 0xff;
ret = i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 6, 1, buf, 2);
if (ret) {
printf("\nExpander @ 0x%02x write FAILED!!!\n",
CONFIG_SYS_I2C_EXPANDER_ADDR);
}
/* For Ethernet RMII selection
* P07(SelA)=0
* P06(SelB)=1
* P05(SelC)=1
*/
if (i2c_read(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
printf("\nExpander @ 0x%02x read FAILED!!!\n",
CONFIG_SYS_I2C_EXPANDER_ADDR);
}
buf[0] &= 0x1f;
buf[0] |= (0 << 7) | (1 << 6) | (1 << 5);
if (i2c_write(CONFIG_SYS_I2C_EXPANDER_ADDR, 2, 1, buf, 1)) {
printf("\nExpander @ 0x%02x write FAILED!!!\n",
CONFIG_SYS_I2C_EXPANDER_ADDR);
}
/* Set the output as high */
temp = REG(GPIO_BANK2_REG_SET_ADDR);
temp |= (0x01 << 6);
REG(GPIO_BANK2_REG_SET_ADDR) = temp;
/* Set the GPIO direction as output */
temp = REG(GPIO_BANK2_REG_DIR_ADDR);
temp &= ~(0x01 << 6);
REG(GPIO_BANK2_REG_DIR_ADDR) = temp;
return 0;
}
开发者ID:Apaisal,项目名称:u-boot,代码行数:81,代码来源:da850evm.c
示例19: i2c_write_2byte
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
}
开发者ID:kongan,项目名称:input--,代码行数:75,代码来源:i2c_io.c
示例20: tun_dbcte702f1_control
INT32 tun_dbcte702f1_control(UINT32 tuner_id, UINT32 freq, UINT32 sym, UINT8 AGC_Time_Const, UINT8 _i2c_cmd)
{
INT32 result;
UINT16 Npro;
UINT32 OscFreq;
UINT8 StepFreq,RefDivRatio,TunCrystal;
UINT8 RS, ATP, BS;
UINT8 data[5];
struct QAM_TUNER_CONFIG_EXT * tuner_dev_ptr = NULL;
if ((tuner_id>=dbcte702f1_tuner_cnt) || (tuner_id>=MAX_TUNER_SUPPORT_NUM))
return ERR_FAILUE;
tuner_dev_ptr = dbcte702f1_dev_id[tuner_id];
DBCTE702F1_PRINTF("%s: feq, sym: %d, %d !\n", __FUNCTION__, freq, sym);
//==========Calculate control bytes=============
OscFreq = freq + tuner_dev_ptr->wTuner_IF_Freq;
StepFreq = tuner_dev_ptr->cTuner_Step_Freq;
RefDivRatio = tuner_dev_ptr->cTuner_Ref_DivRatio;
TunCrystal = tuner_dev_ptr->cTuner_Crystal;
Npro=OscFreq * RefDivRatio / (TunCrystal * 1000);
if (RefDivRatio == 24) //166.667
RS = 0x00;
else if (RefDivRatio == 28)//142.857
RS = 0x01;
else if (RefDivRatio == 50) //80
RS = 0x02;
else if (RefDivRatio == 64) // 62.5
RS = 0x03;
else if (RefDivRatio == 128) // 31.25
RS = 0x04;
else if (RefDivRatio == 80) //50
RS = 0x05;
else
RS = 0x03;
//ATP = 0x01; //Normal op
//ATP = 0x07; //Dual AGC
ATP = tuner_dev_ptr->cTuner_AGC_TOP;
if ((OscFreq >= 85000) && (OscFreq < 185000))
BS = 0x01;
else if ((OscFreq >= 185000) && (OscFreq < 465000))
BS = 0x06;
else if ((OscFreq >= 465000) && (OscFreq < 896000))
BS = 0x0C;
else
BS = 0x0C;
//==========Evaluated to control bytes=============
data[0] = (UINT8)((Npro>>8)&0x7F);
data[1] = (UINT8)(Npro&0xFF);
data[2] = 0x80 | ((ATP<<3)&0x38) | (RS&0x07);
data[3] = BS&0x0f;
data[4] = 0xc3;
//==========Write to tuner register===============
if(AGC_Time_Const == SLOW_TIMECST_AGC)
osal_task_sleep(50);
result = ERR_FAILUE;
if(_i2c_cmd==_1st_i2c_cmd)
{
result = i2c_write(tuner_dev_ptr->i2c_type_id, tuner_dev_ptr->cTuner_Base_Addr, data,5);
}
return result;
}
开发者ID:alkap007,项目名称:ali3606,代码行数:76,代码来源:tun_dbcte702f1.c
注:本文中的i2c_write函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论