我想尝试使用 arduino 上的 smbus 黑客代码修复我的电池。首先它有一些问题。我尝试修复它们,并且修复了。现在我在库上遇到了问题
i2c\test_i2cmaster.co:在函数
main': C:\Users\ugur\Documents\Arduino\libraries\i2c/test_i2cmaster.c:22: multiple definition of
main' 中 i2c\main.co:C:\Users\ugur\Documents\Arduino\libraries\i2c/main.c:88:首先在此处定义 i2c\twimaster.co:在函数i2c_init': C:\Users\ugur\Documents\Arduino\libraries\i2c/twimaster.c:31: multiple definition of
i2c_init' 中 i2c\i2cmaster.So:(.text+0x10):首先在此处定义 i2c\twimaster.co:在函数i2c_start': C:\Users\ugur\Documents\Arduino\libraries\i2c/twimaster.c:42: multiple definition of
i2c_start' 中 i2c\i2cmaster.So:(.text+0x1a):首先在此处定义 i2c\twimaster.co:在函数i2c_start_wait': C:\Users\ugur\Documents\Arduino\libraries\i2c/twimaster.c:78: multiple definition of
i2c_start_wait' 中 i2c\i2cmaster.So:(.text+0x36):首先在此处定义 i2c\twimaster.co:在函数i2c_rep_start': C:\Users\ugur\Documents\Arduino\libraries\i2c/twimaster.c:130: multiple definition of
i2c_rep_start' 中 i2c\i2cmaster.So:(.text+0x22):首先在此处定义 i2c\twimaster.co:在函数i2c_stop': C:\Users\ugur\Documents\Arduino\libraries\i2c/twimaster.c:141: multiple definition of
i2c_stop'中i2c\i2cmaster.So:(.text+0x4a): 首先在此处定义 i2c\twimaster.co: 在函数i2c_write': C:\Users\ugur\Documents\Arduino\libraries\i2c/twimaster.c:161: multiple definition of
i2c_write' 中 i2c\i2cmaster.So:(.text+0x5a): 首先在此处定义 i2c\twimaster.co: 在函数i2c_readAck': C:\Users\ugur\Documents\Arduino\libraries\i2c/twimaster.c:182: multiple definition of
i2c_readAck' 中 i2c\i2cmaster.So:(.text+0x96): 首先在此处定义 i2c\twimaster.co: 在函数i2c_readNak': C:\Users\ugur\Documents\Arduino\libraries\i2c/twimaster.c:197: multiple definition of
i2c_readNak' 中 i2c\i2cmaster.So:(.text+0x92): 首先在此处定义
图书馆是;
如果定义 F_CPU
定义F_CPU 16000000UL
万一
包括
包括
定义 F_SCL 100000UL //SCL 频率
定义预分频器 1
定义 TWBR_val ((((F_CPU / F_SCL) / 预分频器) - 16 ) / 2)
void I2C_init(void){ TWBR = TWBR_val; }
uint8_t I2C_start(uint8_t address){ // 复位 TWI 控制寄存器 TWCR = 0; // 发送 START 条件 TWCR = (1<
// check if the start condition was successfully transmitted
if((TWSR & 0xF8) != TW_START){ return 1; }
// load slave address into data register
TWDR = address;
// start transmission of address
TWCR = (1<<TWINT) | (1<<TWEN);
// wait for end of transmission
while( !(TWCR & (1<<TWINT)) );
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return 1;
return 0;
}
void I2C_write(uint8_t data){ // 将数据加载到数据寄存器 TWDR = data; // 开始传输数据 TWCR = (1<
if( (TWSR & 0xF8) != TW_MT_DATA_ACK ){ return 1; }
return 0;
}
uint8_t I2C_read_ack(无效){
// start TWI module and acknowledge data after reception
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
// wait for end of transmission
while( !(TWCR & (1<<TWINT)) );
// return received data from TWDR
return TWDR;
}
uint8_t I2C_read_nack(无效){
// start receiving without acknowledging reception
TWCR = (1<<TWINT) | (1<<TWEN);
// wait for end of transmission
while( !(TWCR & (1<<TWINT)) );
// return received data from TWDR
return TWDR;
}
void I2C_stop(void){//发送 STOP 条件 TWCR = (1<
我该如何修复它?我是 arduino 和 c/c++ 的新手