Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

i2C on Pic18F67K22 & RTC DS3231 (DS1307) in Mpasm

Status
Not open for further replies.

Djdan_23

New Member
I'm building my programmable "Home heating system control" with 5 times (1 LCD + 2 switches + LM35+ 1 led + 1 relay) + 1 Master LCD & 3 switches & LM 35 & 1 led + 1 relay.
I took a PIC18F26K22 to have enough pins, an internal osc of 16Mhz & a big EEPROM. I use a DS3231 (Chronodot V2.1 from Adafruit) as an external RTC for more precision. I've been working on some "way smaller" PIC chip before but nothing compare to this one. I would like to know how to implement my own I2C software, to talk to this DS3231 (Like the DS1307). Meaning using 2 general pins and my own program, not using the I2C of the chip, to be able to study more about this bus. A good (Documented) and easy way to send and receive from DS3231 once every seconds. Especially according to the way of setting the SDA and SCL timing versus the fast speed of the PIC. I think I will be able to do the rest (LCDs-LM35s-switches-leds-Relays-EEPROM). And finally it should be program in MPLABX : MPASM as I know nothing about the C language, (Or in simple asm). If it too much problem then it could be using the i2C of the chip. Any help is welcome. That may be helpful to other too.
Many thanks to all for your help. Dan

https://www.adafruit.com/products/255
https://datasheets.maximintegrated.com/en/ds/DS3231.pdf
 
Especially according to the way of setting the SDA and SCL timing versus the fast speed of the PIC.

There isn't a huge difference in speed. I2C runs up to 400 KHz, the PIC18F26K22 runs at 16 MIPS max, so to go slowly enough for the I2C you are going to want delay loops of 20 instructions or so if you are running the processor at full speed. That isn't enough time for the processor to usefully go off and do something else, so just a simple delay routine that you call when needed would do.

There is a bit-banged example here

That code has several examples of GOTO $+1 which is a way of getting a 2 cycle pause for 1 line of code. Depending on how fast the PIC is running you might need to substitute a call to a 20 ish cycle delay routine.

If you are wanting to read a few bytes of data it will take less than 10 ms, so for house heating applications you can probably afford the time to finishing talking to the DS3231 and ignore everything else. That is very different from something like RS232 where you have to be accurate with the timing, data could arrive at any time, and it could be quite slow. That is much more difficult to work with if you are doing other things at the same time.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top