View previous topic :: View next topic |
Author |
Message |
Hans Wedemeyer Guest
|
I2C software version... Misery |
Posted: Wed Jul 30, 2003 1:22 pm |
|
|
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
|
Re: I2C software version... Misery |
Posted: Wed Jul 30, 2003 1:45 pm |
|
|
:=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 |
Posted: Wed Jul 30, 2003 1:55 pm |
|
|
:=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
|
Re: I2C software version... Misery |
Posted: Wed Jul 30, 2003 2:16 pm |
|
|
<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
|
Syntax error? |
Posted: Wed Jul 30, 2003 2:20 pm |
|
|
<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 ! |
Posted: Wed Jul 30, 2003 2:51 pm |
|
|
Thanks that worked like a charm ...
hans w
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516505 |
|
|
|