Shop OBEX P1 Docs P2 Docs Learn Events
Asm I2C driver for various stuff... Do with it as you will. — Parallax Forums

Asm I2C driver for various stuff... Do with it as you will.

KyeKye Posts: 2,200
edited 2009-08-13 14:28 in Propeller 1
Hey guys,

I spent some time working on a asm I2C driver for my propeller project. But after some redesigning of the project I have decided to drop it from my plans.

So... to put the code to good use I'll be posting it on the object exchange, the driver comes with some rountines to make a RTC (DS1307)·work. It does not have any EEPROM rountines built into it however, but the driver·say it does. I just never got arround to that.

Anyway, the I2C parts of the driver allow for transmiting and receiving I2C data, making start and stop conditions, aknowledging and not aknowledging, and clock·holding...etc.

Its pretty much everything you woyuld need.·Just call the·asm functions in the main loop to make yourself a driver for any I2C device that run at high speed in the background.

Also·the driver updates at 4 times the clock speed (that being·100 khz) and the driver can be modifed by chaning·to run at 400 khz by modifying the·initialization function.

And, the RTC part is kinda flaky. I don't know if·theres is a problem in the code or· in my own setup. So don't depend on it. Only trust the I2C·functions.

Beyond that, ask if you have any questions...
·

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Comments

  • MGreimMGreim Posts: 114
    edited 2009-05-18 18:34
    Hi kye,

    i have just tested your I2C driver with a DS1338, it seems to work fine. One question:
    When do you write /red to the clock, i didn't understand your assembler code. What is triggering an acces to the I2C slave? a $FF to
    in the RTCSet array? Or is the driver writing and reading permanently ?

    Regards

    Markus
  • KyeKye Posts: 2,200
    edited 2009-05-19 13:13
    Yeah the $FF is a flag that when set causes the driver to load the RTC with the new data.

                            rdbyte  buffer,         RTCSetAddress wz ' Check for RTC Initialization.
                            mov     buffer,         #0               '    
    if_z                    add     buffer,         #7               '
    if_nz                   wrbyte  buffer,         RTCSetAddress    '
                            call    #transmitPacket                  '        
    if_z                    jmp     #RTCUpdate                       ' 
                            
                            mov     arrayBuffer,    RTCSetAddress    ' Setup for initialization. 
                            add     arrayBuffer,    #1               '
                            mov     arrayCounter,   #7               '          
    initializeRTC           rdbyte  buffer,         arrayBuffer      ' Setup time.
                            add     arrayBuffer,    #1               '
                            call    #transmitPacket                  ' Send time.
                            djnz    arrayCounter,   #initializeRTC   ' Repeat. 
    

    The code block on the top checks to see if it needs to·setup the RTC. And the code part on the bottom does that. If it doesn't need to·setup the clock that part is skipped.
    The driver reads and writes the NVRAM continuosly however. The idea behind that was that the driver would read in the values at startup and then rewrite them continuosly until shutdown. Thus any changes in the values·on the propeller chip would be instantly updated on the clock.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • MGreimMGreim Posts: 114
    edited 2009-05-22 15:35
    Hi Kye,

    thanks for your lst explanation.
    The driver is running quite wll with my RTC.
    Now i try just to expand your driver for a 2nd I2C device (its an Atmel as slave, measuring thermocouples)
    Therefore i am studying your code in more details, an i am just wondering of the fuction of the
    movs RAMUpdate , #7
    is this way of changing a jump/call address ??
    The user manual says something about self modifying code,
    but i am to stupid to understand this.
    Any hints ???

    Regards

    Markus
  • KyeKye Posts: 2,200
    edited 2009-05-22 18:56
    Um, no. The point of that is to optimize the driver after it loaded the first ram values.

    Basically, the driver loads all 64 registers from the RTC when it starts and then uses that command to make it only reload the first 7 from then on.

    So...

    ->Read registers 0 - 63.

    loop:

    ->Write registers 7 - 63.
    ->Read registers 0 - 6.

    ->GOTO loop

    And that's essentially what that does. Using the principles of code reuse however.

    I'm not changing the jmp/call address but just the immediant value in the asm instruction that code modifies.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,

    Post Edited (Kye) : 5/22/2009 7:02:23 PM GMT
  • AleAle Posts: 2,363
    edited 2009-08-12 20:05
    Kye:

    Very interesting driver. I'll have to modify it a bit to better suit my needs but this is a super head start. Thanks !!!

    I wish this DS1307 had a seconds counter, just seconds since Jan 1st 1970 lol.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • Agent420Agent420 Posts: 439
    edited 2009-08-12 20:16
    Ale said...
    I wish this DS1307 had a seconds counter, just seconds since Jan 1st 1970 lol.gif
    OT - I've used the DS1307 in the past... pretty sure it has a std seconds register + configuriable 1 pps out that can be used as an interrupt.

    edit - just checked the datasheet, register 00 is seconds 0-59
  • KyeKye Posts: 2,200
    edited 2009-08-13 04:05
    Your welcome.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • AleAle Posts: 2,363
    edited 2009-08-13 05:15
    Agent:

    I just want a seconds counter from 0 to 2^32-1. No days, no hours, no months, it does not have that :-(

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit some of my articles at Propeller Wiki:
    MATH on the propeller propeller.wikispaces.com/MATH
    pPropQL: propeller.wikispaces.com/pPropQL
    pPropQL020: propeller.wikispaces.com/pPropQL020
    OMU for the pPropQL/020 propeller.wikispaces.com/OMU
  • KyeKye Posts: 2,200
    edited 2009-08-13 14:28
    There are other RTC's that have that feature.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
Sign In or Register to comment.