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

Help! PIC16F877A and SM Bus

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



Joined: 11 Jul 2006
Posts: 42
Location: Minden, Germany

View user's profile Send private message

Help! PIC16F877A and SM Bus
PostPosted: Wed Feb 28, 2007 12:55 pm     Reply with quote

Hello!

Can anyone help me to find an answer, why my code is wrong. I'm reading out an IC BQ2085 and i cann't see anything, if i use Hyper Terminal.
[code]
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOWRT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7,parity=n,bits=8,ERRORS)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3, SMBUS)

int8 datal, datah;
int16 data;

void read()
{
i2c_start(); // Start
i2c_write(0x16); //Battery Adress + R/W=0
i2c_write(0x17);// Command Word ( CycleCount)
i2c_start(); // Start
i2c_write(0x17);// Battery Address + R/W=1
datal=i2c_read();
i2c_write(0);
datah=i2c_read();
i2c_write(1);
i2c_stop(); //Stop
data=make16(datah, datal);
}

void send()
{

printf("%2ld\r\n", data);

}


void main()
{
while(1)
{
read();
send();
delay_ms(500);
}
}


[code]

I cann't post the datasheet, sorry.
[/img][/code]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 28, 2007 12:59 pm     Reply with quote

What is this ?
Quote:

datah=i2c_read();
i2c_write(1);

Are you trying to do a NAK on the last read ?
You don't do it like that. Do it like this, with a 0 parameter:
Code:
datah = i2c_read(0);



Also the same thing here. Are you trying to do an ACK ?
You need to study the CCS manual and look at a few i2c
drivers in the CCS drivers directory on your hard disk.
Look at how they do things. Don't invent.
Quote:
datal=i2c_read();
i2c_write(0);
deniska_gus



Joined: 11 Jul 2006
Posts: 42
Location: Minden, Germany

View user's profile Send private message

PostPosted: Wed Feb 28, 2007 1:05 pm     Reply with quote

But in the datasheet i can see just NAK after the last read !?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 28, 2007 1:31 pm     Reply with quote

This is how you do it in CCS:
Code:

datal=i2c_read();
datah=i2c_read(0);  // NAK on last read
i2c_stop(); 
data=make16(datah, datal);
 
deniska_gus



Joined: 11 Jul 2006
Posts: 42
Location: Minden, Germany

View user's profile Send private message

PostPosted: Wed Feb 28, 2007 1:46 pm     Reply with quote

PCM programmer, you are the King. Thank you very much.
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