Crenn,
I2C soft isn't working out for me. Like I said, I modified the Wire.h and Wire.c code to do multiple byte reads. The following is some of my modified code for soft i2c.
uint8 TwoWire::requestFrom(uint8 address, int num_bytes) {
if (num_bytes > WIRE_BUFSIZ) num_bytes = WIRE_BUFSIZ;
rx_buf_idx = 0;
rx_buf_len = 0;
i2c_start(port);
i2c_shift_out(port, (address << 1) | I2C_READ);
if (!i2c_get_ack(port)) return ENACKADDR;
while (rx_buf_len < num_bytes) {
if(rx_buf_len == num_bytes - 1) {
if(!readOneByte(rx_buf + rx_buf_len, HALT)) rx_buf_len++;
else break;
} else {
if(!readOneByte(rx_buf + rx_buf_len, CONTINUE)) rx_buf_len++;
else break;
}
}
i2c_stop(port);
return rx_buf_len;
}
uint8 TwoWire::readOneByte(uint8 *byte, uint8 status) {
*byte = i2c_shift_in(port);
// digitalWrite(port.sda,LOW);
if (status == CONTINUE) i2c_send_ack(port);
else i2c_send_nack(port);
return SUCCESS; // no real way of knowing, but be optimistic!
}
The readings from my oscilloscope shows exactly what the ADXL345 expects for multiple byte i2c reads. (see Figure 40 from http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf). However, after reading the first byte and sending an ACK, the remaining 5 bytes read are all zeros.
I don't quite understand the hardware I2C from the refactor libmaple repository. If someone can point me to some documentation on how Perry's i2c code works, that would speed up my learning process tremendously.