|
|
View previous topic :: View next topic |
Author |
Message |
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
Problem using 2nd I2C port on 18F8722 |
Posted: Wed Jan 18, 2006 6:22 am |
|
|
I need to use both *hardware* I2C ports on an 18F8722.
I'm just testing one of them at the moment, and I've come across a problem.
My code contains the following:-
Code: | // define i2c hardware for the fram device
#use i2c(MASTER,FAST,SDA=PIN_D5,SCL=PIN_D6,FORCE_HW)
/* Write address to external ram */
void ext_ram_write_addr(int16 addr) {
// start i2c cycle
i2c_start();
// send "write" command
i2c_write(FRAM_WRITE);
// send address MSB then LSB
i2c_write(make8(addr, 1));
i2c_write(make8(addr, 0));
} |
As you can see, I'm using the 2nd port (pins D5 amd D6), which should use all the SSP2 registers and bits.
But now look at the listing file ...
Code: | .................... // define i2c hardware for the fram device
.................... #use i2c(MASTER,FAST,SDA=PIN_D5,SCL=PIN_D6,FORCE_HW)
*
02892: BCF F63.7 <--- SSP2CON1, WCOL bit
02894: BCF F9E.3 <--- PIR1, SSP1IF bit **** WRONG ****
02896: MOVFF 937,F66
0289A: MOVLW 02
0289C: BTFSC F63.7
0289E: BRA 28AA
028A0: BTFSS F9E.3 <--- PIR1, SSP1IF bit **** WRONG ****
028A2: BRA 28A0
028A4: MOVLW 00
028A6: BTFSC F62.6 <--- SSP2CON2, ACKSTAT bit
028A8: MOVLW 01
028AA: MOVWF 01
028AC: RETLW 00
*
028E4: BSF F62.3
028E6: BTFSC F62.3
028E8: BRA 28E6
028EA: BTFSC 00.0
028EC: BCF F62.5
028EE: BTFSS 00.0
028F0: BSF F62.5
028F2: BSF F62.4
028F4: BTFSC F62.4
028F6: BRA 28F4
028F8: MOVFF F66,01
028FC: RETLW 00
|
The code is clearly waiting for the SSP1IF bit which is associated with the *first* I2C channel.
Shouldn't the code be looking at the SSP2IF bit (located in PIR3) ?
Am I doing something wrong, or is this a bug ?
Mark |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 19, 2006 3:05 pm |
|
|
I think it's a bug. You should report it to CCS support.
If you do so, and your maintenance has run out, they
will usually let you download the fixed version when
it becomes available.
If you need the 2nd i2c port to work right now, you
will have to write your init function. Use the ASM
code in the .LST file as a guide, and re-write the CCS
code in C, using direct register access where needed.
Of course, fix the CCS bugs as you do it.
Example:
Quote: | (MASTER,FAST,SDA=PIN_D5,SCL=PIN_D6,FORCE_HW)
*
02892: BCF F63.7 <--- SSP2CON1, WCOL bit
02894: BCF F9E.3 <--- PIR1, SSP1IF bit *** WRONG ***
02896: MOVFF 937,F66
0289A: MOVLW 02
0289C: BTFSC F63.7
0289E: BRA 28AA
028A0: BTFSS F9E.3 <--- PIR1, SSP1IF bit *** WRONG ***
028A2: BRA 28A0
028A4: MOVLW 00
028A6: BTFSC F62.6 <--- SSP2CON2, ACKSTAT bit
|
Translate the above to C code:
Code: |
#byte PIR3 = 0xFA4
#bit SSP2IF = PIR3.7
#byte SSP2CON1 = 0xF63
#bit WCOL2 = SSP2CON1.7 // Call it "WCOL2"
void init_i2c_port2(void)
{
WCOL2 = 0;
SSP2IF = 0;
.
.
.
// etc.
}
|
You didn't mention problems with the i2c functions for the 2nd port,
such as i2c_write(), i2c_read(), etc. You may have to write your
own versions of those, two. If it's just the init code that's wrong,
you could call the fixed init routine at the start of main().
Also, the bad CCS code is doing things to the i2c port 1. I didn't
analyze it, but it's possible that you may need to write new code
for port 1 as well. Maybe it's better just to get CCS to fix it all. |
|
|
poynting Guest
|
Same Problem w/18f6722 |
Posted: Tue Jan 24, 2006 11:48 am |
|
|
I'm having what seems to be the same problem on a 18f6722. I need to use SSP1 for an SPI port (since I'm adding to a pre-existing PCB), so I need SSP2 for I2C. I sent an email to CCS support yesterday morning about this but haven't heard a response yet.
Code: |
.................... #use I2C(MASTER,SDA=PIN_D5,SCL=PIN_D6,SLOW,FORCE_HW)
*
22C2: BCF F63.7
22C4: BCF F9E.3
22C6: MOVFF 7E9,F66
22CA: MOVLW 02
22CC: BTFSC F63.7
22CE: BRA 22DA
22D0: BTFSS F9E.3
22D2: BRA 22D0
22D4: MOVLW 00
22D6: BTFSC F62.6
22D8: MOVLW 01
22DA: MOVWF 01
22DC: RETLW 00 |
|
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Thu Jan 26, 2006 4:21 am |
|
|
I have emailed CCS and I am also waiting for a response. |
|
|
Pete Guest
|
same issue here |
Posted: Thu Nov 30, 2006 11:58 pm |
|
|
I'm trying to use the second hardware ssp port on an 18f45j10. The compiler does not recognize the pins i am specifying as the hardware pins and is instead creating i2c software routines.
I noticed this thread from earlier in the year but there was no follow up.
I also sent an email to support a week ago but have received no response.
I'm wondering if someone here who dealt with the previous problem knows whether it was resolved. And if so, is this is a compiler problem or perhaps just something chip specific missing from the header file that would be an easy fix.
thanks,
Pete |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 01, 2006 12:22 am |
|
|
Quote: |
I'm trying to use the second hardware ssp port on an 18f45j10. The
compiler does not recognize the pins i am specifying as the hardware
pins and is instead creating i2c software routines. |
Post your #use i2c() statements and the version of your compiler. |
|
|
Pete Guest
|
|
Posted: Fri Dec 01, 2006 9:17 am |
|
|
Code: |
#include <18f45j10>
#fuses H4_SW,NOWDT
#use delay(clock=40,000,000)
#use i2c(slave,SDA=PIN_D1,SCL=PIN_D0,address=0x4e,FORCE_HW ) //port 2
//#use i2c(slave,SDA=PIN_C4,SCL=PIN_C3,address=0x4e,FORCE_HW) //port 1
|
In my app I'm actually using port 1 as SPI but after finding that Port 2 i2c hardware wasn't working I used the above code to demonstrate to myself that the compiled results for the two #use statements generates completely different code.
If you switch the comment marks from line to line you'll see how they compile differently. Removing the FORCE_HW doesn't affect the result.
I have compiler version 4.016
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 01, 2006 11:44 am |
|
|
I tested it, and I can confirm it doesn't use the hardware MSSP2 module.
You should report it to CCS support. Give them a compilable test
program and show a little bit of the .LST file, to explain the problem.
If your maintenance has run out, they'll let you download the fixed
version when they fix it. Give them your CCS user number.
If you have PCWH, maybe you could fix it with the Device Editor.
I don't have PCWH, so I don't know if it supports enabling the MSSP2
from the Device Editor.
If you need to get the 2nd MSSP running immediately, you'll have to
write your own routines. In the following thread, I try to help someone
write routines to use the MSSP2 for SPI mode. You could do something
similar for i2c.
http://www.ccsinfo.com/forum/viewtopic.php?t=22705
You'll have to write all these routines:
setup_i2c_mssp2()
i2c_start_mssp2()
i2c_stop_mssp2()
i2c_write_mssp2()
i2c_read_mssp2()
i2c_isr_state_mssp2()
i2c_poll_mssp2()
Here's some sample code for the i2c_isr_state() function.
It could help your function that works with the MSSP2.
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 |
|
|
Pete Guest
|
|
Posted: Fri Dec 01, 2006 12:29 pm |
|
|
thanks for the confirmation.
I reported this to support a week ago and was issued an identification number.
Every time I check it says that:
Your e-mail has been assigned to someone in C Tech Support.
As of yet, we have not had time to further review your e-mail.
Thanks |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Sat Dec 02, 2006 6:03 am |
|
|
Pete wrote: | I reported this to support a week ago and was issued an identification number. |
My original bug report has not yet been answered, and as you can see I reported it back in January this year so don't hold your breath !! |
|
|
Pete Guest
|
|
Posted: Sat Dec 09, 2006 8:07 pm |
|
|
To follow up on this issue, the problem, at least in regards to the 18f45j10 is now fixed as of PCH compiler version 4.017.
It correctly compiles using hardware based routines for the second I2C port.
Thanks
Pete |
|
|
|
|
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
|