element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Embedded Forum using a pic to communicate with the DS1803 via I2C
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 6 replies
  • Subscribers 461 subscribers
  • Views 532 views
  • Users 0 members are here
  • i2c
  • ds1803
  • digital_volume
Related

using a pic to communicate with the DS1803 via I2C

JohnDSiviter
JohnDSiviter over 14 years ago

unsigned char I2C_DS1803_SendByte(signed char myVolume)//char myByte)
{

  StartI2C(); //sends start bits
      PORTD =WriteI2C(0b01010000);// 0101 + address
      AckI2C(); 
      result =WriteI2C(0b10101111); // command: write to both potentiometers
      result =WriteI2C(myVolume);
      AckI2C();
   return ReadI2C();
  StopI2C();
}

 

The above code is not working, anyone know why?

  • Sign in to reply
  • Cancel
  • firatkocak
    0 firatkocak over 14 years ago

    Hi,

     

    I don't know which compiler you use but if ACK is needed after each write command then you miss one between those lines below,

     

    result =WriteI2C(0b10101111); // command: write to both potentiometers
    result =WriteI2C(myVolume);

     

    And, this is a Send_Byte function but you use a Read command in it which makes no sense to me. And you use RETURN parameter with this Read command which causes STOPI2C command never runs.

     

    iIf you were using Mikroelektonika C compiler my code would be like below

     

    unsigned char I2C_DS1803_SendByte(signed char myVolume)//char myByte)
    {

          I2c_Start(); //sends start bits
          I2c_Wr( 0b01010000 );// 0101 + address
          I2c_Wr(0b10101111); // command: write to both potentiometers
          I2c_Wr(myVolume);

          I2c_Stop();

    }

     

     

    Firat

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • JohnDSiviter
    0 JohnDSiviter over 14 years ago in reply to firatkocak

    Hi Firat,

    The reason I used a read in there was so I could then return the value now reflected on the potentiometer to PORTD in the main program (Connected to LEDs), so I wouldnt have to be measuring the resistance on the DS1803E-010DS1803E-010 all the time.

    I did wonder if the program would ever reach I2C_stop(), but I couldn't stop it before reading the value, now that you have confirmed my first thoughts I will remove it, thanks.(Edit: yes I know I could have: read->store value->Stop_I2C->return value, but i rushed this code).

    Its quite difficult obtaining documentation, I havent found anything showing what the I2C_Start does for instance, just says it initialises start conditions (just the start bit?), then I read in the DS1803E-010DS1803E-010 datasheet that upon being addressed the DS1803 acqknowledges once the Master sends a SCK, but I dont know if the I2C_Write() is integrating that already into the code behind the scenes. This is possibly a bottleneck of C compilers, with regards to speedy development, knowing exactly what is used within the functions. I think the only way I am going to resolve this is by dissasembling the thing.

    John.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • firatkocak
    0 firatkocak over 14 years ago in reply to JohnDSiviter

    Hi John,

     

    If you use a Read command before a Write command finishes then you cause to fail the Write command process. So, don't use it. John, if a code is written by concerning the protocol specifications, then you don't worry about if there is something missed in the ready-functions. I downloaded the DS1308 datasheet but i could not se any Read command. So the device only accepts WRITE command. So the code sample i have given you should simply work. You can read the pot value with a multimeter to check whether it writes the correct value to the digital pot or not.

     

    Firat

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 14 years ago in reply to firatkocak

    Hi FIRAT:

     

    From the DS1803E-010DS1803E-010 datasheet:

     

    ________________________________________________

    Reading the DS1803E-010DS1803E-010
    As shown in Figure 4, the DS1803E-010DS1803E-010 provides one read command operation. This operation allows the user
    to read both potentiometers. Specifically, the R/W bit of the control byte is set equal to a 1 for a read
    operation. Communication to read the DS1803E-010DS1803E-010 begins with a START condition which is issued by the
    master device. The control byte from the master device will follow the START condition. Once the
    control byte has been received by the DS1803E-010DS1803E-010, the part will respond with an ACKNOWLEDGE. The
    R/W bit of the control byte as stated should be set equal to ‘1’ for reading the DS1803E-010DS1803E-010.
    When the master has received the ACKNOWLEDGE from the DS1803E-010DS1803E-010, the master can then begin to
    receive potentiometer wiper data. The value of the potentiometer-0 wiper position will be the first
    returned from the DS1803E-010DS1803E-010. Once the eight bits of the potentiometer-0 wiper position has been transmitted,
    the master will need to issue an ACKNOWLEDGE, unless it is the only byte to be read, in which case the
    master issues a NOT ACKNOWLEDGE. If desired the master may stop the communication transfer at
    this point by issuing the STOP condition. However, if the value of the potentiometer-1 wiper position
    value is needed, communication transfer can continue by clocking the remaining eight bits of the
    potentiometer-1 value, followed by an NOT ACKNOWLEDGE. Final communication transfer is
    terminated by issuing the STOP command.

    __________________________________________________________

     

    Maybe you have the wrong datasheet.

     

    Iñigo.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • firatkocak
    0 firatkocak over 14 years ago in reply to Former Member

    Oh, yes. My mistake, you right Iñigo. Thanks for the information. I had kept my eyes on the Table 1 of 2-Wire commands. but documentation speaks itself.

     

    Thanks, again

     

    Firat

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • JohnDSiviter
    0 JohnDSiviter over 14 years ago in reply to firatkocak

    Thanks all that replied, I have tried it with Acks and without and still cannot get it working, I am going to build the full circuit this time and use a new DS1803E-010DS1803E-010, I fear the reason for it failing could be due to static.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube