New to Programming and really Really frustrated

Kecked

Member
I am trying to do the most simple of things.....talk to a ds1307 via I2C and read from it. I have the axe033 fitted with the clock chip I set the jumper to I2C. I can send a message to the lcd no problem..... I am using the 28x2 chip as I need 3 PWM from this. (doing the analog meter clock thing but also adding sunrise and sunset leds to meter faces)
I can't seem to write to the ds1307 or read back from it. Here is the code I was using to debug. What am I doing wrong. I spent over 20 hours on this.

Once I get the read write to the ds1307 done I got the rest. Thanks for any suggestions.

Code:
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte                          'setup ds1307
pause 100                                                                                    'wait just to make sure it is ready
hi2cout 0, ($00,$01,$02,$03,$04,$05,$06,$07)                              'send a string to adresses starting at 0 sending dtat for clock (or should it be $00. tried both ways)  also tried writeI2C command here
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte                         'Refresh setup
pause 100                                                                                    'wait again just make sure I don't introduce problems
readi2c 0, (b0,b1,b2,b3,b4,b5,b6,b7)                                              'read out the data I saved to the DS1307
 b8=b2  & $f0/16 + $30                                                                'Convert the data from BCD to ASCII 
  b9=b2  & $0f+$30
  b10=b1 & $f0/16 + $30
  b12=b1  & $0f+$30
  b13=b3 & $f0/16 + $30
  b14=b3  & $0f+$30
  b15=b6 & $f0/16 + $30
  b16=b6  & $0f+$30
  b17=b5 & $f0/16 + $30
  b18=b5  & $0f+$30
  b19=b7 & $f0/16 + $30
  b20=b7  & $0f+$30
hi2csetup i2cmaster, $C6, i2cslow, i2cbyte                  'setup the LCD (This part works fine only the variables are all garbage data)
pause 300
hi2cout 0, (254,128,255)
hi2cout 0, (b8,b9,":",b10,b11,":",b13,b14,255)
hi2csetup i2cmaster, $C6, i2cslow, i2cbyte
pause 100
hi2cout 0, (254,192,255)
hi2cout 0, (b15,b16,"/",b17,b18,"/",b19,b20,255)
 
Last edited:

russbow

Senior Member
I presume as you are writing to the clock chip, you are trying to set the time.
If so, in the program editor go to Picaxe > wizards > AX110 datalogger > DS 1307 set time.

Does it all for you
 

Technical

Technical Support
Staff member
Welcome to the forum.

Sending byte $07 at the end to the RTC is not valid data for that address. Try $10 instead.
Or try this, time date here now in the UK
hi2cout 0, ($00, $09, $16, $13, $27, $09, $12, $10)

Also don't re-issue the hi2csetup command unless you want to change the slave address.
 

Kecked

Member
reply

Welcome to the forum.

Sending byte $07 at the end to the RTC is not valid data for that address. Try $10 instead.
Or try this, time date here now in the UK
hi2cout 0, ($00, $09, $16, $13, $27, $09, $12, $10)

Also don't re-issue the hi2csetup command unless you want to change the slave address.
That helped some. Let me ask one other question. Do I have to set the i2c jumper on the lcd to use i2c on the ds1307 or can I mix it and use the serial commands for the lcd and the i2c for the ds1307. That way I don't have to keep swicthing back and forth and I have gotten a vsm version of it working like that. It seems mixing the i2c on bot hdevices is what kills me. IE leave the jumper for mode off

This works in VSM so I don't know why hardware doesn't work.
 

Technical

Technical Support
Staff member
It's one mode or the other, you can't use a mix of both. Unless of course you remove the DS1307 from the AXE033 and build your own i2c circuit separately.
 

Kecked

Member
It's one mode or the other, you can't use a mix of both. Unless of course you remove the DS1307 from the AXE033 and build your own i2c circuit separately.

Thanks that what I thought. I'll have to try again tonight. I think that control bit being $10 might fix it. Otherwise I'm going to have to do my own i2c bus but that is simple to do. Funny thing is once I have the clock running I don't need the lcd at all except to make sure the meters read right!

I truely appreciate all your support it really makes a differerence. I started in AVR C++ hell and gave up the first time I started to learn these processors. Setting all the registers and such was beyond me. This I can handle.....I hope.

I need to find a good book on data conversions. Once I realized that 16 =1111 and it masked to give upper or lower bytes from a word I got the bcd to ascii conversion. At first it looked like voodoo.

The following works in VSM. I think all I need do is convert the lcd over to i2c and this code should run but that is where I was last night......


Code:
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
hi2cout 0, ($55, $59, $23, $05, $27, $09, $12, $10)
main:
hi2cin 0, (b0,b1,b2,b3,b4,b5,b6,b7)
  b8=b2   & $f0/16 + $30
  b9=b2   & $0f+$30
  b10=b1  & $f0/16 + $30
  b11=b1  & $0f+$30
  b12=b0  & $f0/16 + $30
  b13=b0  & $0f+$30
  b14=b5  & $f0/16 + $30
  b15=b5  & $0f+$30
  b16=b4  & $f0/16 + $30
  b17=b4  & $0f+$30
  b18=b6  & $f0/16 + $30
  b19=b6  & $0f+$30
IF b3=1 then let b20=$53 Let b21=$55 Let b22=$4E
Endif
IF b3=2 then let b20=$4D Let b21=$4F Let b22=$4E
Endif
IF b3=3 then let b20=$54 Let b21=$55 Let b22=$45
Endif
IF b3=4 then let b20=$57 Let b21=$45 Let b22=$44
Endif
IF b3=5 then let b20=$54 Let b21=$48 Let b22=$55
Endif
IF b3=6 then let b20=$46 Let b21=$52 Let b22=$49
Endif
IF b3=7 then let b20=$53 Let b21=$41 Let b22=$54
Endif

serout c.1, n2400, ($FE,$80,$20,$20,$20,$20,b8,b9,":",b10,b11,":",b12,b13)

serout c.1, n2400,  ($FE,$C0,b20,b21,b22,":", b14,b15,"/",b16,b17,"/",b18,b19) 


w11=b2*57


w12=b1*11


w13=b0*11


pwmout c.0,254,w11 'hours
pwmout c.2,254,w12 'mins
pwmout b.2,254,w13 'sec
goto main
 
Last edited:

Kecked

Member
I just ordered the parts from digikey. I'm going serial display with i2c rtc. At least that I got to work VSM. Thing is after a few minutes the display corrupts. I hope that is just the simulation. I still want to degub the other method just to learn it.
 

hippy

Technical Support
Staff member
b19=b6 & $0f+$30
IF b3=1 then let b20=$53 Let b21=$55 Let b22=$4E

You can use ASCII characters inside double quotes which can make code easier to understand ...

b19=b6 & $0f+"0"
IF b3=1 then let b20="M" Let b21="O" Let b22="N"
 

westaust55

Moderator
Further to hippy's suggestion for the lines such as:
b8=b2 & $f0/16 + $30​
the /16 part is in effect shifting the upper 4 bits (a nybble) to the lower 4 bits and places zeros in the upper 4 bits. As such you only need:
b8=b2 /16 + "0"​
you still need the & $0f for each second line
b9=b2 & $0f+"0"​

and albeit may not be as program space efficient, a single BASIC program command which may be seen as more easily read/understood can replace both lines as:
BCDTOASCII b2, b8,b9​

finally: Also please place your code within [code] and [/code] tags as per the forum etiquette
 
Last edited:

John West

Senior Member
Kecked:
I truely appreciate all your support it really makes a differerence. I started in AVR C++ hell and gave up the first time I started to learn these processors. Setting all the registers and such was beyond me. This I can handle.....I hope.
You've found the best support group on the web right here, Kecked, at least as far as I'm concerned. These folks are great.
 

mrburnette

Senior Member
@Kecked:
I started in AVR C++ hell and gave up the first time I started to learn these processors.
I suspect that all of us that program in C/C++ can appreciate the frustration that you felt by "starting" in that environment. However, it is my opinion that while the BASIC dialect of the PICAXE will serve many projects (or most), you should still learn the basics of C/C++. To be polite to the Forum, I'm not suggesting any particular path for that knowledge, many courses/references exist both free or at a small cost. However, as a reference here in the Forum, I did a post a few months back on some comparisons and in this post, I used PICAXE BASIC compared to Arduino C code... obviously similar.

http://www.picaxeforum.co.uk/showthread.php?21079-PICAXE-amp-Arduino

When contemplating the code sizes, keep in mind that the PICAXE is wired with firmware that contain all of the BASIC command instructions (sans the ones that are macro expansion in the PE 'compiler') and the Arduino (sans the serial bootloader) is unburdened with any code until the environment downloads your compiled program... therefore, we are comparing apples and oranges which is kind of the theme of the article!

Every fan of PICAXE should understand the differences between the technologies utilized - not in detail, but at a high level. This knowledge allows for an intelligent conversation with fans of other systems and also allows one to be articulate on the pros-and-cons of both environments. Knowledge in and of itself is non-discriminatory.

- Ray
 

Kecked

Member
All true

@Kecked:


I suspect that all of us that program in C/C++ can appreciate the frustration that you felt by "starting" in that environment. However, it is my opinion that while the BASIC dialect of the PICAXE will serve many projects (or most), you should still learn the basics of C/C++. To be polite to the Forum, I'm not suggesting any particular path for that knowledge, many courses/references exist both free or at a small cost. However, as a reference here in the Forum, I did a post a few months back on some comparisons and in this post, I used PICAXE BASIC compared to Arduino C code... obviously similar.

http://www.picaxeforum.co.uk/showthread.php?21079-PICAXE-amp-Arduino

When contemplating the code sizes, keep in mind that the PICAXE is wired with firmware that contain all of the BASIC command instructions (sans the ones that are macro expansion in the PE 'compiler') and the Arduino (sans the serial bootloader) is unburdened with any code until the environment downloads your compiled program... therefore, we are comparing apples and oranges which is kind of the theme of the article!

Every fan of PICAXE should understand the differences between the technologies utilized - not in detail, but at a high level. This knowledge allows for an intelligent conversation with fans of other systems and also allows one to be articulate on the pros-and-cons of both environments. Knowledge in and of itself is non-discriminatory.

- Ray
I just want a success under my belt. Right now I need something positive to drive me forward. Sort of like getting that perfect drive in golf or your first home run. I tried uploading mr Lincoln's clock code as per his design and even that won't work right. As soon as I set the clock the screen goes back to trash. I am thinking I have a bad LCD board or such or the des chip is faulty. I have all new arriving this week so we will see.

Yes the new picaxe x series dir and pins port commands look a lot like avr but try setting up an adc with the div registers and all. Then you'll see why I gave up. And bit banging.....oh man.
 

mrburnette

Senior Member
<...>

Yes the new picaxe x series dir and pins port commands look a lot like avr but try setting up an adc with the div registers and all. Then you'll see why I gave up. And bit banging.....oh man.
Been there, done that! (and still do, when necessary for efficiency & speed.) But the point is that products such as PICAXE and Arduino project boards allow for a level of abstraction from the low-level stuff. I've rebuild gasoline engines, but it is not a necessary knowledge required to use a lawnmower and cut grass!

Enjoy a productive and satisfying relationship with the PICAXE... they are good technology for many projects. If you never hit the glass-ceiling, great. If you do, there are alternatives that will not put your brain into warp.

- Ray
 

Kecked

Member
I got it thanks to a clue. A member suggested that the i2c bus was resetting because of a voltage problem from the backup battery. He/she was right. I took the battery out and shorted it for a few seconds.....20 ish That dropped the volatage enough to stop the problem. The code was never an issue it seems. That should make it to the cut sheet for the device. I would have never figured that out and just thought I was a fool for trying to learn to program micros again.

I got my success....! Only took about 100 hours to get it but I'll never make that mistake again.

thanks all around for the helping hand.
 

MartinM57

Moderator
I took the battery out and shorted it for a few seconds.....20 ish That dropped the volatage enough to stop the problem. The code was never an issue it seems. That should make it to the cut sheet for the device.
I can't believe that is the standard way of making a DS1307 work (in fact it's not :)) - what battery did/do you use? It needs to be be between 2v and 4v and if you don't have a battery, the Vbat pin needs to be grounded.
 

westaust55

Moderator
The battery voltage (Vbatt) needs to be between 2.0 and 3.5 Volts

The Vcc supply voltage must be greater than 1.25 x Vbatt (better if > 1.28 x Vbatt) and within the range 4.5 Volts to 5.5 Volts
 

Kecked

Member
I used a standard cr2032 lithium battery. nothing special. I was using a breadboard with 5v out for power. I'll never makle that mistake again!
 
Top