![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
lozzoloz Guest
|
Problem with using MSSP and I2C |
Posted: Tue Sep 04, 2007 7:59 am |
|
|
Hi,
i am working with PIC18F4620 and i am using I2C bus to communicate with I2C devices (CCS 3,249 is my compiler)
if i use the following preprocessor code the code works fine
#use i2c (MASTER, SDA=PIN_C4,SCL=PIN_C3)
but it genarates the i2c routines by software and i don't want it
i am changing the preprocessor code like this
#use i2c (MASTER, SDA=PIN_C4,SCL=PIN_C3,FORCE_HW)
in order to use hardware for i2c, the compiler compiles the code without any erros but it doesn't work. i checked the list file every thing seems correct (step by step in 18F4620 's PDF file)
what can be wrong am i missing something
thanks. |
|
![](templates/subSilver/images/spacer.gif) |
icesynth
Joined: 03 Sep 2007 Posts: 32 Location: Edmonton, Alberta
|
|
Posted: Tue Sep 04, 2007 10:49 am |
|
|
Is there any activity on the SCL or SDA lines when you call the functions? _________________ Programming for the the real world.
--Chris Burchett
Sylver Technologies Inc. |
|
![](templates/subSilver/images/spacer.gif) |
lozzoloz Guest
|
|
Posted: Tue Sep 04, 2007 11:55 pm |
|
|
no it doesnt |
|
![](templates/subSilver/images/spacer.gif) |
lozzoloz Guest
|
|
Posted: Wed Sep 05, 2007 12:22 am |
|
|
i wrote the i2c functions my self it still doesn't work
Code: |
//register adresses for 18f4620
#byte SSPCON1 = 0xFC6
#byte SSPCON2 = 0xFC5
#byte SSPSTAT = 0xFC7
#byte SSPBUF = 0xFC9
#byte SSPADD = 0xFC8
#byte PORTC = 0xF82
#bit dir_scl =PORTC.3
#bit dir_sda =PORTC.4
void i2c_init_my()
{
bit_set(SSPSTAT,0); //SMP=1; standart mode
bit set(SSPCON1,3); //SSMP3=1;
bit_clear(SSPCON1,2); //
bit_clear(SSPCON1,1); //
bit_clear(SSPCON1,0); //
bit_set(SSPCON1,5); //SSP enable
SSPADD = 0x4F; //set i2c speed
dir_scl=1; //i2c pins are input
dir_sda=1;
return;
}
void i2c_start_my()
{
bit_set(SSPCON2,0); //send start
while(bit_test(SSPCON2,0)); //wait until start has been send
return;
}
|
first i call i2c_init_my();
then if i call i2c_start_my();
it doesnt come back from i2c_start_my(); which means SSPCON2,0 is always 1; |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Sep 05, 2007 2:38 am |
|
|
SMP, is bit 7, not bit 0.
Personally, just simpler to write complete bytes. Also, you must set the resource to 'off', before updating some bits. So:
Code: |
bit_clear(SSPCON1,5); //turn off SSP
SSPCON1=0b10000000;
SSPSTAT=0b00001000;
SSPADD=0x4F;
bit_set(SSPCON1,5); //reenable SSP
dir_scl=0; //i2c pins are input - wrong. Table 10-5
dir_sda=1;
|
You need the SCL pin to be set as an output, not an input. Look at table 10-5, which shows how TRIS needs to be set for various modes.
Obvious comment applies though. You _have_ got the resistor pull-ups on the I2C bus?.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
lozzoloz Guest
|
|
Posted: Wed Sep 05, 2007 5:52 am |
|
|
SMP is bit 7 , this is correct my mistake, but i tried again i have still the same conditions.
i have the pull-up resistors, the circuit and the code is working perfect with #use i2c(master.........) without force_hw
when i write force_hw nothing works, thus i tried to write my own code thought CCS could have the problem but in my code i cant even send start condition
thanks for your comments |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Sep 05, 2007 6:18 am |
|
|
Try selecting a much slower rate.
The big difference, between software, and hardware, is the available drive rates. The software version will 'limit out' on speed, at a rate of only a relatively few tens of kHz.
So use (say):
#use i2c (MASTER, SDA=PIN_C4,SCL=PIN_C3,FORCE_HW,SLOW=50000)
and see if there is any change.
The reason I asked about the resistors, is that functionally, there is not really a true 'open collector' drive available in the software moe, and this is simulated, by using the TRIS to turn off the pull up transistor. The behaviour is slightly different from the hardware mode, and I have seen systems work in software mode, and fail in hardware mode, when the pull-up is inadequate.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|