After using software master I2C on ATTiny85 succesfully before, now trying use USI I2C and this what I've noticed in this sample I2C master library described there:
ATTiny USI I2C Introduction - A powerful, fast, and convenient communication interface for your ATTiny projects!it looks there is no timeout support etc :/
Additionally, I've no idea .. how I2C frequency is defined, since it looks like they use something like this for timing in
usi_i2c_master.c:
#define USICR_CLOCK_STROBE_MASK 0b00101011
#define USI_CLOCK_STROBE() { USICR = USICR_CLOCK_STROBE_MASK; }
I've no external clock in many ATTiny projects since I do not need fast I2C and what I've noticed is
USI
USICR register mask defined in this file
I've downloaded this example USI I2C ATTiny library from this linked mentioned in above instructables:
https://github.com/CalcProgrammer1/Stepper-Motor-Controller/tree/master/UnipolarStepperDriverAdded definitions for ATTiny85 port and SCL/SDA pin definitions like this:
#if defined (__AVR_ATtiny25__) | \
defined (__AVR_ATtiny45__) | \
defined (__AVR_ATtiny85__)
#define DDR_USI DDRB
#define PORT_USI PORTB
#define PIN_USI PINB
#define PORT_USI_SDA PB0
#define PORT_USI_SCL PB2
#define PIN_USI_SDA PINB0
#define PIN_USI_SCL PINB2
#endif
It compiles now, but while trying to talk to RTC (PCF8563) to set its output clock out to 1 Hz in my hand watch project, for the moment probably waits forever in one of those: USI_I2C_WAIT_HIGH() / USI_I2C_WAIT_LOW() routines since for the moment I didn't have timeout support-just tried to use this library and see how it works on ATTiny85
Maybe external crystal clock was used in this project, so USICR_CLOCK_STROBE_MASK bits
00101011 In ATTiny85 datsheet I found something like this:
The clock can be selected from three different sources: The USCK pin, Timer/Counter0 Compare Match or from software.
...
The clock is generated by the Master device software by toggling the USCK pin via the PORTB register or by writing a one to bit USITC bit in USICR.
ATTiny85 USICR register below:
Such bits are set in clock strobe routines in USICR:
00101011 -there is no F_CPU or something like I2C frequency settings in this linked USI I2C library...
Last page of ATTiny85 USI documentation shows how clock is selected and it looks like bits USICR[3:1] (101) in this I2C master library selects clock source as "External, positive edge" with "Software clock strobe USITC" .
Does it mean this I2C master library uses external clock connected to SCL pin? Doesn't setting USITC toggle this SDA line?
According to this page they only mention that to be able see SCL changes DDR output pin must be set (1) to allow "easy" clock generation when implementing master devices
What exactly this "External, positive edge" clock source means? Which clock?-I haven't got external crystal clock.
I could create timer and drive this SCL pin, since I do not want any external clocks in low speed I2C setups.
I'm lost for the moment with USI I2C setup, but have ready Attiny85 programmed so will try hard today talk to this RTC as I2C master
Support for I2C master arrbitration could be additional advantage and challenge, since in a few projects I might want use this more advanced I2C master mode.
Could someone give some hints (maybe I'm missing something) USI I2C master ATTiny85 library (without any external crystal clocks), please?
Reading again this ATTiny USI datasheet (pages from 108 in linked below PDF):
http://www.atmel.com/Images/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdfNOTE: I've F_CPU set to 8MHz, but no fuses set for this-I switch to 8MHz at the beginning in software, than wait 1s and try to talk via I2C to RTC using routines described above... so my ATTiny85 runs at 8MHz now , but it will be much lower frequency in hand watch project to save battery life .
#define F_CPU 8000000UL