<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="it">
	<id>https://www.raspibo.org/wiki/index.php?action=history&amp;feed=atom&amp;title=MCP3204_Read_analog_data_using_SPI</id>
	<title>MCP3204 Read analog data using SPI - Cronologia</title>
	<link rel="self" type="application/atom+xml" href="https://www.raspibo.org/wiki/index.php?action=history&amp;feed=atom&amp;title=MCP3204_Read_analog_data_using_SPI"/>
	<link rel="alternate" type="text/html" href="https://www.raspibo.org/wiki/index.php?title=MCP3204_Read_analog_data_using_SPI&amp;action=history"/>
	<updated>2026-05-07T05:45:32Z</updated>
	<subtitle>Cronologia della pagina su questo sito</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://www.raspibo.org/wiki/index.php?title=MCP3204_Read_analog_data_using_SPI&amp;diff=6603&amp;oldid=prev</id>
		<title>Cecchi: Aggiunto esperimento con MCP3204 Analog to Digital Converter</title>
		<link rel="alternate" type="text/html" href="https://www.raspibo.org/wiki/index.php?title=MCP3204_Read_analog_data_using_SPI&amp;diff=6603&amp;oldid=prev"/>
		<updated>2018-04-13T08:06:59Z</updated>

		<summary type="html">&lt;p&gt;Aggiunto esperimento con MCP3204 Analog to Digital Converter&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nuova pagina&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This experiment shows how to communicate between an Arduino (Nano in this case) and a MCP3204 using SPI.&lt;br /&gt;
&lt;br /&gt;
The MCP3204 is a 4-Channel 12-Bit A/D Converters with SPI Serial Interface. Device information here: http://ww1.microchip.com/downloads/en/DeviceDoc/21298e.pdf.&lt;br /&gt;
&lt;br /&gt;
You can find the SPI library reference here: https://www.arduino.cc/en/Reference/SPI&lt;br /&gt;
&lt;br /&gt;
Arduino Nano specialized pins functions for SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK).&lt;br /&gt;
&lt;br /&gt;
We connected the Arduino Nano to work as master.&lt;br /&gt;
&lt;br /&gt;
[[File:MCP3204_Arduino.png|400px]]&lt;br /&gt;
(&amp;quot;this image was created with Fritzing&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The source code of the Arduino's sketch is:&lt;br /&gt;
&amp;lt;source lang='C'&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/* Analog to Digital Converter */&lt;br /&gt;
&lt;br /&gt;
/* Input: Analog signal to CH0 of the MCP3204&lt;br /&gt;
 * Output: Serial print&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include  &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
//2 byte to store 12 bits&lt;br /&gt;
byte byte0; //highbyte for bit11-8&lt;br /&gt;
byte byte1; //lowbyte for bit7-0&lt;br /&gt;
&lt;br /&gt;
int cs=10; //chipselect&lt;br /&gt;
&lt;br /&gt;
void setup(){&lt;br /&gt;
  pinMode(cs, OUTPUT);&lt;br /&gt;
  digitalWrite(cs, HIGH);&lt;br /&gt;
  SPI.begin();&lt;br /&gt;
  SPI.setBitOrder(MSBFIRST); //MSB goes first out&lt;br /&gt;
  SPI.setClockDivider(SPI_CLOCK_DIV16); //1Mhz SPI clock&lt;br /&gt;
  Serial.begin(9600);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop(){&lt;br /&gt;
  digitalWrite(cs, LOW);&lt;br /&gt;
  SPI.transfer(0x18); //0b0000011000 configuration bits: five 0's, startbit, sind/diff, D2,D1,D0(in this case channel 0)&lt;br /&gt;
  byte0=SPI.transfer(0x00); //transfer something to request data (synchronous communication)&lt;br /&gt;
  byte1=SPI.transfer(0x00); //transfer something to request data (synchronous communication)&lt;br /&gt;
  digitalWrite(cs, HIGH);&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
  uint16_t myword;&lt;br /&gt;
  myword = ( byte0 &amp;lt;&amp;lt; 8 | byte1 ) &amp;amp; 0b111111111111; //cast to keep only our 12 bits&lt;br /&gt;
  Serial.print(&amp;quot;merged word:&amp;quot;);&lt;br /&gt;
  Serial.println(myword, DEC);&lt;br /&gt;
&lt;br /&gt;
  delay(1000);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cecchi</name></author>
	</entry>
</feed>