{"id":88,"date":"2010-01-09T22:30:41","date_gmt":"2010-01-09T21:30:41","guid":{"rendered":"http:\/\/blog.blockos.org\/?p=88"},"modified":"2014-09-21T17:10:00","modified_gmt":"2014-09-21T16:10:00","slug":"dataflash-of-the-two-worlds","status":"publish","type":"post","link":"https:\/\/blog.blockos.org\/?p=88","title":{"rendered":"Dataflash of the two worlds"},"content":{"rendered":"<p>I spent the whole afternoon trying to make the arduino works with 2 dataflash chips. A coupe of really stupid code mistakes and some weird stuffs later, it worked. You can now have 2 instances of ATD45DB161D class. For example one will use the pins 2, 4 and 5 for SS, RESET and WP and the other one will use pins 10,8 and 7.<br \/>\nI couldn&#8217;t make SS work with an other pin than the pin 10 until I ran across <a href=\"http:\/\/www.arduino.cc\/cgi-bin\/yabb2\/YaBB.pl?num=1227719581\">forum post<\/a>. So I have to set both the requested SS pin and pin 10 (hardwired SS pin) high before setting the SPCR register so that the atmega168 becomes master.<br \/>\nSo I moved the SPCR initialization to a new method astutely called <em>Enable<\/em>. And I added its counterpart called <em>Disable<\/em> which drives the SS pin high.<br \/>\nSo before using a given Dataflash chip, you&#8217;ll have to call <em>Enable<\/em> before using it. And call <em>Disable<\/em> when you are done with it.<\/p>\n<p><del datetime=\"2010-01-11T22:12:20+00:00\">As I&#8217;m not happy with the current design, I created a new branch for this dev.<\/del><\/p>\n<p>You can find it <strong><a href=\"http:\/\/github.com\/BlockoS\/arduino-dataflash\/tree\/configurable_pins\">[here]<\/a><\/strong>.<br \/>\nAny ideas\/suggestions for a cleaner\/safer way to handle multiple SPI device are welcome \ud83d\ude42<\/p>\n<p><a href=\"http:\/\/blog.blockos.org\/wp-content\/uploads\/2010\/01\/dataflash2.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blog.blockos.org\/wp-content\/uploads\/2010\/01\/dataflash2.png\" alt=\"\" title=\"Arduino Diecimila with 2 atmel Dataflash\" width=\"422\" height=\"270\" class=\"aligncenter size-full wp-image-87\" srcset=\"https:\/\/blog.blockos.org\/wp-content\/uploads\/2010\/01\/dataflash2.png 422w, https:\/\/blog.blockos.org\/wp-content\/uploads\/2010\/01\/dataflash2-300x191.png 300w\" sizes=\"(max-width: 422px) 100vw, 422px\" \/><\/a><\/p>\n<p><strong>[edit]<\/strong>: Arg, I should have checked Atmel site. They have an application note called <a href=\"http:\/\/www.atmel.com\/dyn\/resources\/prod_documents\/doc2585.pdf\">AVR151: Setup And Use of The SPI<\/a>.<br \/>\n<strong>[edit]<\/strong> (it&#8217;s the last one. I swear \ud83d\ude42 ) I moved the SPI master init into a new function (<em>spi_init<\/em>). It&#8217;s a little bit cleaner now. But it&#8217;ll stay in a branch until I run more tests and have some feedback.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spent the whole afternoon trying to make the arduino works with 2 dataflash chips. A coupe of really stupid code mistakes and some weird stuffs later, it worked. You can now have 2 instances of ATD45DB161D class. For example one will use the pins 2, 4 and 5 for\u2026 <a class=\"continue-reading-link\" href=\"https:\/\/blog.blockos.org\/?p=88\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,3],"tags":[26,27,10],"_links":{"self":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts\/88"}],"collection":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=88"}],"version-history":[{"count":12,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":977,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=\/wp\/v2\/posts\/88\/revisions\/977"}],"wp:attachment":[{"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.blockos.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}