I2C code to write the DAC MCP4725


+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2006
    Posts
    13

    Default I2C code to write the DAC MCP4725

    I am trying to control the DAC MCP4725 but my code seems not work . My code:

    sda var portb.4
    scl var portb.5

    cont var byte
    cont = %1100
    addr var byte
    addr = $60


    '=========================================
    writedac4725:

    I2CWRITE sda,scl,cont,addr,[4095] '12 bit value
    PAUSE 10 ' Wait 10ms for write to complete

    return
    '=========================================​


    The address of my board was confirmed $60 by reading the board with I2CScanner Arduino sketch
    The device control %1100 was from datasheet :


    https://ww1.microchip.com/downloads/...doc/22039d.pdf


    I would appreciate any help

    Thanks
    ACJacques

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: I2C code to write the DAC MCP4725

    The address depends on the A2, A1 that are hardcoded into the chip at manufacturing time and also on the A0 that the user controls.

    I guess you have double checked them.

    Also the control byte I think should be a constant and not a variable.

    Ioannis

  3. #3
    Join Date
    Oct 2006
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: I2C code to write the DAC MCP4725

    Richard from Support Melabs give me the solution:

    addr var byte
    addr = $C0 ;$60 <<1

    '==========================================
    writedac4725:
    I2CWRITE sda,scl,addr,[4000] '12 bit value
    PAUSE 10 ' Wait 10ms for write to complete
    return
    '=========================================

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,387


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: I2C code to write the DAC MCP4725

    Richard from Support Melabs give me the solution:
    I should point out that I'm just an enthusiastic user on that forum and this one . I do not represent Melabs in any way shape or form
    Warning I'm not a teacher

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: I2C code to write the DAC MCP4725

    Quote Originally Posted by acjacques View Post
    I2CWRITE sda,scl,addr,[4000] '12 bit value
    And that does work now?

    Ioannis

  6. #6
    Join Date
    Aug 2011
    Posts
    408


    Did you find this post helpful? Yes | No

    Default Re: I2C code to write the DAC MCP4725

    Code:
    addr var byte
    addr = $C0 ;$60 <<1
    
    writedac4725:
    I2CWRITE sda,scl,addr,[4000] '12 bit value
    PAUSE 10 ' Wait 10ms for write to complete
    That'll do a fast-mode write to the DAC register as long as the "12-bit value" is <4095, so you could remove the 'PAUSE 10'.
    If the upper control bits are '01x' then it'll possibly write to the DAC + EEPROM, depending on the actual value.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: I2C code to write the DAC MCP4725

    Isn't necessary the control byte?

    Ioannis

  8. #8
    Join Date
    Aug 2011
    Posts
    408


    Did you find this post helpful? Yes | No

    Default Re: I2C code to write the DAC MCP4725

    In fast mode (with the upper two bits 00) you only need two bytes.
    If you want to use the EEPROM function you need all three bytes.

    Of course, both modes need the address byte too.
    Last edited by tumbleweed; - 13th November 2023 at 16:44.

  9. #9
    Join Date
    Oct 2006
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: I2C code to write the DAC MCP4725

    Yes. It is working in the Fast Mode.

    valuedac= 4095

    I2CWRITE sda,scl,%11000010,[valuedac.highbyte,valuedac.lowbyte]


    The above control byte in binary is from data sheet 1100 = device code
    0010 is the board with address code set to A0 = 1 . Most default boards are factory 0000. I have tied the user A0 bit to VCC in the board.
    Control and Address are in the same first byte.

    Data sheet says that second and third bytes may be repeated (valuedac may be repeated ) like
    I2CWRITE sda,scl,%11000010,[valuedac.highbyte,valuedac.lowbyte,valuedac.highby te,valuedac.lowbyte]
    This also works but seems be not necessary.

    I will try next days to write a code for other modes.

    Data Sheet link: https://ww1.microchip.com/downloads/...doc/22039d.pdf
    Last edited by acjacques; - 14th November 2023 at 01:22.

Similar Threads

  1. PicBasic Pro code to drive MCP4291 DAC?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th July 2015, 03:28
  2. I2C Read and Write
    By DerekMacom in forum mel PIC BASIC
    Replies: 14
    Last Post: - 21st April 2008, 15:44
  3. I2C write - value too big
    By ruijc in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 6th April 2008, 13:20
  4. i2c with a dac
    By fabritio in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 29th March 2006, 17:13
  5. I2C write
    By TonyCNC in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd January 2006, 10:40

Members who have read this thread : 16

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts