Searching \ for '[PIC]:I2C DAC test' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/i2cs.htm?key=i2c
Search entire site for: 'I2C DAC test'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:I2C DAC test'
2004\03\17@165030 by Nicholas

picon face
I am trying to test my I2C DAC using the following PIC C language. But there
is no output at all when i used the digital multimeter to test it. The
microcntroller board has went though the functional test.

Is the following sorce code logic flow right? To output a high at the DAC
output pin.

Thank you,
Nicholas

#include<p18f452.h>
#include<i2c.h>

//function prototype
void MAX517(unsigned int channel);

void main(void){

   char data_DAC;

   //init condition
   TRISC = 0X1A;    //Set SDA & SCL as 1. Activate I2C port

   OpenI2C(MASTER, SLEW_ON);    //Initialize I2C module
   SSPADD = 9;    //400KHz Baud clock (9) @16MHz

   while(1){    //Start condition
       data_DAC = 0xFF;
       MAX517(data_DAC);    //Write data to I2C DAC
       }//end of while
}//end of main

void MAX517(unsigned int channel){
StartI2C();                 //Start condition
WriteI2C(0x58);        //Address byte of DAC
AckI2C();                 //Ack
WriteI2C(0x00);       //Command byte
AckI2C();                //Ack
WriteI2C(channel);  //Output Data
AckI2C();               //Ack
StopI2C();             //Stop condition
}//end of MAX517 funtion

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\03\17@170653 by Ken Pergola

flavicon
face
Nicholas wrote:


> I am trying to test my I2C DAC using the following PIC C
> language. But there
> is no output at all when i used the digital multimeter to test it. The
> microcntroller board has went though the functional test.
>
> Is the following sorce code logic flow right? To output a high at the DAC
> output pin.


Hi Nicholas,

I see you are using the 'divide and conquer' approach -- this is good.

I still think you should provide some more details:

Nicholas, could you answer the following questions for starters?:

1) What is the value you are using for the pull-up resistors on the I2C bus?

2) What is the voltage of the voltage reference?

3) Or if you are not using one, does the MAX ADC chip have a built-in
reference?
  I don't have the data sheet handy

4) What PICmicro are you using?

5) What does the digital multimeters say the voltage is WRTG (with respect
to ground)?
  In other words, what voltage are you expecting and what are you actually
measuring?

6) Could you show us the source code of all the C functions you are using
but are not showing the source code to?



Best regards,

Ken Pergola

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\03\17@183557 by Nicholas

picon face
Hi Ken,

Thanks for replying, I'm really in need of some suggestions.
Heres my component I'm using:
Microcontroller - Microchip PIC18F452
Digital to Angloue convertor - Max 517

> 1) What is the value you are using for the pull-up resistors on the I2C
bus?
The specification for the MAX DAC suggested that for 400KHz used pullup
resistor value of 2Kohm. So that the value i'm using.

> 2) What is the voltage of the voltage reference?
I need an output voltage of 0.22V to supply to the audio amplifier.
Therefore I tied the pin 5 (ref0) of DAC to a voltage divider(10Kohm to
source and 470ohnm to ground). Therefore the voltage reference to the DAC is
0.22V

> 3) Or if you are not using one, does the MAX ADC chip have a built-in
reference?  I don't have the data sheet handy
http://pdfserv.maxim-ic.com/en/ds/MAX517-MAX519.pdf

> 4) What PICmicro are you using?
I'm using Microcontroller - Microchip PIC18F452
http://www.microchip.com/download/lit/pline/picmicro/families/18fxx2/39564b.pdf

> 5) What does the digital multimeters say the voltage is WRTG (with respect
to ground)?
There is no value at DAC output (0V) But when I measure the DAC source and
wrt ground, there is a supply of 5V.

> In other words, what voltage are you expecting and what are you actually
measuring?
I am testing the DAC at the present moment to see where my DAC is it working
with my PIC18F452. Therefore I tried to send a high (0xff) to the DAC using
PIC-C language. I should expect some voltage at the output instead of 0V
right?

> 6) Could you show us the source code of all the C functions you are using
but are not showing the source code to?
http://www.microchip.com/download/tools/picmicro/code/mplab18/51297b.pdf

2.4 I2CT FUNCTIONS
2.4.1 Function Descriptions
Function Description
AckI2C    -    Generate I2C bus Acknowledge condition.
CloseI2C    -    Disable the SSP module.
DataRdyI2C    -    Is the data available in the I2C buffer?
getcI2C    -     Read a single byte from the I2C bus.
getsI2C    -    Read a string from the I2C bus operating in master I2C mode.
IdleI2C    -    Loop until I2C bus is idle.
NotAckI2C    -     Generate I2C bus Not Acknowledge condition.
OpenI2C    -     Configure the SSP module.
putcI2C    -     Write a single byte to the I2C bus.
putsI2C    -     Write a string to the I2C bus operating in either Master or
Slave mode.
ReadI2C    -     Read a single byte from the I2C bus.
RestartI2C    -     Generate an I2C bus Restart condition.
StartI2C    -     Generate an I2C bus START condition.
StopI2C    -     Generate an I2C bus STOP condition.
WriteI2C    -     Write a single byte to the I2C bus.

Here is my source code:
#include<p18f452.h>
#include<i2c.h>

//function prototype
void MAX517(unsigned int channel);

void main(void){

   char data_DAC;

   //init condition
   TRISC = 0X1A;    //Set SDA & SCL as 1. Activate I2C port

   OpenI2C(MASTER, SLEW_ON);    //Initialize I2C module
   SSPADD = 9;    //400KHz Baud clock (9) @16MHz

   while(1){    //Start condition
       data_DAC = 0xFF;
       MAX517(data_DAC);    //Write data to I2C DAC
       }//end of while
}//end of main

void MAX517(unsigned int channel){
StartI2C();                 //Start condition
WriteI2C(0x58);        //Address byte of DAC
AckI2C();                 //Ack
WriteI2C(0x00);       //Command byte
AckI2C();                //Ack
WriteI2C(channel);  //Output Data
AckI2C();               //Ack
StopI2C();             //Stop condition
}//end of MAX517 funtion

Nicholas


{Original Message removed}

2004\03\17@224552 by Rafael Fraga

flavicon
face
Hi,
You are using AckI2C calls. I suppose you are trying to wait for the
acknowledge bit, but the micro does the job for you.
This function is intended to *generate* an ack bit, not wait for it.
Replace this functions with IdleI2C(), to make it wait until the bits are
sent.
This code will give you a staircase voltage in DAC0, at least in a MAX518.
The difference between the chips is minimal.
Rafael


#include "p18f252.h"
#include "i2c.h"


#define strobe LATCbits.LATC2
unsigned char contador;
unsigned char loop1;
unsigned char loop2;
unsigned char loop3;


void main(void)
{
TRISCbits.TRISC2 = 0;

TRISCbits.TRISC3 = 1;
TRISCbits.TRISC4 = 1;

contador=0xAA;
SSPADD = 0xFF;
OpenI2C(MASTER, SLEW_OFF);// Initialize I2C module

while(1)
{

strobe=1;
while( loop1<250 )
loop1++;
strobe=0;

while( loop1<250 )
loop1++;
while( loop1<250 )
loop1++;
while( loop1<250 )
loop1++;

// genera la condicion de start     (send start)
StartI2C();

// envia direccion                        (send chip address)
IdleI2C();
WriteI2C( 0x5E );

// envia comando                        (send command)
IdleI2C();
WriteI2C( 0x0 );

// envia datos                                (send data)
IdleI2C();
WriteI2C(contador);

// genera la condicion de stop            (send stop)
IdleI2C();
StopI2C();
IdleI2C();

 // espera un tiempo                     (wait)
loop1=0;
while( loop1<5 )
{
loop2=0;
while( loop2<2 )
 {
 loop2++;
 }
loop1++;
}


contador++;
if (contador>254)
contador=0;

}
}



<snip>

{Quote hidden}

<snip>

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\03\17@230501 by Ken Pergola

flavicon
face
Hi Nicholas,

Now wonder you are having problems -- see what happens when you provide
extra details?

When I first looked at your code, I thought it was written by you. I thought
your reference to the function 'AckI2C()' was a check for slave acknowledge,
but now that I know you are using the C18 compiler, the 'AckI2C()' is a
function that generates a MASTER ACK which is what you do not want. It looks
like the WriteI2C() function automatically checks for a slave ACK.


Therefore, try this (remove all 'AckI2C()' from your DAC code):
I changed the int you were using to unsigned char, and made some other
changes.



void MAX517( unsigned char DataByte,
             unsigned char I2C_Address )
{
     I2C_Address &= 0xFE;   // Coerce address byte to WRITE mode

     StartI2C();            // Start condition

     WriteI2C(I2C_Address); // Address byte of DAC

     WriteI2C(0x00);        // Command byte

     WriteI2C(DataByte);    // Output Data

     StopI2C();             // Stop condition
}


Let us know if this works. You might also want to process the function
return code of the WriteI2C() function, but for now just try to get the DAC
working.

Also, I would recommend a stiffer voltage reference versus the resistive
voltage divider Vref that you are currently using.
If you need help selecting a voltage reference just come on back with some
questions. If you are breadboarding, you can easily find them in a TO-93
package.

Best regards,

Ken Pergola

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\03\18@181653 by Nicholas

picon face
Hi Ken,

I tried it out today in my lab using the source code you provided, though
there is still no output but i can step though the program from from the
program memory using the MPLAB.

I wonder is it my hardware connection is wrong.
This is my connection:
Pin 1 - output of DAC
Pin 2, 5, 6 - Ground
Pin 3 - SCL (2k pullup resistor)
Pin 4 - SDA (2k pullup resistor)
Pin 7 - 5V
Pin 8 - No connection

I still couldn't get any voltage at the Pin 1. What could be the problem?
This is the source code after I implement.
I will try again tomorrow.

#include<p18f452.h>
#include<i2c.h>

//function prototype
void MAX517(unsigned char data_DAC, unsigned char I2C_Address);

void main(void){

char data_DAC;
char I2C_Address;

//init condition
TRISC = 0X1A; //Set SDA & SCL as 1. Activate I2C port

OpenI2C(MASTER, SLEW_ON); //Initialize I2C module
SSPADD = 9;     //400KHz Baud clock (9) @16MHz

while(1){ //Start condition

  data_DAC = 0xFF;
  MAX517(data_DAC, I2C_Address);     //Write data to I2C DAC
  }//end of while

}//end of main

void MAX517( unsigned char data_DAC, unsigned char I2C_Address )
{
     I2C_Address &= 0x58;   // Coerce address byte to WRITE mode

     StartI2C();            // Start condition

     WriteI2C(I2C_Address); // Address byte of DAC

     WriteI2C(0x00);        // Command byte

     WriteI2C(data_DAC);    // Output Data

     StopI2C();             // Stop condition
}


{Original Message removed}

2004\03\18@192119 by Ken Pergola

flavicon
face
Hi Nicholas,

Nicholas you definitely want to initialize 'I2C_Address' otherwise your code
will not work:

Try this:

    char I2C_Address = 0x58;

Instead of:
    char I2C_Address;



The actual 7-bit slave device address for the way you wired the MAX517 (with
pins AD1, AD0 grounded) is 0x2C.
But when the slave address is coerced into the 8-bit 'I2C_Address' because
of the R/W bit, it becomes 0x58.
So you did your homework well and came up with 0x58. :)

Nicholas, I think your best course of action is to test the function return
code of the 'WriteI2C()' function like I mentioned in my last post. This
will provide you with some useful information. You should really test and
act upon the function return code in future code, but for now, just test the
return value to see what you get.

I've always written my own I2C routines in HI-TECH PICC, PICC-18, and
PICC-Lite. I have never used the Microchip C18 compiler.
You main goal is to see if your slave ACKs your control byte correctly -- I
would imagine that this status is reflected in 'WriteI2C()' funtion code
status.

Nicholas, in your pinout you said 'Pin 8 - No connection' -- this is where
you want to feed your voltage reference.
Isn't this the pin you said yesterday you connected to a voltage divider?
I'm confused now. You definitely do not want that pin as a NO CONNECT since
that's you voltage reference input. You could tie that pin to Vdd for now.
Then if you sent 0x7F to the DAC (output byte) you would expect
approximately Vdd/2 on your DAC output pin.

I'm about a day away from a Master I2C/SMBus Engine (MISE) release that
could validate your project I2C hardware in a few minutes.
The MISE utility give you interactive feedback on your I2C transactions so
that you'll know if the START condition worked, if the control byte was
ACKed by the slave, etc.


I'm assuming that the MAX517 does not have a half-buffered output (some DACs
like the TLC5620 do) -- just check the data sheet to make sure.


Make that change I mentioned above and please report back.

Good luck.

Ken Pergola

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\03\18@194154 by Nicholas

picon face
Hi Ken,

> The actual 7-bit slave device address for the way you wired the MAX517
(with
> pins AD1, AD0 grounded) is 0x2C.
> But when the slave address is coerced into the 8-bit 'I2C_Address' because
> of the R/W bit, it becomes 0x58.
> So you did your homework well and came up with 0x58. :)

Hahaha, thank for praising me. It my first time doing such project, really
got alot of thing to learn. But programming C  language really a challenge
for myself.

> Nicholas, I think your best course of action is to test the function
return
> code of the 'WriteI2C()' function like I mentioned in my last post. This
> will provide you with some useful information. You should really test and
> act upon the function return code in future code, but for now, just test
the
> return value to see what you get.

Yup, sure. But i got to get my DAC working first. Now I got to double up my
effort, deadline for the project in end april. Opppsss... But really enjoy
doing it, so much thing to learn...

> Nicholas, in your pinout you said 'Pin 8 - No connection' -- this is where
> you want to feed your voltage reference.
> Isn't this the pin you said yesterday you connected to a voltage divider?
> I'm confused now. You definitely do not want that pin as a NO CONNECT
since
> that's you voltage reference input. You could tie that pin to Vdd for now.
> Then if you sent 0x7F to the DAC (output byte) you would expect
> approximately Vdd/2 on your DAC output pin.

Oh, yup that the pin that will be conencted to the voltage divider. but
today i did not connect anything to it. cos i just wanna to make sure that
my DAC is working. Maybe tomorrow i will tied it to Vdd.

> I'm about a day away from a Master I2C/SMBus Engine (MISE) release that
> could validate your project I2C hardware in a few minutes.
> The MISE utility give you interactive feedback on your I2C transactions so
> that you'll know if the START condition worked, if the control byte was
> ACKed by the slave, etc.

Sure, i will want to have it too. See whether my I2C really working. I2C
device really simplify the hardware connection. I love it. hahaha...

> I'm assuming that the MAX517 does not have a half-buffered output (some
DACs
> like the TLC5620 do) -- just check the data sheet to make sure.

Errr... I got to check it out.

Thank Ken. I will try again tomorrow in my lab. Will feedback to you again.

Nicholas


{Original Message removed}

2004\03\18@195025 by Nicholas

picon face
Hey Ken,

So sorry, by the way, what is this pointer used for? I dun quite understand?
Can advise me?

I2C_Address &= 0x58;

Is this the right way of writing it?

void MAX517( unsigned char data_DAC, unsigned char I2C_Address )
{
I2C_Address &= 0x58;   // Source address byte to WRITE mode

StartI2C();            // Start condition

WriteI2C(I2C_Address); // Address byte of DAC

WriteI2C(0x00);        // Command byte

WriteI2C(data_DAC);    // Output Data

StopI2C();             // Stop condition
}

Nicholas

{Original Message removed}

2004\03\18@202139 by Ken Pergola

flavicon
face
Nicholas wrote:


Sorry for not explaining that.

By adding the 'I2C_Address' parameter to your MAX517 function, I made it
more universal versus the way you coded it. Your code was not bad at all,
I'm just showing you a different perspective, that's all.

In other words, you had hard-coded the I2C address so that only a MAX517
with a slave device address of 0x2C would work.
By having your MAX517 function accept an 'I2C_Address' argument, I'm showing
you how you can accommodate up to 4 MAX517 devices on the I2C bus with one
function if you ever need future expansion.

Be careful Nicholas, you did not use my exact example that I posted
yesterday. Somehow you changed my code. You need to add my original code
back in.

My original reference was:

    I2C_Address &= 0xFE;   // Coerce address byte to WRITE mode


The reference to 'I2C_Address &= 0xFE;' should have been written more
clearly as:

 I2C_Address = ( I2C_Address & 0xFE );

Both do the same thing -- just short-hand versus long-hand.

The '&' is the bitwise AND operator. What this is doing is forcing your R/W
bit (bit 0) of your I2C address to be 0 without affecting the other 7 bits.
In this case, it is just defensive programming since you could have passed
in 0x59 (R/W bit = 1 = read) (correct 7-bit device address but incorrect
8-bit I2C address).

Nicholas, I think you are doing great so far -- keep up the good work and do
not give up. You'll be posting soon sharing your success with us.


Best regards,

Ken Pergola

P.S. Don't forget to make that change: I2C_Address = ( I2C_Address & 0xFE );

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\03\18@203255 by Nicholas

picon face
Thank Ken. Let you know the outcome tomorrow. I'm getting excited in this
project. Hahaha...

Thank for the encourgement.

Nicholas

{Original Message removed}

2004\03\19@042052 by Alan B. Pearce

face picon face
>I still couldn't get any voltage at the Pin 1. What could be the problem?

Are you sure the DAC will operate correctly with the very low reference
voltage you quoted previously (0.22V IIRC)?

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2004\03\19@182053 by Nicholas

picon face
Hi Ken,

There is still not output from the DAC. I am suspecting that I may initial
the TRISC incorrectly. What do you think might be the problem?
I have tied the Vref (pin8) to high, just wanna see whether is ther any
voltage in the output.
I have double check my hardware connection and it seem alright. Please
advise me?

Thanks,
Nicholas

#include<p18f452.h>
#include<i2c.h>

//function prototype
void MAX517(unsigned char data_DAC, unsigned char DAC_Address);

void main(void){
   char data_DAC;
   char DAC_Address = 0x58;

   //init condition
   TRISC = 0X1A;     //Set SDA & SCL as 1. Activate I2C port
   OpenI2C(MASTER, SLEW_ON);     //Initialize I2C module
   SSPADD = 9;     //400KHz Baud clock (9) @16MHz

   while(1){ //Start condition
       data_DAC = 0x7F;
       MAX517(data_DAC, DAC_Address);     //Write data to I2C DAC
       }//end of while
   }//end of main

//DAC function
void MAX517(unsigned char data_DAC, unsigned char DAC_Address)
{
   DAC_Address = (DAC_Address & 0xFE);     // Coerce address byte to WRITE
mode
   StartI2C();     // Start condition
   WriteI2C(DAC_Address);     // Address byte of DAC
   WriteI2C(0x00);     // Command byte
   WriteI2C(data_DAC);     // Output Data
   StopI2C();     // Stop condition
}

{Original Message removed}

2004\03\19@185001 by Ken Pergola

flavicon
face
Hi Nicholas,

Let's go back to square one and let me ask some basic questions:

Forgetting about the DAC right now:

1) Can you toggle an I/O line on the PIC just to make sure you know the PIC
is actually operating?
2) What are your configuration bit settings for the PIC18F452?
3) Do you have a schematic of the whole project as it stands right now to
post?

How about (for right now) not writing to the DAC in an endless loop, do this
instead:
(just trying to simplify things)



    data_DAC = 0x7F;
    MAX517(data_DAC, DAC_Address);     //Write data to I2C DAC

    while(1)
    {
         ;  // Make sure you clear the WDT here if you have it enabled
    }


Nicholas, let me grab a bite to eat and I'll study your message in more
detail. I'll be back.

If you know for sure the PIC is alive and properly executing code, then you
really need to check that I2C function's return code -- maybe you can send
it out the serial port or something.

I know you said you want to get the DAC working first, but inspecting the
return code of the WriteI2C() function is part of the process in getting
your DAC working.


On another note Nicholas, do you have a spare PIC16F877 or PIC16F877A in the
lab?
The reason I'm asking is that I released that I2C tool today and it would
let you prove out your circuit in a jiffy.
Then, you could determine if your hardware is working or not (divide and
conquer).

If you could answer the above three questions that would be great.


Best regards and please don't get discouraged,

Ken Pergola

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2004\03\19@194228 by Ken Pergola

flavicon
face
Hi Nicholas,

Another question: is your clock or crystal driving the PIC really 16 MHz as
your comments indicate?
I realize that your comment says 16 MHz, but the reason I'm asking, is
sometimes code comments do not always reflect actual hardware details --
especially if the hardware is in a state of flux.

In order to operate according to the PIC18F452's I2C engine spec, the
PIC18F452's Fosc must be 10 MHz minimum to operate at an I2C SCL frequency
of 400 KHz. If you do have a 16 MHz clock or crystal, then you're golden. :)

The other thing Nicholas:

Can you supply the actual C source code behind those C18 functions? I hate
not being able to see what's behind the scenes.
I'm tempted to say you might need to use the IdleI2C() function between your
I2C events, but I have never used the C18 compiler or its I2C function
library. Maybe those C18 I2C functions embed use the IdleI2C() within
them -- I don't know. There does not seem to be much documentation in the
PDF link you listed regarding the I2C functions so I share your pain.


If you could the questions I posed here (and from my previous post) that
would be great.


Best regards,

Ken Pergola

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2004\03\19@202535 by Nicholas

picon face
Hi ken,

I had just send a document file to your email address at localnet.com. I
hope it explain better. Thank for helping.

Nicholas

{Original Message removed}

2004\03\19@211344 by Nicholas

picon face
Hi Ken,

The frequency of the PIC18F452 is 40MHz. It is fast enough to drive the I2C
devices which is 400KHz. But I may need to have a Timer routine eventually
to clock my wave file at a smapling rate of 8KHz. But this is the later part
of the project. Now the critical part is to make the DAC function. So I
believed that the microcontroller will be fast enough for the I2C devices.

The C18 source code is very limited for I2C. Here the site to see:
MPLAB. C18 C Compiler Libraries
http://www.microchip.com/download/tools/picmicro/code/mplab18/51297b.pdf

MPLAB. C18 C Compiler User's Guide
http://www.microchip.com/download/tools/picmicro/code/mplab18/51288b.pdf

Right now, I am willing to try anything as long as to get the DAC to get
working. I am wondering whether is my TRISC initialise wrongly.
Am I right to put both SDA and SCL as input (1) for TRISC?

Bit 7    Bit 6   Bit 5    Bit 4    Bit 3    Bit 2    Bit 1    Bit 0

PORTC     RC7     RC6     RC5     RC4     RC3     RC2     RC1     RC0

TRISC      0          0          0          1          1          0
0          0

                                                     SDA    SCL


Nicholas

{Original Message removed}

2004\03\19@223233 by Ken Pergola

flavicon
face
Nicholas wrote:

> I had just send a document file to your email address at localnet.com. I
> hope it explain better. Thank for helping.

Hi Nicholas,

Yes I received it and sent you a reply. You have a nice project going on
there.
Hang in there Nicholas, engineering is full of "bumps" in the road and "up
against the wall" situations, but what until you get the feeling when you
fix the problem -- it's addictive!

Best regards,

Ken Pergola

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2004\03\20@112012 by Ken Pergola

flavicon
face
Nicholas wrote:

> Right now, I am willing to try anything as long as to get the DAC to get
> working. I am wondering whether is my TRISC initialise wrongly.
> Am I right to put both SDA and SCL as input (1) for TRISC?

Hi Nicholas,

I don't see anything wrong. You are doing things correctly as far as setting
SDA and SCL as inputs via the TRISC register.

Do you have any oscilloscopes in the lab?
I don't know if you know how to use one, but if not, someone in the lab
should be able to help you out.

After you ensure that your "tin can" 40 MHz clock oscillator is connected to
the PIC's OSC1/CLKI pin (by probing this with a 'scope as well), you could
probe the SCL line to see if you see it toggling. But in this case, you
would want to put your DAC write function in an infinite loop.

If you have not, it would be a good idea to embed your PIC18F452
Configuration Bit settings in your C source code.
I have not used Microchip's C18 C compiler, but you should look up in the
manual to see how this is done. I'm guessing there should be some type of
CONFIG directive in C18. Perhaps a scan in the table of contents or index
will help you.

On Monday, send me your HEX file and a screen shot of your Configuration Bit
settings in MPLAB.

I can't stress this enough:
---------------------------
If your configuration bit settings are not set correctly (especially with
regard to the oscillator settings), then your microcontroller most likely
will not run. You will need to use the EC or ECIO oscillator type setting
with regard to the FOSC2, FOSC1, and FOSC0 configuration bits because you
are using a 40 MHz external "tin can" clock oscillator.

We have to make sure you are on track in this regard before proceeding to
other levels of troubleshooting.


Best regards,

Ken Pergola

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2004\03\20@113048 by Ken Pergola

flavicon
face
Nicholas,

Now that I know you are using a 40 MHz clock for the PIC18F452 you must
change the value you are loading into SSPADD:

You are loading a value of 0x09, but if your Fosc to the PIC is 40 MHz, then
your SCL clock frequency is actually 1 MHz!
Clearly this is in violation of the MAX417 (which is rated at 400 KHz
maximum). I'm not saying this will fix your problem, but you don't want to
operate above the manufacturer's specifications.

In other words Nicholas this line of code would be wrong for an external
clock of 40 MHz:

   SSPADD = 9;     //400KHz Baud clock (9) @16MHz


Your homework assignment:

Calculate a new SSPADD value, report back and I will verify the value you
calculated.


Best regards,

Ken Pergola

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

2004\03\21@101256 by Nicholas

picon face
Good afternoon Ken,

Yup, thank for reminding me that. I saw my mistake already.

Fosc = 40MHz
Baud rate = 400KHz

Therefore, SSPADD = (Fosc/4*Baud rate)-1

In the case I will get, SSPADD = 24;    //400KHZ Baud clock @ 40MHz

Am I correct to say that?

I have rewrite the I2C_inital as shown below. I added in the SSPCON1 which I
miss out at first. But I do not know whether the C18 complier command
OPENI2C(MASTER, SLEW_ON) is the same as using SSPCON1.

Just for you to verify.

//I2C_init condition
TRISC = 0X18;                               //Set SDA (PIN 4) & SCL (PIN3)
as input. Activate I2C port
OpenI2C(MASTER, SLEW_ON);  //Initialize I2C module
SSPADD = 24;                                //400KHz Baud clock @ 40MHz
SSPCON1 = 0x28;                          //set up SCL & SDA as the source
for the serial port and set the I2C module to master mode

Thank you,
Nicholas

{Original Message removed}

2004\03\21@121523 by Ken Pergola

flavicon
face
Nicholas wrote:

> In the case I will get, SSPADD = 24;    //400KHZ Baud clock @ 40MHz
>
> Am I correct to say that?


Yes you are correct.


> I have rewrite the I2C_inital as shown below. I added in the
> SSPCON1 which I
> miss out at first. But I do not know whether the C18 complier command
> OPENI2C(MASTER, SLEW_ON) is the same as using SSPCON1.


Since I have never used the Microchip C18 C compiler, I don't know how much
of the low level details those library functions encapsulate. You really
need to see the source code (or resultant assembly language) behind  the
'OPENI2C()' function, for example, to see what's really going  at the
register level.


Best regards,

Ken Pergola

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...