本文整理汇总了C++中I2C_start函数的典型用法代码示例。如果您正苦于以下问题:C++ I2C_start函数的具体用法?C++ I2C_start怎么用?C++ I2C_start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了I2C_start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TSL_readCH1
uint16_t TSL_readCH1(uint8_t addr){
uint16_t data;
//PowerUp TSL
I2C_start();
I2C_sendAddr(addr); // Modo escrita
I2C_sendByte(0x80); // Program control register
I2C_sendByte(0x03); // Power up
I2C_stop();
I2C_start(); // READ BLOCK
I2C_sendAddr(addr); //
I2C_sendByte(0x8E); // Command LSB // 1st READ LSB
//
I2C_repeatStart(); //
I2C_sendAddr(addr+1); // reading mode //
data = I2C_receiveByte_NACK(); //
I2C_stop(); //
// THEN
I2C_start(); // READ MSB
I2C_sendAddr(addr); //
I2C_sendByte(0x8F); // Command MSB //
//
I2C_repeatStart(); //
I2C_sendAddr(addr+1); //
data |= (I2C_receiveByte_NACK() <<8); //
I2C_stop(); //
return data;
}
示例2: I2C_readreg
uint8_t I2C_readreg(uint8_t reg)
{
uint8_t tmp;
I2C_start(i2c_dev, SLAVE_ADDRESS, I2C_Direction_Transmitter); // start a transmission in Master transmitter mode
USART1_puts("start!\r\n");
I2C_write(i2c_dev, (uint8_t) reg); // write one byte to the slave
USART1_puts("write!\r\n");
I2C_stop(i2c_dev); // stop the transmission
USART1_puts("stop!\r\n");
delay(100);
I2C_start(i2c_dev, SLAVE_ADDRESS, I2C_Direction_Receiver); // start a transmission in Master receiver mode
USART1_puts("master received!\r\n");
tmp = I2C_read_nack(i2c_dev);
USART1_puts("read nack!\r\n");
I2C_stop(i2c_dev); // stop the transmission
USART1_puts("stop!\r\n");
delay(100);
return tmp;
}
示例3: AK8963_Init
void AK8963_Init(void)
{
int i = 0;
Delay(500000);
// First extract the factory calibration for each magnetometer axis
uint8_t buffer[3]; // x/y/z gyro calibration data stored here
AK8963_WriteRegister(AK8963_CNTL, MODE0_POWER_DOWN); // Power down magnetometer
AK8963_WriteRegister(AK8963_CNTL, MODE6_FUSE_ROM_ACCESS); // Enter Fuse ROM access mode
I2C_start(I2C1, AK8963_ADDRESS<<1, I2C_Direction_Transmitter);
I2C_write(I2C1, AK8963_ASAX);
I2C_stop(I2C1); // stop the transmission
// start a transmission in Master receiver mode
I2C_start(I2C1, AK8963_ADDRESS<<1, I2C_Direction_Receiver);
// read one byte and request another byte
for(i = 0; i < 3-1; i++){
buffer[i] = I2C_read_ack(I2C1);
}
// read one byte and don't request another byte, stop transmission
buffer[3-1] = I2C_read_nack(I2C1);
mag_calibration[0] = (float)(buffer[0] - 128)/256.0 + 1.0; // Return x-axis sensitivity adjustment values, etc.
mag_calibration[1] = (float)(buffer[1] - 128)/256.0 + 1.0;
mag_calibration[2] = (float)(buffer[2] - 128)/256.0 + 1.0;
AK8963_WriteRegister(AK8963_CNTL, MODE0_POWER_DOWN); // Power down magnetometer
AK8963_WriteRegister(AK8963_CNTL, RESOLUTION_16_BIT << 4 | MODE3_CONTINUOUS_100_HZ); // Set magnetometer data resolution and sample ODR
Delay(500000);
}
示例4: read_acc
void read_acc()
{
//acc
I2C_start(I2C1, LSM303DL_A_ADDRESS, I2C_Direction_Transmitter);
I2C_write(I2C1,0x28| (1 << 7));
I2C_stop(I2C1);
I2C_start(I2C1, LSM303DL_A_ADDRESS, I2C_Direction_Receiver);
xla = I2C_read_ack(I2C1);
xha = I2C_read_ack(I2C1);
yla = I2C_read_ack(I2C1);
yha = I2C_read_ack(I2C1);
zla = I2C_read_ack(I2C1);
zha = I2C_read_nack(I2C1);
I2C_stop(I2C1); // stop the transmission
char buffer_out[100];
ax=0,ay=0,az=0;
ax = ((int16_t)(xha << 8 | xla)) >> 4;
sprintf(buffer_out,"ax%i\r\n",ax);
usb_cdc_printf(buffer_out);
ay = ((int16_t)(yha << 8 | yla)) >> 4;
buffer_out[0]='\0';
sprintf(buffer_out,"ay%i\r\n",ay);
usb_cdc_printf(buffer_out);
az = ((int16_t)(zha << 8 | zla)) >> 4;
buffer_out[0]='\0';
sprintf(buffer_out,"az%i\r\n",az);
usb_cdc_printf(buffer_out);
//acc
}
示例5: I2C_recieve
void I2C_recieve(uint8_t slaveAddress, uint8_t regAddress, uint8_t data[], uint8_t dataLength)
{
uint8_t status, i;
status = I2C_start(); //Send start condition
if (status != TW_START) //Check value of TWI Status Register. Mask prescaler bits.
ERROR(status); //If status different from start go to error
TWDR = (slaveAddress + TW_WRITE) << 1; //Load SLA_W into TWDR Register
status = I2C_transmit(); //transmit
if (status != TW_MT_SLA_ACK) //Check value of TWI Status Register. Mask prescaler bits.
ERROR(status); //If status different from MR_SLA_ACK go to ERROR
TWDR = regAddress; //Load register address into TWDR Register
status = I2C_transmit(); //transmit
if (status != TW_MT_SLA_ACK) //Check value of TWI Status Register. Mask prescaler bits.
ERROR(status); //If status different from MR_SLA_ACK go to ERROR
status = I2C_start(); //Send start condition
if (status != TW_START) //Check value of TWI Status Register. Mask prescaler bits.
ERROR(status); //If status different from start go to error
TWDR = (slaveAddress << 1) + TW_READ; //Load SLA_R into TWDR Register
status = I2C_transmit(); //transmit
if (status != TW_MR_SLA_ACK) //Check value of TWI Status Register. Mask prescaler bits.
ERROR(status); //If status different from MR_SLA_ACK go to ERROR
status = I2C_transmit(); //transmit
if (status != TW_MR_DATA_ACK) //Check value of TWI Status Register. Mask prescaler bits.
ERROR(status); //If status different from MR_SLA_ACK go to ERROR
data[0] = TWDR;
//TWCR &= ~(1<<TWEA); //generate a NACK to let the slave now that the master is done
I2C_stop(); //Send stop condition
}
示例6: read_mag
void read_mag()
{
//mag
I2C_start(I2C1, LSM303DL_M_ADDRESS, I2C_Direction_Transmitter);
I2C_write(I2C1,0x03); //LSM303_OUT_X_H_M 0x03
I2C_stop(I2C1);
I2C_start(I2C1, LSM303DL_M_ADDRESS, I2C_Direction_Receiver);
xhm = I2C_read_ack(I2C1);
xlm = I2C_read_ack(I2C1);
yhm = I2C_read_ack(I2C1);
ylm = I2C_read_ack(I2C1);
zhm = I2C_read_ack(I2C1);
zlm = I2C_read_nack(I2C1);
I2C_stop(I2C1);
char buffer_out[100];
mx=0,my=0,mz=0;
mx = (int16_t)(xhm << 8 | xlm);
sprintf(buffer_out,"mx%i\r\n",mx);
usb_cdc_printf(buffer_out);
my = (int16_t)(yhm << 8 | ylm);
buffer_out[0]='\0';
sprintf(buffer_out,"my%i\r\n",my);
usb_cdc_printf(buffer_out);
mz = (int16_t)(zhm << 8 | zlm);
buffer_out[0]='\0';
sprintf(buffer_out,"mz%i\r\n",mz);
usb_cdc_printf(buffer_out);
//mag
}
示例7: readRegister
uint8_t readRegister(uint8_t sensorAddress, uint8_t _register){
I2C_start(ULTRASONICSENSOR_I2C, sensorAddress, I2C_Direction_Transmitter);
I2C_write(ULTRASONICSENSOR_I2C, _register);
I2C_stop(ULTRASONICSENSOR_I2C);
I2C_start(ULTRASONICSENSOR_I2C, sensorAddress, I2C_Direction_Receiver);
return I2C_read_nack(ULTRASONICSENSOR_I2C);
}
示例8: read_gyro
void read_gyro()
{
//gyro
I2C_start(I2C1, LSM303DL_G_ADDRESS, I2C_Direction_Transmitter);
I2C_write(I2C1, 0x28| (1 << 7) ); //L3G_OUT_X_L 0x28
I2C_stop(I2C1);
I2C_start(I2C1, LSM303DL_G_ADDRESS, I2C_Direction_Receiver);
xlg = I2C_read_ack(I2C1);
xhg = I2C_read_ack(I2C1);
ylg = I2C_read_ack(I2C1);
yhg = I2C_read_ack(I2C1);
zlg = I2C_read_ack(I2C1);
zhg = I2C_read_nack(I2C1);
I2C_stop(I2C1);
char buffer_out[100];
gx=0,gy=0,gz=0;
gx = (int16_t)(xhg << 8 | xlg);
sprintf(buffer_out,"gx%i\r\n",gx);
usb_cdc_printf(buffer_out);
gy = (int16_t)(yhg << 8 | ylg);
buffer_out[0]='\0';
sprintf(buffer_out,"gy%i\r\n",gy);
usb_cdc_printf(buffer_out);
gz = (int16_t)(zhg << 8 | zlg);
buffer_out[0]='\0';
sprintf(buffer_out,"gz%i\r\n",gz);
usb_cdc_printf(buffer_out);
//gyro
}
示例9: rtrd
// ds1307 rtc read
bit rtrd (void)
{
unsigned char i; // return 0=ok 1=error
bit err;
I2C_start();
err = I2C_write(0xd0); // address & r/w bit
if (!err)
{
printf("in rtrd");
err = I2C_write(0x00); // start register addr=0
if (!err)
{
printf("in rtrd");
I2C_stop();
I2C_delay();
I2C_start();
err = I2C_write(0xd1); // address & r/w bit
if (!err)
{
printf("in rtrd");
for (i=0;i<=6;i++)
{
TIMBUF[i] = I2C_read();
}
TIMBUF[7] = I2C_readn(); // last byte
}
}
}
I2C_stop();
return (err);
}
示例10: checkInterrupt
char checkInterrupt(){
char int_values;
I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);
I2C_write(I2C_BASE, 0x30, 0);
I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 1);
int_values = I2C_read(I2C_BASE, 1);
return int_values;
}
示例11: I2C_read_register
byte I2C_read_register(byte device_register){
byte data = 0;
I2C_start();
I2C_send_address(DS1307);
I2C_write(device_register);
I2C_start();
I2C_send_address(DS1307+1);//Read operation
data = I2C_read_nack();
I2C_stop();
return data;
}
示例12: ov7670_get
uint8_t ov7670_get(uint8_t reg) {
uint8_t data = 0;
I2C_start(I2C2, 0x42, I2C_Direction_Transmitter);
I2C_write(I2C2, reg);
I2C_stop(I2C2);
delayx(1000);
I2C_start(I2C2, 0x43, I2C_Direction_Receiver);
data = I2C_read_nack(I2C2);
I2C_stop(I2C2);
delayx(1000);
return data;
}
示例13: I2C_Read_Reg
uint8_t I2C_Read_Reg(I2C_TypeDef* I2Cx, uint8_t Device, uint8_t Register)
{
uint8_t data;
I2C_start(I2Cx, Device <<1, I2C_Direction_Transmitter); // start a transmission in Master transmitter mode
I2C_write(I2Cx, Register); // Select the register you want to read from.
I2C_stop(I2Cx); // stop the transmission
I2C_start(I2Cx, Device <<1, I2C_Direction_Receiver); // start a transmission in Master receiver mode
data = I2C_read_nack(I2Cx); // read one byte from the register of interest.
I2C_stop(I2Cx);
return data;
}
示例14: PCF8583_read
u08 PCF8583_read(u08 address)
{
u08 a;
a=(PCF8583_A0<<1)|0xa0;
I2C_start();
I2C_write(a);
I2C_write(address);
I2C_start();
I2C_write(a|1);
a=I2C_read(1);
I2C_stop();
return a;
}
示例15: initHt16
void initHt16(){
I2C_start(I2C1, slave_address<<1, I2C_Direction_Transmitter); // start a transmission in Master transmitter mode
I2C_write(I2C1, osci); // write one byte to the slave
I2C_stop(I2C1);
/*Blink off*/
I2C_start(I2C1, slave_address<<1, I2C_Direction_Transmitter); // start a transmission in Master transmitter mode
I2C_write(I2C1, HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (HT16K33_BLINK_OFF << 1));
I2C_stop(I2C1);
/*max brightness*/
I2C_start(I2C1, slave_address<<1, I2C_Direction_Transmitter); // start a transmission in Master transmitter mode
I2C_write(I2C1, HT16K33_CMD_BRIGHTNESS| 2);
I2C_stop(I2C1);
}