Difference between revisions of "PIC32MX: I2C DAC"

From Mech
Jump to navigationJump to search
Line 12: Line 12:
While we were able to send data to the DAC, we were NOT able to elicit output from said DAC.
While we were able to send data to the DAC, we were NOT able to elicit output from said DAC.


This particular DAC, the MAX518 requires three bytes (note: 1 byte = 8 bits) of information every time it changes its output. The first byte defines the DAC as a slave, and contains the address. This byte WILL NOT change when repeatedly sending data to the DAC. The next byte is the actual data the IC should convert. The third byte is named the command byte. The bits are, in order of most significant to least significant: R2, R1, R0, RST, PD, X, X, A0. R2 = R1 = R0 =0. This is always true. The next bit, RST, will reset all registers if set to 1. Setting PD to 1 will tell the device to hibernate after it outputs the desired data. The next two bits do not matter (X = don't care). Finally, the address bit, instructing the DAC which output to send the data too.
This particular DAC, the MAX518 requires three bytes (note: 1 byte = 8 bits) of information every time it changes its output. The first byte defines the DAC as a slave, and contains the address. This byte WILL NOT change when repeatedly sending data to the DAC. The next byte is the actual data the IC should convert.

The third byte is named the command byte. The bits are, in order of most significant to least significant: R2, R1, R0, RST, PD, X, X, A0. R2 = R1 = R0 =0. This is always true. The next bit, RST, will reset all registers if set to 1. Setting PD to 1 will tell the device to hibernate after it outputs the desired data. The next two bits do not matter (X = don't care). Finally, the address bit, instructing the DAC which output to send the data too.


== Circuit ==
== Circuit ==

Revision as of 21:14, 15 February 2010

Original Assignment

Do not erase this section!

Your assignment is to interface to the MAX518 I2C digital to analog converter (DAC).

Overview

Note: PROJECT NOT FULLY FUNCTIONAL!

On this page we will present code and a wiring schematic that allows for the PIC32MX to speak to an 8-bit Digital to Analog Converter. In particular, our project used the MAX518 DAC.

While we were able to send data to the DAC, we were NOT able to elicit output from said DAC.

This particular DAC, the MAX518 requires three bytes (note: 1 byte = 8 bits) of information every time it changes its output. The first byte defines the DAC as a slave, and contains the address. This byte WILL NOT change when repeatedly sending data to the DAC. The next byte is the actual data the IC should convert.

The third byte is named the command byte. The bits are, in order of most significant to least significant: R2, R1, R0, RST, PD, X, X, A0. R2 = R1 = R0 =0. This is always true. The next bit, RST, will reset all registers if set to 1. Setting PD to 1 will tell the device to hibernate after it outputs the desired data. The next two bits do not matter (X = don't care). Finally, the address bit, instructing the DAC which output to send the data too.

Circuit

Include a schematic and give any part numbers. A photo of your circuit is OK, but not as a replacement for a schematic.

Code

Our code is separated into sections, each with sufficient comments to explain all functions Our code:

 
#include <HardwareProfile.h> 
#include <HardwareProfile_NU32.h> 
#include <plib.h> 
 
 
// Configuration Bit settings 
// SYSCLK = 80 MHz (8MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV) 
// PBCLK = 50 KHz 
// Primary Osc w/PLL (XT+,HS+,EC+PLL) 
// WDT OFF 
// Other options are don't care 
// 
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF 
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_2 
 
// DEFINES 
 
#define SYSCLK	(80000000) // set system clock to 80MHz 
#define PBCLK  (SYSCLK/1000) // set PBCLK to 80 KHz 
 
#define Fsck	50000 
#define BRG_VAL 	((PBCLK/2/Fsck)-2) 
 
#define Nop() asm( "nop" )  //allows for a pause command 
 
// a simple puase command 
void i2c_wait(unsigned int cnt) 
{ 
	while(--cnt) 
	{ 
		Nop(); 
		Nop(); 
	} 
} 
 
///////////////////////////////////////////// 
///////////////////////////////////////////// 
 
int main(void) 
 
{	 
	ODCA = 0xC000; 
	unsigned char SlaveAddress; 
	char i2cData[3]; 
	//Enable channel using default values 
	OpenI2C1( I2C_EN, BRG_VAL ); 
	SlaveAddress = 0x58; 
	i2cData[0] = ((SlaveAddress )); 
	i2cData[1] = 0x05; //command line 
	i2cData[2] = 0xFF; //end command 
 
while(1) // run the code over and over again 
{ 
 
 
 
	StartI2C1();	//Send the Start Bit (begin of data send) 
	IdleI2C1();		//Wait to complete 
	MasterWriteI2C1 (i2cData[0]); //address 
	IdleI2C1(); 
	AckI2C1(); //ask for acknowledge bit before continuing 
	MasterWriteI2C1 (i2cData[1]); //command line 
	IdleI2C1(); 
	AckI2C1(); 
	MasterWriteI2C1(i2cData[2]); //output 
	IdleI2C1(); 
	AckI2C1(); 
	StopI2C1();  //end of data send 
 
} 
}