I2C Help Required!
Posted: Sat Jun 03, 2017 4:53 am
The documentation on I2C functions is sparse, to say the least! I am interfacing a DS1307 chip with the ESP12 and can successfully read the time from the RTC. However, it's a day out and, whatever I try, I cannot seem to write to the chip.
Previous experience with other microcontrollers and I2C suggests that I first need to do an I2C.begin with the address of the RTC (&H68, or 104), then do a write to the byte that I want to modify - I2C.write(4) which is the date field, and finally the value I want in that field - I2C.write(3) and an I2C.end command. The question is, do I need an I2C.end between the two writes? Do I need to do another I2C.begin between the writes, with or without the I2C.end?
This is part of the code I have been trying:
but whatever combination of commenting in or out of the two lines in the middle, the value never gets changed.
I know the basic I2C connection is working because I can read the time and date from the RTC with no problems. Where am I going wrong?
Previous experience with other microcontrollers and I2C suggests that I first need to do an I2C.begin with the address of the RTC (&H68, or 104), then do a write to the byte that I want to modify - I2C.write(4) which is the date field, and finally the value I want in that field - I2C.write(3) and an I2C.end command. The question is, do I need an I2C.end between the two writes? Do I need to do another I2C.begin between the writes, with or without the I2C.end?
This is part of the code I have been trying:
Code: Select all
address = 104
i2c.setup(13,12) 'set I2C pins on ESP
i2c.begin(address) 'start I2C conversation
i2c.write(4) 'point to the date address location
'i2c.end() 'finish this conversation
'i2c.begin(address) 'start another conversation
i2c.write(3) 'the value to go in the date field
i2c.end 'finish this conversation
but whatever combination of commenting in or out of the two lines in the middle, the value never gets changed.
I know the basic I2C connection is working because I can read the time and date from the RTC with no problems. Where am I going wrong?