本文整理汇总了C++中I2C_Write函数的典型用法代码示例。如果您正苦于以下问题:C++ I2C_Write函数的具体用法?C++ I2C_Write怎么用?C++ I2C_Write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了I2C_Write函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: i2c_data_verify
bool i2c_data_verify(alt_u32 scl_base, alt_u32 sda_base, alt_u8 ControlAddr){
bool bPass;
const alt_8 DeviceAddr = 0xA0;
alt_u8 OrgData, TestData, Data;
TestData = alt_nticks();
if (TestData == 0)
TestData = 0x12;
bPass = I2C_Read(scl_base, sda_base, DeviceAddr, ControlAddr, &OrgData);
if (bPass) // write
bPass = I2C_Write(scl_base, sda_base, DeviceAddr, ControlAddr, TestData);
if (bPass) // read
bPass = I2C_Read(scl_base, sda_base, DeviceAddr, ControlAddr, &Data);
if (bPass && (Data != TestData)) // verify
bPass = FALSE;
// restore
if (bPass) // write back
bPass = I2C_Write(scl_base, sda_base, DeviceAddr, ControlAddr, OrgData);
if (bPass) // read
bPass = I2C_Read(scl_base, sda_base, DeviceAddr, ControlAddr, &Data);
if (bPass && (Data != OrgData)) // verify
bPass = FALSE;
return bPass;
}
示例2: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main()
{
int i;
/*System clock configuration*/
SystemInit();
/* Configure UART2 */
S_UART_Init(115200);
conf.scl = I2C_PA_9;
conf.sda = I2C_PA_10;
I2C_Init(&conf);
//============ Write ==============
I2C_Write(&conf, 0xa0, &Transmit_Data[0], MAX_SIZE);
delay_function(4000);
//========= Read =============
//Write memory address
I2C_Write(&conf, 0xA0, &Transmit_Data[0], 1);
delay_function(4000);
//Read data
I2C_Read(&conf, 0xA0, &Recv_Data[0], MAX_SIZE - 1);
printf("Recv data : ");
for(i=0; i<MAX_SIZE - 1; i++)
{
printf("0x%x ", Recv_Data[i]);
}
printf("\r\n");
}
示例3: Init_MPU6050
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
// MPU-6050 initialisieren
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
void Init_MPU6050(void) {
// Abtastrate des Sensors einstellen - Register 0x19 mit 7 beschreiben
i2cData[0] = 0x19;
i2cData[1] = 7;
I2C_Write(I2C1, i2cData, 2, I2C_MPUAddress);
// internen Tiefpassfilter deaktivieren - Register 0x1A mit 0 beschreiben
i2cData[0] = 0x1A;
i2cData[1] = 0x00;
I2C_Write(I2C1, i2cData, 2, I2C_MPUAddress);
// max. Messbereich des Drehratensensors auf +/-250°/s einstellen - Register 0x1B mit 0 beschreiben
i2cData[0] = 0x1B;
i2cData[1] = 0x00;
I2C_Write(I2C1, i2cData, 2, I2C_MPUAddress);
// max. Messbereich des Beschleunigungssensors auf +/-2g einstellen - Register 0x1C mit 0 beschreiben
i2cData[0] = 0x1C;
i2cData[1] = 0x00;
I2C_Write(I2C1, i2cData, 2, I2C_MPUAddress);
// Taktquelle auswählen - Register 0x6B mit 1 beschreiben
PLL[0] = 0x6B;
PLL[1] = 0x01;
I2C_Write(I2C1, PLL, 2, I2C_MPUAddress);
}
示例4: MPL3115A2_write8
bool MPL3115A2_write8(uint8_t a, uint8_t d) {
unsigned char data_write[2];
data_write[0] = a;
data_write[1] = d;
int i;
for(i=0;i<5;i++)
{
if(I2C_Write(MPL3115A2_ADDRESS,
data_write,
2,
1)) // no stop bit
break;
}
if(i<5) {
d = MPL3115A2_read8(a);
while(d != data_write[1])
{
if(I2C_Write(MPL3115A2_ADDRESS,
data_write,
2,
1)) // no stop bit
{
d = MPL3115A2_read8(a);
if (d == data_write[1])
return true;
}
i++;
if (i>5)
break;
}
return true;
}
return false;
}
示例5: I2C_PCA9532_SetPwm
/*********************************************************************
*
* I2C_PCA9532_SetPwm
*
* Function description
* Sets the timing for PWM0 or PWM1 and assigns the pin to the
* according PWM.
*
* Return value
* 0: O.K.
* != 0: Error
*/
U8 I2C_PCA9532_SetPwm(U32 I2CBaseAddr, U8 Addr, U8 Pin, U8 PwmNumber, U8 Pwm, U8 Psc) {
U8 Data[2];
U8 r;
if (PwmNumber > 1) {
return 1; // Error, invalid PWM number
}
if (PwmNumber) {
Data[0] = PSC1;
} else {
Data[0] = PSC0;
}
Data[1] = Psc;
r = I2C_Write(I2CBaseAddr, Addr, Data, 2);
if (r == 0) {
if (PwmNumber) {
Data[0] = PWM1;
} else {
Data[0] = PWM0;
}
Data[1] = Pwm;
r = I2C_Write(I2CBaseAddr, Addr, Data, 2);
if (r == 0) {
r = _SetPinSelect(I2CBaseAddr, Addr, Pin, I2C_PCA9532_PWM0 + PwmNumber);
}
}
return r;
}
示例6: BusyXLCD
unsigned char BusyXLCD(void) {
OLATB_curr |= 0xC0; // RW and RS are on
clockLCDLow();
I2C_Write(EXPANDER_IODIRB, 0x1E); // data bus is now an input
I2C_Write(EXPANDER_OLATB, OLATB_curr);
DelayFor18TCY();
clockLCDHigh(); // Clock in the command with E
DelayFor18TCY();
busy = I2C_Read(EXPANDER_GPIOB);
clockLCDLow(); // Reset clock line
DelayFor18TCY();
clockLCDHigh(); // Clock out other nibble
DelayFor18TCY();
clockLCDLow();
OLATB_curr &= 0xBF; // Reset control line
I2C_Write(EXPANDER_OLATB, OLATB_curr);
I2C_Write(EXPANDER_IODIRB, 0x00); // set data bus back to output
// busy bit is high?
if (busy & 0x02)
{
return 1;
}
// Busy bit is low
return 0;
}
示例7: I2C_StoreDate
//--------------------------------------------------------
void I2C_StoreDate(stDS1307Time *time)
{
I2C_Write(TMR_ADDR,REG_MONTH,time->Month);
_delay_us(100);
I2C_Write(TMR_ADDR,REG_DATE,time->Date);
_delay_us(100);
}
示例8: I2C_WriteRegister
void I2C_WriteRegister(uint8_t deviceRegister, uint8_t data) {
I2C_Start(DS1307);
// send address
I2C_Write(deviceRegister);
// write data to that address
I2C_Write(data);
I2C_Stop();
}
示例9: Init_L3G4200D
void Init_L3G4200D(void)
{
SCLDirOut();
SDADirOut();
I2C_Write(L3G4200D_SLAVE_ADDR, CTRL_REG1,0x4f);
I2C_Write(L3G4200D_SLAVE_ADDR, CTRL_REG2,0x00);
I2C_Write(L3G4200D_SLAVE_ADDR, CTRL_REG3,0x08);
I2C_Write(L3G4200D_SLAVE_ADDR, CTRL_REG4,0x00);
I2C_Write(L3G4200D_SLAVE_ADDR, CTRL_REG5,0x00);
}
示例10: I2C_StoreTime
//---------------------------------------------------
void I2C_StoreTime(stDS1307Time *time)
{
I2C_Write(TMR_ADDR,REG_HOURS,time->Hours);
_delay_us(100);
I2C_Write(TMR_ADDR,REG_MINUTES,time->Minutes);
_delay_us(100);
I2C_Write(TMR_ADDR,REG_SECONDS,0x0);
_delay_us(100);
}
示例11: RTC_Init
/***************************************************************************************************
void RTC_Init()
***************************************************************************************************
* I/P Arguments: none.
* Return value : none
* description :This function is used to Initialize the Ds1307 RTC.
***************************************************************************************************/
void RTC_Init()
{
I2C_Init(); // Initialize the I2c module.
I2C_Start(); // Start I2C communication
I2C_Write(C_Ds1307WriteMode_U8); // Connect to DS1307 by sending its ID on I2c Bus
I2C_Write(C_Ds1307ControlRegAddress_U8);// Select the Ds1307 ControlRegister to configure Ds1307
I2C_Write(0x00); // Write 0x00 to Control register to disable SQW-Out
I2C_Stop(); // Stop I2C communication after initializing DS1307
}
示例12: RTC_SetDate
/***************************************************************************************************
void RTC_SetDate(uint8_t var_day_u8, uint8_t var_month_u8, uint8_t var_year_u8)
****************************************************************************************************
* I/P Arguments: uint8_t,uint8_t,uint8_t-->day,month,year to Initialize the Date into DS1307.
* Return value : none
* description :This function is used to set Date(dd,mm,yy) into the Ds1307 RTC.
The new Date is updated into the non volatile memory of Ds1307.
Note: The I/P arguments should of BCD,
like 0x15,0x08,0x47 for 15th day,8th month and 47th year.
***************************************************************************************************/
void RTC_SetDate(uint8_t var_day_u8, uint8_t var_month_u8, uint8_t var_year_u8)
{
I2C_Start(); // Start I2C communication
I2C_Write(C_Ds1307WriteMode_U8); // connect to DS1307 by sending its ID on I2c Bus
I2C_Write(C_Ds1307DateRegAddress_U8); // Request DAY RAM address at 04H
I2C_Write(var_day_u8); // Write date on RAM address 04H
I2C_Write(var_month_u8); // Write month on RAM address 05H
I2C_Write(var_year_u8); // Write year on RAM address 06h
I2C_Stop(); // Stop I2C communication after Setting the Date
}
示例13: DS1307_SetTime
void DS1307_SetTime(unsigned char hh, unsigned char mm, unsigned char ss)
{
I2C_Start(); // Start I2C communication
I2C_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
I2C_Write(SEC_ADDRESS); // Select the SEC RAM address
I2C_Write(ss); // Write sec on RAM address 00H
I2C_Write(mm); // Write min on RAM address 01H
I2C_Write(hh); // Write hour on RAM address 02H
I2C_Stop(); // Stop I2C communication after Setting the Time
}
示例14: RTC_SetTime
/***************************************************************************************************
void RTC_SetTime(uint8_t var_hour_u8, uint8_t var_min_u8, uint8_t var_sec_u8)
****************************************************************************************************
* I/P Arguments: uint8_t,uint8_t,uint8_t-->hh,mm,ss to Initialize the time into DS1307.
* Return value : none
* description :This function is used to update the Time(hh,mm,ss) of Ds1307 RTC.
The new time is updated into the non volatile memory of Ds1307.
Note: The I/P arguments should of BCD,
like 0x12,0x39,0x26 for 12hr,39min and 26sec.
***************************************************************************************************/
void RTC_SetTime(uint8_t var_hour_u8, uint8_t var_min_u8, uint8_t var_sec_u8)
{
I2C_Start(); // Start I2C communication
I2C_Write(C_Ds1307WriteMode_U8); // connect to DS1307 by sending its ID on I2c Bus
I2C_Write(C_Ds1307SecondRegAddress_U8); // Select the SEC RAM address
I2C_Write(var_sec_u8); // Write sec from RAM address 00H
I2C_Write(var_min_u8); // Write min from RAM address 01H
I2C_Write(var_hour_u8); // Write hour from RAM address 02H
I2C_Stop(); // Stop I2C communication after Setting the Time
}
示例15: DS1307_SetDate
void DS1307_SetDate(unsigned char dd, unsigned char mm, unsigned char yy)
{
I2C_Start(); // Start I2C communication
I2C_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
I2C_Write(DATE_ADDRESS); // Request DAY RAM address at 04H
I2C_Write(dd); // Write date on RAM address 04H
I2C_Write(mm); // Write month on RAM address 05H
I2C_Write(yy); // Write year on RAM address 06h
I2C_Stop(); // Stop I2C communication after Setting the Date
}