I'm trying to use the I2C on an 841, to send data to a raspberry Pi. It is currently "kind of" working, where I can see data but it is not fully coherent.
If I try to do a 'BUS.read_i2c_block_data' it fails with an Input/Output error
I can seem to get data if I read byte by byte with 'BUS.read_byte' and a test loop. But weirdly it seems to be missing every other byte from the sent test string.
At the moment I am working through the code on the slave side (ATTINY841) to try and figure out how the function I got (from a forum) is working the TWI to see if I can figure out the problem.
The code that initialises the TWI is a bit curious:
TWSCRA = (1 << TWEN) // Two-Wire Interface Enable
| (1 << TWSHE) // TWI SDA Hold Time Enable
| (1 << TWASIE) // TWI Address/Stop Interrupt Enable
| (1 << TWSIE) // TWI Stop Interrupt Enable
| (1 << TWDIE); // TWI Data Interrupt Enable
I can see how it is setting up the TWSCRA register that controls the I2C using bitwise shifts, but can't see where the bitwise values are coming from.
example "TWSHE" is being shifted in to the register, but what is 'TWSHE' value?
I can only think that "TWSHE" is a const with a value of the correct bit (bit 7 on an ATTINY841)- presumably to allow the library to work with different devices, is this a correct assumption?