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 support@ccsinfo.com

problem in I2C when connecting picf873a with mcp9800
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
b.sandheep@gmail.com



Joined: 19 Dec 2014
Posts: 11

View user's profile Send private message

problem in I2C when connecting picf873a with mcp9800
PostPosted: Fri Dec 19, 2014 5:08 am     Reply with quote

I was working to communicate temperature sensor with pic16f873a. But i couldn't. Anyone please help to correct it. This is my code:
Code:

#include <main.h>

#byte spbrg= 0x99
#bit sync = 0x98.4
#bit spen =0x18.7
#bit trisc7=0x07.7
#bit trisc6=0x07.6
#bit txen=0x98.5
#bit cren=0x18.4
#byte txreg=0x19
#bit trmt=0x98.1

int cmd=0xFF,i=1,o=1;
byte incoming,state;
byte address,buffer[0x10],a[0x10];

#int_SSP
void ssp_interupt()
{
o = i;
i++;
state=i2c_isr_state();

incoming=i2c_read();

if(state==1)
{
address=incoming;
}

if(state > 1)
{
buffer[address]=incoming;

}

if(state==0x80)
{
i2c_write(buffer[address]);
}

}


void main()
{
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);

// TRISCbits.TRISC7=1;
 
spbrg= 25;
sync = 0;
spen =1;
trisc7=1;
trisc6=0;

txen=1;
cren=1;

i2c_start();
i2c_write(0x48); //i2c address of a slave device
i2c_write(0b00000001); //1st byte to slave
i2c_write(0b10000111); //2nd byte to slave
i2c_stop();

while(TRUE)
   {
   printf ("%x",buffer[address]);
   }

}

I need the result in uart but i couldn't.

Thanks in advance

Regards
Sandheep B
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 19, 2014 4:17 pm     Reply with quote

MCP9800 is similar to the LM75. It appears to be compatible with LM75
in its default register settings. Try the CCS driver in this directory:
Quote:
c:\program files\picc\drivers\lm75cim3.c



Quote:
spbrg= 25;
sync = 0;
spen =1;
trisc7=1;
trisc6=0;

txen=1;

Don't do the UART setup manually. Use the #use rs232() feature of CCS
to setup the UART. Example:
Code:
#use rs232(baud=9600, UART1, ERRORS)



Quote:
#int_SSP
void ssp_interupt()
{
o = i;
i++;
.
.
.
}

You don't need this #int_ssp routine. Delete it.

Use the CCS driver: lm75cim3.c

Make sure you have pull-up resistors on SDA and SCL.
b.sandheep@gmail.com



Joined: 19 Dec 2014
Posts: 11

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 1:29 am     Reply with quote

Thanks for your reply but its not working.
Code:

#include "C:\Documents and Settings\Administrator\Desktop\tem\main.h"
#include "C:\Program Files\PICC\Drivers\LM75CIM3.C"
void main()
{

signed long data1;
init_temp();

while(1)
{
data1=read_full_temp();

printf("%x",data1);

}
 

}


LM75CMI3.C


+++++++++++++++++++++
lm75cim3.c code deleted.
Reason: Forum rule #10
10. Don't post the CCS example code or drivers.
http://www.ccsinfo.com/forum/viewtopic.php?t=26245
Put code in code block.
- Forum Moderator
+++++++++++++++++++++


can you help me were i made mistake.

Thanks in advance

Regards
Sandheep B
Ttelmah



Joined: 11 Mar 2010
Posts: 19339

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 2:44 am     Reply with quote

Of course it won't work. You have remmed out the I2C setup line. Without this the I2C is _not_ configured.
b.sandheep@gmail.com



Joined: 19 Dec 2014
Posts: 11

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 2:46 am     Reply with quote

ya even i place its not working any how that line i have added up in main.h.
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 6:12 am     Reply with quote

I2C rule #1 . be sure proper I2C bus resistors are in place.Typically 4k7 or 3k3.

I2C rule #2. download,compile,install,run PCMP's 'I2C scanner' program from the 'code library'. Do NOT proceed until it 'sees' your I2C devices.

I2C rule #3, use the internal hardware if possible.

I2C rule #4,use the CCS I2C functions.

After all that and it still doesn't work, post small program that fails.

hth
jay
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 7:52 am     Reply with quote

Once have completed the Bus Scanner test successfully and
repost your code, you need to do a few things:
1. Show us what is in Main.h
2. Delete the LM75CMI3.C code you posted since posting it that violates the
CCS copyright and we all have it anyway.
3. Use the Code button like you did the first time to properly format your
code and make it readable.
_________________
Google and Forum Search are some of your best tools!!!!
b.sandheep@gmail.com



Joined: 19 Dec 2014
Posts: 11

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 10:45 pm     Reply with quote

ok. every thing is ok but still i couldn't read mcp9800.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 10:56 pm     Reply with quote

Quote:
ok. everything is ok but still i couldn't read mcp9800.

What do see displayed ?

To display 'long' data, you need to use %lx (that's an L) as shown below:
Quote:

signed long data1;
init_temp();

while(1)
{
data1=read_full_temp();

printf("%lx",data1);

}
b.sandheep@gmail.com



Joined: 19 Dec 2014
Posts: 11

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 11:08 pm     Reply with quote

nothing i could see.

Actually when i add init_tem(); the further line were not executed.

i think I2C is not initializing.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 11:34 pm     Reply with quote

You are probably missing the pullup resistors on SDA and SCL.
b.sandheep@gmail.com



Joined: 19 Dec 2014
Posts: 11

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 11:43 pm     Reply with quote

no i have placed. even in simulator its not working
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 21, 2014 11:55 pm     Reply with quote

Run this program on your PIC. See if it finds the mcp9800 chip.
http://www.ccsinfo.com/forum/viewtopic.php?t=49713
b.sandheep@gmail.com



Joined: 19 Dec 2014
Posts: 11

View user's profile Send private message

PostPosted: Mon Dec 22, 2014 12:09 am     Reply with quote

now i have fused my program in a hardware. but it displays 40 always even any change in the temperature.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 22, 2014 12:22 am     Reply with quote

One problem is that you don't give answers to questions, you just jump
ahead. Then you report things in a very obscure way. For example:
Quote:
but it displays 40 always even any change in the temperature.

Did the i2c bus scanner program find the lm9800 ? What address did it
report ? Apparently the lm9800 is now working (somewhat). What did
you do to make it work ?

You said it displays 40. It that the temperature ? But is that in hex 0x40 ?
Or is it decimal ?

Because your replies leave out so much information, it is hard to help you.
I have to quit for the night. Maybe someone else can help.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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