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 and Partners
    Products and Partners
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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
Community Hub
Community Hub
Member's Forum Help, Pi2 and MCP3008
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Community Hub to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 14 replies
  • Answers 2 answers
  • Subscribers 631 subscribers
  • Views 1869 views
  • Users 0 members are here
  • mcp3008
  • spi
  • analog
  • pi2
Related

Help, Pi2 and MCP3008

e14 Contributor
e14 Contributor over 10 years ago

My analog board and Pi2 are inside a well ventilated metal enclosure. The MCP3008 is not getting warm to the touch. There is a fan pushing air though the enclosure.

 

All signals look clean on the scope.

 

Vcc, and Vref are 3.3v.  All samples are within 0-3.3v.

 

I have tried all different SPI clocks form 500Khz to 3Mhz.

 

An identical board sitting on my desk has been working fine for 45 min.  Three different PI and MCP3008 inside the metal enclosure will work for about 5 min after a power cycle then the readings go nuts, before all eight channels revert to zero.

 

I will leave the working board running all night.  The AC cuts off here at about now.  So the temp in this office will go up over night to about 30c (Singapore) so I guess I will know if the temperature affects it.

 

Here is my "transfer" code:

 

//==================================================================

//Private main read/write

//==================================================================

int CMCP3008::spiWriteRead( unsigned char *data, int length)

{

  struct spi_ioc_transfer spi[length];

  int i = 0;

  int result=-1;

 

    //One spi transfer for each byte

    for(i=0;i<length;i++)

    {

      memset(&spi[i],0,sizeof(spi[i]));              //Flush

      spi[i].tx_buf        = (unsigned long)(data+i); //Transmit from "data"

      spi[i].rx_buf        = (unsigned long)(data+i); //Receive into "data"

      spi[i].len           = sizeof(*(data+i));

      spi[i].delay_usecs   = 0;

      spi[i].speed_hz      = this->speed;

      spi[i].bits_per_word = this->bitsPerWord;

      spi[i].cs_change = 0;

    }

 

    result=ioctl (this->spifd,SPI_IOC_MESSAGE(length),&spi) ;

    if(result<0) {  printf("spiWR==[%i]\n",result); return -1; }

 

  return 0; //Success

}

 

Please help

  • Sign in to reply
  • Cancel
  • e14 Contributor
    0 e14 Contributor over 10 years ago in reply to e14 Contributor

    IT WORKS!

     

    I added some op amps as voltage followers.  On the input side I set up pi filters to create a super low pass filter.( 4.7uF, 1mH, 1uF ) and a resistor to ground to discharge the 4.7uF cap.  On the output of the op amps  I used 330 ohm resistors and 1uF caps.

    The values read are dead on!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • dougw
    0 dougw over 10 years ago

    As you probably know, RPi's are notoriously picky about their power supply - even when the voltage looks good.

    Maybe try a different power supply and power cable - known to be good....

    The only other issue I've had with MCP3008's is missing a byte and getting the low and high byte confused, but this doesn't seem to be your problem.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 10 years ago

    What SPI mode are you using, is it the correct one ?

     

    See here for more info

    http://www.ti.com/lit/ug/slau411d/slau411d.pdf

    and

    https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

     

    The MCP3008 can use mode 0 or 1 and depending on what your clock is doing, it could be getting confused but this is only showing when the MCP3008 gets warm, Try setting to the other mode and see if it helps, your code does not show the mode your using.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 10 years ago in reply to shabaz

    It appears to be dropping into low power mode and staying there. 

     

    I do not understand it, because the readings are accurate to three decimal places.

     

    I will isolate the inputs. I am having the boards redone with low power op amps as voltage followers.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • shabaz
    0 shabaz over 10 years ago in reply to e14 Contributor

    If the MCP is getting into some hanged or latched state, this sounds like it could be enough to damage it eventually, a reset may just hide the issue for a while.

    You may need isolation from whatever circuit you're connected to I'm afraid.

    Just resetting a chip could be done with a MOSFET or two to control the power to it, but I don't think this is a good solution for this issue unfortunately.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 10 years ago in reply to shabaz

    Do you know of a way to "Reset" the chip?  I have tried everything and I cannot get it to work.

     

    I have probed every line, and the signals are clean.  It should not matter how far away the voltage is so long as it is between 0 and 3.3v.

     

    The chip just dies and will do nothing until the power is cycled.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 10 years ago in reply to shabaz

    Thanx for all the help.  I will check my ground loops. 

     

    I think I will set a loop up that will throw the raw value to the screen every couple hundred milliseconds, and see what it takes to cause the problem.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 10 years ago in reply to e14 Contributor

    One other thing worth trying is to log the raw SPI content that is read from the ADC, e.g. dump it to the screen or a file the contents of data in ::spiWriteRead. Just in case it is possible to spot something from there when the fault occurs inside the enclosure. You can delete the memset function call there, it is not having any useful effect (nor a negative effect).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 10 years ago in reply to e14 Contributor

    The purpose of the circuit is to monitor a power supply, and a non-rechargeable battery.  Again all the samples are low impedance.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 10 years ago in reply to e14 Contributor

    I see - it sounds like you know what you're doing with regards to the electronics side.

    The only other thing I can see is that the ::readAverage method should have

    while(cnt<6)

    instead of

    while(cnt<5)

     

    Apart from that, I can't see what else could be ocurring : (

    • 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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube