View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 15, 2006 11:44 pm |
|
|
Quote: |
1. (MASTER)Why do we always call i2c_write(0x00); after calling
i2c_write(0xA0); |
The Ex_Slave program emulates a 24C00 eeprom. The protocol
is defined in the eeprom data sheet.
http://ww1.microchip.com/downloads/en/DeviceDoc/21178d.pdf
Look at the sequence of bytes shown in the data sheet.
It will show you the answer.
Quote: |
2. (MASTER)Why do we always call i2c_start() second time. |
Again, look in the 24C00 data sheet.
Quote: |
3. In the MASTER and SLAVE I also wrote the code, if I needed the slave
to send the 32 byte data packet. |
Write the code to do that. Then debug and test it.
Quote: |
4. I hope the i2c_isr_state() gets reset after the first i2c_stop() in the
Master.
|
To see when the compiler clears the i2c state variable, look at
the listing file. It will have a file extension of .LST, and it's in
your project directory. Then put in comments to explain what
each line is doing. In the listing below, you can see that the
state variable is cleared whenever the i2c module receives an
address byte. Look in the PIC's data sheet to see the meaning
of each bit in the SSPSTAT register.
Code: |
...... state = i2c_isr_state();
0044: BSF STATUS.5 // Bank 1
0045: BTFSC SSPSTAT.5 // Goto 0047 if Address
0046: GOTO 04C // Goto 004C if Data
0047: BCF STATUS.5 // Bank 0
0048: CLRF @I2C_STATE // If got Address, clear state var.
0049: BTFSC SSPBUF.0 // Goto 004B if Write
004A: BSF @I2C_STATE.7 // If Read, set bit 7 of state var.
Write_operation:
004B: BSF STATUS.5 // Bank 1
Got_Data_Byte:
004C: BCF STATUS.5 // Bank 0
004D: MOVF @I2C_STATE,W // Save state var. in W
004E: INCF @I2C_STATE,F // Increment state variable
004F: MOVWF state // Return state variable
*
0099: MOVLW 03 // Upon program start-up,
009A: MOVWF @I2C_STATE // init state var. = 0x03 |
|
|
|
pr83
Joined: 20 Jul 2006 Posts: 15
|
|
Posted: Mon Oct 16, 2006 2:40 pm |
|
|
Dear PCM Programmer,
Thanks a ton for the EEPROM data sheet. It was very helpfull. |
|
|
Rhesus Guest
|
About an insctruction you're using... |
Posted: Fri Oct 27, 2006 7:08 pm |
|
|
Hey, I tried to use the i2c_isr_state() directly, though it didn't work. Where is it? Do I need to include a library or maybe it is a special function register in the PIC?. Please let me know where can I find that statement and use it, since i'm having a really tough time with the I2C bus. Currently I'm using PIC18F452 (it has hardware I2C) and CCS PCWH v. 3.225.
Thanx. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Oct 27, 2006 7:46 pm |
|
|
Quote: | I tried to use the i2c_isr_state() directly, though it didn't work.
Currently I'm using PIC18F452 (it has hardware I2C) and CCS PCWH v. 3.225.
|
See this thread, which tells you the version number at which that
function was first available. It also provides a link to code which
emulates the i2c_isr_state() function, in case your version doesn't
support it.
http://www.ccsinfo.com/forum/viewtopic.php?t=26978 |
|
|
|