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

I2C software version... Misery

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







I2C software version... Misery
PostPosted: Wed Jul 30, 2003 1:22 pm     Reply with quote

I plan to use the built in functions to read ext. fram and never gave it much thought.... after all CCS has code ready for i2c eeprom and that is about the same...
Right.... arrrrrrrrrrgh ! No... I tried using the eemprom code with the delayed after write removed removed, but the problem shows up a lot earlier.

In the header
#use I2C(master, sda=PIN_A3, scl=PIN_A2, SLOW)

This is done at starup.
Set the trisA bit for PIN_A2 and A3 as output, becasue I assume the I2C funstion take care of directions when called.

Initialize by floating the two pins.
output_float(PIN_A2);
output_float(PIN_A3);

then a call is made to write_fram(0,'X'); // write and X to location zero

the code never gets past i2c_start();

void write_fram(long int address, byte data)
{
i2c_start();
i2c_write((0xa0|(byte)(address>>7))&0xfe);
i2c_write(address);
i2c_write(data);
i2c_stop();
}

What's the magic about i2c.... I prefer SPI but have no choice in this case.

I feel sure the hardware is correct, I have 4K7 pull-ups at the end of the i2c bus, and the length of the i2c bus is about 2 inches.

Some wise comment would be very welcome...

Hans W

PS I noticed how many people struggle with i2c, is it really that big of a mess ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516499
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: I2C software version... Misery
PostPosted: Wed Jul 30, 2003 1:45 pm     Reply with quote

:=I plan to use the built in functions to read ext. fram and never gave it much thought.... after all CCS has code ready for i2c eeprom and that is about the same...
---------------------------------------------------


What's the part number of the FRAM chip you're using ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516500
Hans Wedemeyer
Guest







Re: I2C software version... Misery
PostPosted: Wed Jul 30, 2003 1:55 pm     Reply with quote

:=What's the part number of the FRAM chip you're using ?

FM24C256

According to the data sheet it's a farily normal i2c part.

Do you know of any problems with ti ?

BTW these are very new part. so they will do the abort read is needed.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516502
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: I2C software version... Misery
PostPosted: Wed Jul 30, 2003 2:16 pm     Reply with quote

<font face="Courier New" size=-1>:=:=What's the part number of the FRAM chip you're using ?
:=
:=FM24C256
:=
-----------------------------------------------------------

Try using these routines:


#define FRAM_I2C_WRITE_ADDR 0xA0
#define FRAM_I2C_READ_ADDR 0xA1


void write_fram_byte(long addr, char data)
{
i2c_start();
i2c_write(FRAM_I2C_WRITE_ADDR);
i2c_write((char)(addr >> 8));
i2c_write((char)addr);
i2c_write(data);
i2c_stop();
}


char read_fram_byte(long addr)
{
char data;
i2c_start();
i2c_write(FRAM_I2C_WRITE_ADDR);
i2c_write((char)(addr >> 8));
i2c_write((char)addr);

i2c_start();
i2c_write(FRAM_I2C_READ_ADDR);

data = i2c_read(0);
i2c_stop();

return(data);
}
</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516503
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Syntax error?
PostPosted: Wed Jul 30, 2003 2:20 pm     Reply with quote

<font face="Courier New" size=-1>:=I plan to use the built in functions to read ext. fram and never gave it much thought.... after all CCS has code ready for i2c eeprom and that is about the same...
:=Right.... arrrrrrrrrrgh ! No... I tried using the eemprom code with the delayed after write removed removed, but the problem shows up a lot earlier.
:=
:=In the header
:=#use I2C(master, sda=PIN_A3, scl=PIN_A2, SLOW)
:=
:=This is done at starup.
:=Set the trisA bit for PIN_A2 and A3 as output, becasue I assume the I2C funstion take care of directions when called.
:=
:=Initialize by floating the two pins.
:=output_float(PIN_A2);
:=output_float(PIN_A3);
:=
:=then a call is made to write_fram(0,'X'); // write and X to location zero
:=
:=the code never gets past i2c_start();
:=
:=void write_fram(long int address, byte data)
:={
:= i2c_start();
:= i2c_write((0xa0|(byte)(address>>7))&0xfe);
:= i2c_write(address);
:= i2c_write(data);
:= i2c_stop();
:=}
:=
:=What's the magic about i2c.... I prefer SPI but have no choice in this case.
:=
:=I feel sure the hardware is correct, I have 4K7 pull-ups at the end of the i2c bus, and the length of the i2c bus is about 2 inches.
:=
:=Some wise comment would be very welcome...
:=
:=Hans W
:=
:=PS I noticed how many people struggle with i2c, is it really that big of a mess ?

Is this line correct?
void write_fram(long int address, byte data)
Should it have both long and int to declare the address?</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516504
Hans Wedemeyer
Guest







Re: I2C software version... It works !
PostPosted: Wed Jul 30, 2003 2:51 pm     Reply with quote

Thanks that worked like a charm ...
hans w
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516505
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