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

Why i2c_isr_state() testing SSPBUF.0 instead of SSPCON.RW

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



Joined: 06 Apr 2008
Posts: 16

View user's profile Send private message

Why i2c_isr_state() testing SSPBUF.0 instead of SSPCON.RW
PostPosted: Mon Jun 29, 2009 10:49 pm     Reply with quote

Hi,

The disassembly of i2c_isr_state() reveals that it reads SSPBUF.0 to determine if the ADDR is for read or write, instead of probing SSPCON RW flag. Why is that so?

The Microchip AN734 shown the use of SSPCON RW to determine ADDR+R or ADDR+W.

Code:

646:                 smbusState = i2c_isr_state();
004C    1683     BSF 0x3, 0x5
004D    1A94     BTFSC 0x14, 0x5       ; SSPSTAT.DA, ADDR or DATA
004E    2854     GOTO 0x54
004F    1283     BCF 0x3, 0x5
0050    01EC     CLRF 0x6c             ; 0x6c, CCS I2C internal use register
0051    1813     BTFSC 0x13, 0         ; SSPBUF bit 0, RD or WR
0052    17EC     BSF 0x6c, 0x7
0053    1683     BSF 0x3, 0x5
0054    1283     BCF 0x3, 0x5
0055    086C     MOVF 0x6c, W
0056    0AEC     INCF 0x6c, F
0057    00CE     MOVWF 0x4e            ; smbusState 0x4e


Info:
1. CCS PCM C Compiler, Version 4.073, 38894
2. Target IC, master 16F887 MSSP, slave 16F916 SSP
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Jun 29, 2009 11:10 pm     Reply with quote

If you request i2c_isr_state() after receiving the address byte, both methods are equivalent. However, I didn't think yet about the intended use of this function. The compiler manual isn't very clear in this respect. Acquiring the necessary information from SFR directly is probably the clearer method.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 29, 2009 11:16 pm     Reply with quote

Quote:
The disassembly of i2c_isr_state() reveals that it reads SSPBUF.0 to determine if the ADDR is for read or write, instead of probing SSPCON RW flag. Why is that so?

Here are two posts that will help you to understand that function:

Commented .LST file for the i2c_isr_state() function:
http://www.ccsinfo.com/forum/viewtopic.php?t=28531&start=10

C source code for i2c_isr_state():
http://www.ccsinfo.com/forum/viewtopic.php?t=26477&start=3
epalite



Joined: 06 Apr 2008
Posts: 16

View user's profile Send private message

PostPosted: Mon Jun 29, 2009 11:57 pm     Reply with quote

Hi PCM Programmer,

I read your explanation.

My question is why doesn't the i2c_isr_state() function extract the R/W flag from SSPCON.RW (0x94 bit 2)?

Doesn't the SSPCON.RW carry the ADDR R/W flag?

Hi FvM,

The i2c_isr_state() is used in the INT_SSP ISR.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 30, 2009 12:54 am     Reply with quote

That is a good question. I'll look at it tomorrow, if nobody else does it first.
epalite



Joined: 06 Apr 2008
Posts: 16

View user's profile Send private message

PostPosted: Tue Jun 30, 2009 1:32 am     Reply with quote

Hi,

I rewrote and emulated i2c_isr_state(), except to retrieve RW from SSPCON.RW instead of SSPBUF.0. It didn't work on 16F690, 16F916, 16F887 M/SSP slave.

It seems RW flag has not been set on SSPCON.RW.
Ttelmah
Guest







PostPosted: Tue Jun 30, 2009 3:16 am     Reply with quote

In the first ISR, SSPBUF, _must_ be read. If it is not, the BF flag won't clear, and WCOL/OERR can become set on the next byte. So, to use the R/W bit in SSPCON, you actually have to read the SSPBUF, anyway, so it is simpler just to use the bottom bit from SSPBUF, and 'kill two birds with one stone'. Where the R/W bit is useful, is on the second pass in the ISR, where it keeps the status recorded with the start of the transaction. However the I2C_ISR_STATE function, itself saves the bit, so it makes no point to use this bit. for the function as written.....
It is just a case of a chip feature, not really gaining anything, and not being used.

Best Wishes
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