I have poked and prodded on with this as far as I want to go for now, so I want to move up a gear and incorporate my DS1307 RTC Module. I have gone to an enormous expense and invested in a readymade module from Fleabay again, its an I2C Tiny RTC DS1307 Real Time Clock Module with an NVR AT24C32 onboard. Which I’m hoping to cobble into my 16f18326,32 and GLC SSD1306 which is counting away the hours quite merrily in front of me.
I have not changed any of the I2C bus ports, parameters or settings from the original code which started me going and I have reviewed the i2c_DS1307_16F1937_LCD.gcb from the GCB Demo’s which looks like something I could possible graft onto (or into) my project.
I have a feeling someone is going to say just change the #chip 16F1937, 32 to #chip 16f18326,32 and it should work just fine, but my gut instinct is telling me to ask before screwing everything up, and confusing the hell out of me.
The RTC Module is on Fleabay item number: 221445347596 it has all the I2C protocol connections and a backup battery. I could post what code I have so far if you think necissary.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is there a video or some help on using the I2C Discovery routine as you mention? I have found the i2c2HardwareDiscovery to Terminal_Alternative_Display_16F18855.gcb code in the Demo's directortories, Is this the right one?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Back at the bowl again, looking for a solution. I have tried grafting the settings from my working GLCD project in a hope that I could see some sort of response. Needless to say it simply throws the rattle out of the pram with a dozen errors.
lcd.h (398): Error: SYSLCDTEMP.1 is not a valid I/O pin or port
lcd.h (399): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (409): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (483): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (484): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (485): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (486): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (860): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (910): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (911): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (912): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (913): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
The message has been logged to the file Errors.txt.
I'm seriously scratching my head with this as when I try to identify where the errors are it reply's that it cannot navigate from this line, File not found, "location of the file on my PC"
The code I have thus far is and includes the header txt by Evan:
I have now manged to compile the code but needless to say it doesn't work which is no surprise. But all is not in vain as I have used the time to try out the original code from Evan with a huge 40 pin 16F1937 and an even bigger 4x20 LCD with the YwRobot LCD1602 IIC serial adaptor and my DS1307 clock module which is working like a treat.
I think I can flog on and begin to follow how these things tick to where I can eventually bring it down onto the 16F18326 and the SSD1306 GLCD Display.
One burning question which is puzzling me at the minute is to do with another LCD IIC Serial adaptor. (Fleabay item number: 201074371899) which has the PCF8574 I/O Expander device on it.
This gave me a royal run-around until I fell upon a display with YwRobot LCD1602 which eventually sparked things into life.
Back to the question, in Evan’s code the LCD address is set up in the line as :
#define LCD_I2C_Address_1 0x4E which to me is decimal 78 but I can only manual select an address from 0x21 to 0x27.
Am I right in saying that I should change the line #define LCD_I2C_Address_1 0x4E to #define LCD_I2C_Address_1 0x27?
The second question is can I use the 16F1937 with the TinyBootloader ?
.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hex address 0x27 is the 7-bit address and equates to binary 0100111 . If we add the read/write bit it becomes 01001110. This converts to 8-bit Hex Address of 0x4E. It should likely remain at 0x4E. You may want to run I2C discovery demo code to find the actual address if it does not work with 0x4E. The last devices I got used address 0x7E
I believe there is a bootloader firmware for 16F1938 but not for 16F1937. I can possibly make one for you, but it will be tomorrow.before ready.
Last edit: William Roth 2017-04-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Great Cow Basic uses the 8-bit Address for I2C Devices. There are only 16 possible addresses for the PCF8574 Chip. Check your chip as see if it is a "T" or an "AT". One of these addresses will be the correct one.
For the PCF8574T:
0x40
0x42
0x44
0x46
0x48
0x4A
0x4C
0X4E
For the PCF8574AT:
0x70
0x72
0x74
0x76
0x78
0x7A
0x7C
0x7E
Last edit: William Roth 2017-04-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am making the bootloader right now. Should be ready in a few minutes. I will post a link in your private messages to the hex file. So check your messages
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you Bill. Still trying to get MPLab IPE to look at my16F1937 to install the bootloader, being a bit of a pain but I'll get back to you as soon as I have sorted it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I assume you are using a Pickit3 since MPLABX does not support PK2. If you have previously used the PK3 GUI App, you may need to open that App, detect the chip, then in the tools "Revert to MPLAB Mode" Then close the GUI app and try IPE again.
As far as that goes, either the PK3 or Pk2 GUI apps should be able to write the hex file to the chip, Just import the hex and program.
Also you cannot have both DTR from the serial converter and PK3 connected to the MCLR Pin at the same time without a blocking diode. As always there needs to be a 10K pullup from MCLR pin to Vdd.
It is probably best to completely disconnect the USB/TTL adapter from the PIC when programming the bootloader hex via PK3.
Last edit: William Roth 2017-04-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@William sorry for not getting back to you sooner, up to my nipples in the proverbial so to speak. Never the less I have now managed to program my 16F1937 with the TbL program, replaced the picodes.ini file with one you sent but there is no connectivity between my Serial ICP module and the 16F1937 when I select the Check Device button.
Forgive my ignorance but on checking the new picodes.ini file I cannot find any mention of a 16F1937. There is a 16F1939 which is un-commented but no 16F1937, is that right?
I have double checked my Port config and Serial device against a working 16F18326 project – that works fine.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm still having a couple of issues with using the 16F1937 and the TinyBootloader. I am going to start from scratch in a day or two with a clear head and fresh thoughts.
In the meanwhile I have gone back to my original plan of using the SSD1306 GLCD and 16F18326 and the DS107 clock which is where I want to be eventually so what I have done is stripped out all of my other code down to the minimum code which I feel is needed to run a the RTC.
I know it is seeing the DS1307 on the I2C bus because if I dis the CLK or DAT lines from RTC it errors out and says i2cHW, No DS1307 – Stopped.
However all I see on the display when it is all connected up DOW, date, month, year as in the attached image. I don’t seem to be able to make it pull the data contents from the device.
I have had to rem out the line DS1307_SetHourMode(mode) as it is stopping it compiling with an error which reads Error: GCASM: Duplicate, conflicting definition for ENDIF20
I have located 4 (genuine) DS1307 chips in my junk bin on some scrap/surplus net server cards. Give me some time and I will try to set one up and see what's up with all this.
I think the first thing is to just get the DS1307 up and running with minimal code, then build on that. My setup will be:
PIC 16F1939
DS1307
Citizen 32.768KHz Crystal
16X2 I2C LCD
Software I2C
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A quick few things. I am assuming that I2C discovery is finding the device.
It is a very very quick way to confirm is to toggle the DS1307_SetSQW 0 ..turn off and off with the correct resitive connection.
I have updated DS1307.h - get the latest. I resolved the IF-ENDIF error. This is an odd error as something has caused this and I need to find the root cause. The new library is here
Thank you Evan, that include file cured my ENDIF20 error. I'm not too sure what you mean with, 'toggle the DS1307_SetSQW 0 ..turn off and off with the correct resistive connection' I can turn on and off the SQW in the code but after that I'm scratching my bonce again.
Introducing your code as above only produces as in the image attached.
@William,
That would be great Bill. but please remember that my eventual aim is to use a SSD1306 GLCD which as you have told me previously is a very different beast to a 2x16 LCD
Thank you both for your very generous input. I'm sure this little project which will interface all three devices will prove to be quite a popular project as it is moving away from a huge 40 pin Microprocessor and a conventional LCD display down to something pocket sized.
Test SSD1306, using standard demo I adapted the code to support the 16f1939. How? I set the SSD1306 to SDD1306_32.... it only used 512bytes of the buffer. It worked as expected after I updated the library as I had forget to change the buffer size for the small devices. Worked. Get latest library here. https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/glcd_SSD1306.h Note: I only had to publish this library because I want to proove the GLCD 1306 driver on Microchip.
Then, I took you code, adapted for the screen.. correct the typos - strings to variables. Works. See attached.You have a lot of work to do! I just proved it all worked.
I get the time displayed. Hours, mins and secs. Is currenly shows: 24 8 44 53 0 means 24hrs mode, 8hrs 44mins 53 secs and something I cannot remember!
I have modified a DS1307 Demo to work with PIC16F1614 which is a 14Pin Device.
The "mode" variable changed to "DSmode" due to a conflict with the 16F1614 datfile that uses "mode" as a bit name. (This needs to be fixed in the dat file.)
To eliminate any potential issues with PPS/HI2C configuration, software i2C was used.
The device test routine for SW I2C was eliminated because it did not work and did not detect a missing or non responsive Ds1307.
The code enables SQW by default. If working the DS1307 will output a 32.768KHz squarewave on SQW/OUT.
If a battery is not connected to DS1307 "Vbat" then it should be tied to ground.
This program works and should be easily adaptable to the PIC16F18326. A schematic is attached that shows all connections and necessary resistors/capactiors.
@Keith
I suggest you follow the schematic and adapt this code for your 16F18326. This will verify the operation of the DS1307. Then AFTER you get the DS1307 working begin to add in other sections of code specific to your application.
Where is this I2C Discovery program and how do I use it?
Really sorry for being such a pain but I feel I am seriously wasting everyones time through my ignorance.
Keith
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What you have looks good. First review. I would stay with this approach.
You could adapt to update a large string but that would be more complex.
😀
I have poked and prodded on with this as far as I want to go for now, so I want to move up a gear and incorporate my DS1307 RTC Module. I have gone to an enormous expense and invested in a readymade module from Fleabay again, its an I2C Tiny RTC DS1307 Real Time Clock Module with an NVR AT24C32 onboard. Which I’m hoping to cobble into my 16f18326,32 and GLC SSD1306 which is counting away the hours quite merrily in front of me.
I have not changed any of the I2C bus ports, parameters or settings from the original code which started me going and I have reviewed the i2c_DS1307_16F1937_LCD.gcb from the GCB Demo’s which looks like something I could possible graft onto (or into) my project.
I have a feeling someone is going to say just change the #chip 16F1937, 32 to #chip 16f18326,32 and it should work just fine, but my gut instinct is telling me to ask before screwing everything up, and confusing the hell out of me.
The RTC Module is on Fleabay item number: 221445347596 it has all the I2C protocol connections and a backup battery. I could post what code I have so far if you think necissary.
The GLCD ssd1306 spi works fine with arduino uno and pic18f25k22. 18f25k22 and pickit 2/3 is also ok.Just mentioning.
I would. Confirm the address on the device by using the I2c discovery routine.
Then, mega an example. .. using PPS if appropriate.
Is there a video or some help on using the I2C Discovery routine as you mention? I have found the i2c2HardwareDiscovery to Terminal_Alternative_Display_16F18855.gcb code in the Demo's directortories, Is this the right one?
Back at the bowl again, looking for a solution. I have tried grafting the settings from my working GLCD project in a hope that I could see some sort of response. Needless to say it simply throws the rattle out of the pram with a dozen errors.
makeHEX.bat
Great Cow Basic Pre-processing (v0.97.01)
Great Cow BASIC (0.97.01 2017-02-20)
Compiling R:\GC Projects\DS1307 Clock\i2c_DS1307_16F1937_LCD.gcb ...
Errors have been found:
lcd.h (398): Error: SYSLCDTEMP.1 is not a valid I/O pin or port
lcd.h (399): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (409): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (483): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (484): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (485): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (486): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (860): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (910): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (911): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (912): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
lcd.h (913): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
The message has been logged to the file Errors.txt.
I'm seriously scratching my head with this as when I try to identify where the errors are it reply's that it cannot navigate from this line, File not found, "location of the file on my PC"
The code I have thus far is and includes the header txt by Evan:
(Continued as an attachment)
Last edit: Keith 2017-04-17
The errors are caused by calling LCD routines (Print, etc) when both I2C and LCD setups are commented out.
From looking at the code, I can only assume that you are using both a GLCD and LCD where the LCD is using Software I2C and the GLCD is uing HI2C.
To solve the errors uncomment the following lines
.
Alternatively, If the LCD is not used then any liines that call LCD functions must be removed otherwise those errors will show up.
.
Next:
The code is calling InitPPS, but the initPPS sub does not exist. You must create an InitPPS sub that sets the appropriate PPS Bits.
With large programs is is generally a good idea to post the code as an attachment instead of pasting it in the post.
Last edit: William Roth 2017-04-17
I have now manged to compile the code but needless to say it doesn't work which is no surprise. But all is not in vain as I have used the time to try out the original code from Evan with a huge 40 pin 16F1937 and an even bigger 4x20 LCD with the YwRobot LCD1602 IIC serial adaptor and my DS1307 clock module which is working like a treat.
I think I can flog on and begin to follow how these things tick to where I can eventually bring it down onto the 16F18326 and the SSD1306 GLCD Display.
One burning question which is puzzling me at the minute is to do with another LCD IIC Serial adaptor. (Fleabay item number: 201074371899) which has the PCF8574 I/O Expander device on it.
This gave me a royal run-around until I fell upon a display with YwRobot LCD1602 which eventually sparked things into life.
Back to the question, in Evan’s code the LCD address is set up in the line as :
#define LCD_I2C_Address_1 0x4E which to me is decimal 78 but I can only manual select an address from 0x21 to 0x27.
Am I right in saying that I should change the line #define LCD_I2C_Address_1 0x4E to #define LCD_I2C_Address_1 0x27?
The second question is can I use the 16F1937 with the TinyBootloader ?
.
Hex address 0x27 is the 7-bit address and equates to binary 0100111 . If we add the read/write bit it becomes 01001110. This converts to 8-bit Hex Address of 0x4E. It should likely remain at 0x4E. You may want to run I2C discovery demo code to find the actual address if it does not work with 0x4E. The last devices I got used address 0x7E
I believe there is a bootloader firmware for 16F1938 but not for 16F1937. I can possibly make one for you, but it will be tomorrow.before ready.
Last edit: William Roth 2017-04-17
About the PCF8574
Great Cow Basic uses the 8-bit Address for I2C Devices. There are only 16 possible addresses for the PCF8574 Chip. Check your chip as see if it is a "T" or an "AT". One of these addresses will be the correct one.
For the PCF8574T:
0x40
0x42
0x44
0x46
0x48
0x4A
0x4C
0X4E
For the PCF8574AT:
0x70
0x72
0x74
0x76
0x78
0x7A
0x7C
0x7E
Last edit: William Roth 2017-04-18
@William, did you find time to make the bootloader 16F1938?
Hi Keith,
I am making the bootloader right now. Should be ready in a few minutes. I will post a link in your private messages to the hex file. So check your messages
Thank you Bill. Still trying to get MPLab IPE to look at my16F1937 to install the bootloader, being a bit of a pain but I'll get back to you as soon as I have sorted it.
I assume you are using a Pickit3 since MPLABX does not support PK2. If you have previously used the PK3 GUI App, you may need to open that App, detect the chip, then in the tools "Revert to MPLAB Mode" Then close the GUI app and try IPE again.
As far as that goes, either the PK3 or Pk2 GUI apps should be able to write the hex file to the chip, Just import the hex and program.
Also you cannot have both DTR from the serial converter and PK3 connected to the MCLR Pin at the same time without a blocking diode. As always there needs to be a 10K pullup from MCLR pin to Vdd.
It is probably best to completely disconnect the USB/TTL adapter from the PIC when programming the bootloader hex via PK3.
Last edit: William Roth 2017-04-20
@William sorry for not getting back to you sooner, up to my nipples in the proverbial so to speak. Never the less I have now managed to program my 16F1937 with the TbL program, replaced the picodes.ini file with one you sent but there is no connectivity between my Serial ICP module and the 16F1937 when I select the Check Device button.
Forgive my ignorance but on checking the new picodes.ini file I cannot find any mention of a 16F1937. There is a 16F1939 which is un-commented but no 16F1937, is that right?
I have double checked my Port config and Serial device against a working 16F18326 project – that works fine.
Check your messages
I'm still having a couple of issues with using the 16F1937 and the TinyBootloader. I am going to start from scratch in a day or two with a clear head and fresh thoughts.
In the meanwhile I have gone back to my original plan of using the SSD1306 GLCD and 16F18326 and the DS107 clock which is where I want to be eventually so what I have done is stripped out all of my other code down to the minimum code which I feel is needed to run a the RTC.
I know it is seeing the DS1307 on the I2C bus because if I dis the CLK or DAT lines from RTC it errors out and says i2cHW, No DS1307 – Stopped.
However all I see on the display when it is all connected up DOW, date, month, year as in the attached image. I don’t seem to be able to make it pull the data contents from the device.
I have had to rem out the line DS1307_SetHourMode(mode) as it is stopping it compiling with an error which reads Error: GCASM: Duplicate, conflicting definition for ENDIF20
Continued as an attacment text
Last edit: Keith 2017-04-24
Keith,
I have located 4 (genuine) DS1307 chips in my junk bin on some scrap/surplus net server cards. Give me some time and I will try to set one up and see what's up with all this.
I think the first thing is to just get the DS1307 up and running with minimal code, then build on that. My setup will be:
A quick few things. I am assuming that I2C discovery is finding the device.
It is a very very quick way to confirm is to toggle the DS1307_SetSQW 0 ..turn off and off with the correct resitive connection.
I have updated DS1307.h - get the latest. I resolved the IF-ENDIF error. This is an odd error as something has caused this and I need to find the root cause. The new library is here
Is printing text.... try
Thank you Evan, that include file cured my ENDIF20 error. I'm not too sure what you mean with, 'toggle the DS1307_SetSQW 0 ..turn off and off with the correct resistive connection' I can turn on and off the SQW in the code but after that I'm scratching my bonce again.
Introducing your code as above only produces as in the image attached.
@William,
That would be great Bill. but please remember that my eventual aim is to use a SSD1306 GLCD which as you have told me previously is a very different beast to a 2x16 LCD
Thank you both for your very generous input. I'm sure this little project which will interface all three devices will prove to be quite a popular project as it is moving away from a huge 40 pin Microprocessor and a conventional LCD display down to something pocket sized.
You are still printing a string no the variables - check the code in the next posting.
or, it something like..
I just used the I2C test bed. This a many i2C devices attached for the testing program.
This is the result of i2c discovery. Note devices 0x78,0x78 and 0D01 and 0xD1 they are the SDDSSD1306
Test SSD1306, using standard demo I adapted the code to support the 16f1939. How? I set the SSD1306 to SDD1306_32.... it only used 512bytes of the buffer. It worked as expected after I updated the library as I had forget to change the buffer size for the small devices. Worked. Get latest library here. https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/glcd_SSD1306.h
Note: I only had to publish this library because I want to proove the GLCD 1306 driver on Microchip.
Then, I took you code, adapted for the screen.. correct the typos - strings to variables. Works. See attached.You have a lot of work to do! I just proved it all worked.
I get the time displayed. Hours, mins and secs. Is currenly shows: 24 8 44 53 0 means 24hrs mode, 8hrs 44mins 53 secs and something I cannot remember!
Enjoy.
I have modified a DS1307 Demo to work with PIC16F1614 which is a 14Pin Device.
The "mode" variable changed to "DSmode" due to a conflict with the 16F1614 datfile that uses "mode" as a bit name. (This needs to be fixed in the dat file.)
To eliminate any potential issues with PPS/HI2C configuration, software i2C was used.
The device test routine for SW I2C was eliminated because it did not work and did not detect a missing or non responsive Ds1307.
The code enables SQW by default. If working the DS1307 will output a 32.768KHz squarewave on SQW/OUT.
If a battery is not connected to DS1307 "Vbat" then it should be tied to ground.
This program works and should be easily adaptable to the PIC16F18326. A schematic is attached that shows all connections and necessary resistors/capactiors.
@Keith
I suggest you follow the schematic and adapt this code for your 16F18326. This will verify the operation of the DS1307. Then AFTER you get the DS1307 working begin to add in other sections of code specific to your application.
Last edit: William Roth 2017-04-24
Where is this I2C Discovery program and how do I use it?
Really sorry for being such a pain but I feel I am seriously wasting everyones time through my ignorance.
Keith
:-)
See https://www.youtube.com/watch?v=swoQrq6TbU4 and the your installed demo folder for I2c Discovery