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

Hardware I2C doesn work

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







Hardware I2C doesn work
PostPosted: Tue Jul 26, 2005 9:54 am     Reply with quote

Please help me.
I' m trying to get this short peace of code working, but I always get a software I2C. Why??
Code:
#include <16F747.h>

#use delay(clock=31250)
#fuses NOWDT,INTRC_IO, NOPUT, NOPROTECT, NOBROWNOUT, BORV20, MCLR, NODEBUG, NOFCMEN, NOIESO, NOBORSEN

#use I2C(slave,sda=PIN_C4,scl=PIN_C3,address=0xa0,FORCE_HW)

void main()
{

   i2c_Start();
   i2c_Write(64);
   i2c_Stop();
}


Compiler Version is 3.203
MPLAB Version is 7.20

Please help me!
Thanks a lot
WildMax
Guest







PostPosted: Tue Jul 26, 2005 9:57 am     Reply with quote

Oh, the assembled code is:
Code:

1:                 #include <16F747.h>
   000    3000     MOVLW 0
   001    008A     MOVWF 0xa
   002    282D     GOTO 0x2d
   003    0000     NOP
2:                 
3:                 #use delay(clock=31250)
4:                 #fuses NOWDT,INTRC_IO, NOPUT, NOPROTECT, NOBROWNOUT, BORV20, MCLR, NODEBUG, NOFCMEN, NOIESO, NOBORSEN
5:                 
6:                 #use I2C(slave,sda=PIN_C4,scl=PIN_C3,address=0xa0,FORCE_HW)
   004    3008     MOVLW 0x8
   005    00F8     MOVWF 0x78
   006    1683     BSF 0x3, 0x5
   007    1587     BSF 0x7, 0x3
   008    1207     BCF 0x7, 0x4
   009    1283     BCF 0x3, 0x5
   00A    1D87     BTFSS 0x7, 0x3
   00B    280E     GOTO 0xe
   00C    1683     BSF 0x3, 0x5
   00D    2809     GOTO 0x9
   00E    0DA1     RLF 0x21, F
   00F    1803     BTFSC 0x3, 0
   010    1607     BSF 0x7, 0x4
   011    1C03     BTFSS 0x3, 0
   012    1207     BCF 0x7, 0x4
   013    1D87     BTFSS 0x7, 0x3
   014    2813     GOTO 0x13
   015    0BF8     DECFSZ 0x78, F
   016    2818     GOTO 0x18
   017    281A     GOTO 0x1a
   018    1683     BSF 0x3, 0x5
   019    2809     GOTO 0x9
   01A    1987     BTFSC 0x7, 0x3
   01B    281A     GOTO 0x1a
   01C    1683     BSF 0x3, 0x5
   01D    1607     BSF 0x7, 0x4
   01E    1283     BCF 0x3, 0x5
   01F    1987     BTFSC 0x7, 0x3
   020    2823     GOTO 0x23
   021    1683     BSF 0x3, 0x5
   022    281E     GOTO 0x1e
   023    01F8     CLRF 0x78
   024    1A07     BTFSC 0x7, 0x4
   025    1478     BSF 0x78, 0
   026    0000     NOP
   027    1683     BSF 0x3, 0x5
   028    1187     BCF 0x7, 0x3
   029    1283     BCF 0x3, 0x5
   02A    1187     BCF 0x7, 0x3
   02B    118A     BCF 0xa, 0x3
   02C    284B     GOTO 0x4b
7:                 
8:                 void main()
9:                 {
   02D    0184     CLRF 0x4
   02E    301F     MOVLW 0x1f
   02F    0583     ANDWF 0x3, F
   030    1683     BSF 0x3, 0x5
   031    081F     MOVF 0x1f, W
   032    39C0     ANDLW 0xc0
   033    3803     IORLW 0x3
   034    009F     MOVWF 0x1f
   035    3007     MOVLW 0x7
   036    1283     BCF 0x3, 0x5
   037    009F     MOVWF 0x1f
10:               
11:                   i2c_Start();
   038    1683     BSF 0x3, 0x5
   039    1587     BSF 0x7, 0x3
   03A    1607     BSF 0x7, 0x4
   03B    1283     BCF 0x3, 0x5
   03C    1A07     BTFSC 0x7, 0x4
   03D    2840     GOTO 0x40
   03E    1683     BSF 0x3, 0x5
   03F    283B     GOTO 0x3b
   040    1D87     BTFSS 0x7, 0x3
   041    2840     GOTO 0x40
   042    1987     BTFSC 0x7, 0x3
   043    2840     GOTO 0x40
   044    1683     BSF 0x3, 0x5
   045    1187     BCF 0x7, 0x3
   046    1283     BCF 0x3, 0x5
   047    1187     BCF 0x7, 0x3
12:                   i2c_Write(64);
   048    3040     MOVLW 0x40
   049    00A1     MOVWF 0x21
   04A    2804     GOTO 0x4
13:                   i2c_Stop();
   04B    1683     BSF 0x3, 0x5
WildMax
Guest







PostPosted: Tue Jul 26, 2005 10:01 am     Reply with quote

Oh, i haven't seen, that the #use i2c statement was for a slave but if i change it to master, the same problem occours!!

Please help me, it is really important and has to go very quick!!
Ttelmah
Guest







PostPosted: Tue Jul 26, 2005 10:04 am     Reply with quote

Probably because a slave device, cannot issue a 'start' on I2C.
The whole point is that with a slave, the _master_ allways begins and ends the transaction. As soon as you use the 'start', and 'stop' commands, you are overriding the instruction to be a hardware slave.

Best Wishes
Guest








PostPosted: Tue Jul 26, 2005 10:07 am     Reply with quote

Ttelmah wrote:
Probably because a slave device, cannot issue a 'start' on I2C.


Yeah, i know that, but if i change it to master, there are not many changes (its also software)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 26, 2005 10:15 am     Reply with quote

Your version of the compiler doesn't create hardware i2c code.
I tested your version and then installed vs. 3.228, and the later
version does create code for H/W i2c.

If you have PCW or PCWH, you could use the Device Editor to
see if CCS has properly configured the 16F747. This screenshot
of the Device Editor shows two check boxes for i2c Slave and i2c Master.
http://www.ccsinfo.com/pix/Device%20Editor.gif

You could also upgrade the compiler or write the H/W i2c functions
yourself.
mwildbolz



Joined: 26 Jul 2005
Posts: 16

View user's profile Send private message

PostPosted: Tue Jul 26, 2005 10:20 am     Reply with quote

in my compiler version, i2c Master is enabled, but i2c slave not.
I'll try to change this and then i'll try it on a newer compiler version

Thanks
mwildbolz



Joined: 26 Jul 2005
Posts: 16

View user's profile Send private message

PostPosted: Tue Jul 26, 2005 10:22 am     Reply with quote

OK!

I've found the problem!
In the device editor, both has to be enabled (i2c master AND slave).
In my case, only Master was enabled and therfore, the compiler wasn't able to produce code for HW - I2C

Thanks for your help
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 26, 2005 10:25 am     Reply with quote

It's possible that CCS left the i2c slave box unchecked because
they didn't have it working at the time of the release.
You should look at the ASM code produced for the i2c Slave and
verify that it's correct.

That's what I would do, just to be safe.
mwildbolz



Joined: 26 Jul 2005
Posts: 16

View user's profile Send private message

PostPosted: Tue Jul 26, 2005 10:33 am     Reply with quote

I think, now it is in the right form:

Code:
6:                 #use I2C(master,sda=PIN_C4,scl=PIN_C3,FORCE_HW)
   004    1394     BCF 0x14, 0x7
   005    118C     BCF 0xc, 0x3
   006    0821     MOVF 0x21, W
   007    0093     MOVWF 0x13
   008    3002     MOVLW 0x2
   009    1B94     BTFSC 0x14, 0x7
   00A    2812     GOTO 0x12
   00B    1D8C     BTFSS 0xc, 0x3
   00C    280B     GOTO 0xb
   00D    3000     MOVLW 0
   00E    1683     BSF 0x3, 0x5
   00F    1B11     BTFSC 0x11, 0x6
   010    3001     MOVLW 0x1
   011    1283     BCF 0x3, 0x5
   012    00F8     MOVWF 0x78
   013    118A     BCF 0xa, 0x3
   014    2841     GOTO 0x41


Thats the listing directly under the #use i2c
And this lines use the SSP registers
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 26, 2005 10:36 am     Reply with quote

I didn't mean that. I meant, check the code to make sure it works.
mwildbolz



Joined: 26 Jul 2005
Posts: 16

View user's profile Send private message

PostPosted: Tue Jul 26, 2005 10:39 am     Reply with quote

Oh, clear.
I'll check it and report as soon as possible!
Guest








PostPosted: Tue Jul 26, 2005 11:32 am     Reply with quote

OK, i've tested the Code and all is OK!

I'm happy Very Happy

I wish you a nice day
mwildbolz



Joined: 26 Jul 2005
Posts: 16

View user's profile Send private message

PostPosted: Tue Jul 26, 2005 11:33 am     Reply with quote

Sorry, i've forgotten to log in Very Happy


regards, Markus
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