CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

dspic30f6014a and I2C

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
on7nh



Joined: 05 Jun 2006
Posts: 41
Location: Belgium

View user's profile Send private message Visit poster's website MSN Messenger

dspic30f6014a and I2C
PostPosted: Mon May 21, 2012 7:55 am     Reply with quote

hello,
have someboby experience with a dspic30f6014a and i2c?
i have this project,
the processor is running over it without problem, but the result is always 0
pull up resistors are 4.7k, i see on a scoop the request from the cpu, and i see the TC74A5 answering.



Code:

#include <30f6014a.h>
#DEVICE ADC=12

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES EC_PLL8                 //XT Crystal Oscillator mode with 8X PLL
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES PUT64                    //Power On Reset Timer value 64ms
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
#USE DELAY(Clock=80M)           //10Mhz Crystal with 8X PLL (Is that right?)
#use i2c(master, sda = PIN_G3, scl = PIN_G2, force_hw)
#USE RS232(UART1,Baud=115200,Parity=N,Bits=8)
 
 
#include <t6963_test.C>
#include <graphics.c>
#include <Math.h>

/////////////////// Variabelen /////////////////
   int ack;
   Float Temperatuur;
      void Prnt_display();
   void Analoog_Conversie();
   void Temperatuur_lezen();


////////////////////////////////////////////////////////////////////////////////
void Temperatuur_lezen()
{       // lezen TC74A5 //
      i2c_start();
      ack = i2c_write(0x9A);
      ack = i2c_write(0x00);
      /* send start again */
      i2c_start();
      ack = i2c_write(0x9B);
      Temperatuur = i2c_read(0);
      i2c_stop();

   printf("temp %f  \r\n",temperatuur/10);
}

////////////////////////////////////////////////////////////////////////////////

void main()
{
   setup_adc_ports(sAN2 | sAN3 | sAN4 | sAN5 );
   setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_31);

   printf("%c[2J%c[H",27,27);
   printf("Booting \n\r");


   

while(1){


      Temperatuur_lezen();
      Prnt_display();

      
      
   
}
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon May 21, 2012 8:25 am     Reply with quote

Obvious first question:
Why are you dividing the value by 10?.
The chip returns the temperature as a _signed_ integer value from +127 to -65 (specification limit in the -ve direction). In degrees. No scale by ten involved.
To display the temperature for this, you want:

printf("temp %d \n\r",temperatuur);

No division, and use the signed output format.
Assuming your room is at (say) 20C, then you would only get perhaps '1' as an output with your division, since this is being performed using integer maths.

Might be the whole problem....

If your serial works, then this verified your clockrate is OK (you query this).

What version of the 7C74A5 have you got?. Needs to be the TC74A5-5.0VCT or the TC74A5-5.0VAT.

The chip requires you to wait for 250mSec after power on, before a reading will be ready.

The _maximum_ specified clock speed for the bus, is 100KHz. I'd explicitly specify a rate below this:

#use i2c(master, slow=80000, sda = PIN_G3, scl = PIN_G2, force_hw)

I'd explicitly ensure the device is out of shutdown:
Code:

      i2c_start();
      i2c_write(0x9A);
      i2c_write(0x01);
      i2c_write(0); //set command register to 0 to ensure chip is on
      i2c_stop();

The data sheet says this bit should be 0 at POR, but worth being sure....

Try running PCM_programmers I2C bus scanner program, and verify you do get an ACK from the chip.

Best Wishes
on7nh



Joined: 05 Jun 2006
Posts: 41
Location: Belgium

View user's profile Send private message Visit poster's website MSN Messenger

PostPosted: Mon May 21, 2012 11:54 pm     Reply with quote

i did yesterday some tests,

dividing was...i was thinking the TC74 was working wit a decimal...NOT..

the TC74A5-5.0VAT is responding the correct vallue (see picture) but the controller give me always a 0

clockrate is changed to 80000

pull up resistors are now 10k

Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group