by maestro » Mon Nov 02, 2009 4:09 pm
by maestro
Mon Nov 02, 2009 4:09 pm
Hi,
I'm using roboard and the roblib to obtain some i2c values.
Sometimes reading values works just fine, but sometimes I get the following errors_
Can't open I2c
Interrupted system call
It means, that ii2c_Initialize() fails while initializing the i2c bus. Which system (which can be interrupted) are used in i2c_initialize()? Can I write a more reliable function to obtain the i2c_values?
- Code: Select all
int ADin::MCP3221getADvalue() {
unsigned char highByte, lowByte;
if (i2c_Initialize(I2CIRQ_DISABLE) == false) {
Logger::error << __func__ << ": Can't open I2c" << std::endl;
Logger::error << strerror(errno) << std::endl;
return -5;
}
if (i2c0_SetSpeed(I2CMODE_STANDARD, 100000L) == 0) {
Logger::error << __func__ << ": Can't set speed: "
<< roboio_GetErrMsg() << std::endl;
}
//START with address 0x40 to write 1 byte
if (!i2c0master_Start(MCP3221, I2C_READ)) {
Logger::error << __func__ << ": START fail ( " << roboio_GetErrMsg()
<< ")... try again" << std::endl;
if (!i2c0master_Start(MCP3221, I2C_READ)) {
Logger::error << __func__ << ": START fail again ( "
<< roboio_GetErrMsg() << ")" << std::endl;
i2c_Close();
return -4;
}
}
highByte = i2c0master_ReadSecondLast();
lowByte = i2c0master_ReadLast();
i2c_Close();
return highByte * 256 + lowByte;
}
Thanks for any suggestions. [/list]
Hi,
I'm using roboard and the roblib to obtain some i2c values.
Sometimes reading values works just fine, but sometimes I get the following errors_
Can't open I2c
Interrupted system call
It means, that ii2c_Initialize() fails while initializing the i2c bus. Which system (which can be interrupted) are used in i2c_initialize()? Can I write a more reliable function to obtain the i2c_values?
- Code: Select all
int ADin::MCP3221getADvalue() {
unsigned char highByte, lowByte;
if (i2c_Initialize(I2CIRQ_DISABLE) == false) {
Logger::error << __func__ << ": Can't open I2c" << std::endl;
Logger::error << strerror(errno) << std::endl;
return -5;
}
if (i2c0_SetSpeed(I2CMODE_STANDARD, 100000L) == 0) {
Logger::error << __func__ << ": Can't set speed: "
<< roboio_GetErrMsg() << std::endl;
}
//START with address 0x40 to write 1 byte
if (!i2c0master_Start(MCP3221, I2C_READ)) {
Logger::error << __func__ << ": START fail ( " << roboio_GetErrMsg()
<< ")... try again" << std::endl;
if (!i2c0master_Start(MCP3221, I2C_READ)) {
Logger::error << __func__ << ": START fail again ( "
<< roboio_GetErrMsg() << ")" << std::endl;
i2c_Close();
return -4;
}
}
highByte = i2c0master_ReadSecondLast();
lowByte = i2c0master_ReadLast();
i2c_Close();
return highByte * 256 + lowByte;
}
Thanks for any suggestions. [/list]