|
|
View previous topic :: View next topic |
Author |
Message |
agrj
Joined: 26 Sep 2003 Posts: 48
|
I2C, PIC18F8720 and force_hw |
Posted: Wed Jan 14, 2004 6:00 am |
|
|
Hi,
after some hours trying to put my I2C bus to work I found a bug in CCS compiler.
when you try to use I2C with force_hw it gets stuck. the only way to use I2C with PC18F8720 (at least was what I found) is by software (without force_hw flag).
anyone knows why?
thanks
Dinho |
|
|
SteveS
Joined: 27 Oct 2003 Posts: 126
|
I2C, 18F8720, and force_hw |
Posted: Wed Jan 14, 2004 7:29 am |
|
|
I don't use the 18F8720 but I do use the 18F6720 which is the same but without the external bus feature. I am using I2C with FORCE_HW very heavily and it seems to work fine.
What version compiler do you have? I'm using 3.182. I find that if you have one of the first versions to support a new CPU there are frequently problems with peripherals. Thankfully they usually get straightened out quickly in follow on versions.
You can try compiling for an 18F6720 and comparing the generated I2C code with the 18F8720 compile to see if there are differences.
Good luck.... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jan 14, 2004 8:12 am |
|
|
It is hard to say without a code snippet demonstrating the problem. However, a typical problem that some people make is that they forget to add pullups to the data and clock lines. These are needed. |
|
|
agrj
Joined: 26 Sep 2003 Posts: 48
|
I2C, PIC18F8720 and force_hw |
Posted: Wed Jan 14, 2004 8:21 am |
|
|
Hi,
One thing I have found is that when I use force_hw, the SSPCON1 is not initialized. the code generated was:
112: void main() {
113:
000E1C 06AF8 CLRF 0xff8, ACCESS
000E1E 09ED0 BCF 0xfd0, 0x7, ACCESS
000E20 08E0D BSF 0xd, 0x7, ACCESS
000E22 00EFE MOVLW 0xfe
000E24 06E00 MOVWF 0, ACCESS
000E26 00E0F MOVLW 0xf
000E28 06E01 MOVWF 0x1, ACCESS
000E2A 06AEA CLRF 0xfea, ACCESS
000E2C 00E02 MOVLW 0x2
000E2E 06EE9 MOVWF 0xfe9, ACCESS
000E30 06AEF CLRF 0xfef, ACCESS
000E32 02AE9 INCF 0xfe9, F, ACCESS
000E34 0B4D8 BTFSC 0xfd8, 0x2, ACCESS
000E36 02AEA INCF 0xfea, F, ACCESS
000E38 02E00 DECFSZ 0, F, ACCESS
000E3A 0EF18 GOTO 0xe30
000E3E 02E01 DECFSZ 0x1, F, ACCESS
000E40 0EF18 GOTO 0xe30
000E44 06AEA CLRF 0xfea, ACCESS
000E46 06AE9 CLRF 0xfe9, ACCESS
000E48 00E0F MOVLW 0xf
000E4A 06EC1 MOVWF 0xfc1, ACCESS
000E4C 00E07 MOVLW 0x7
000E4E 06EB4 MOVWF 0xfb4, ACCESS
000E50 08694 BSF 0xf94, 0x3, ACCESS
000E52 08894 BSF 0xf94, 0x4, ACCESS
000E54 06AC8 CLRF 0xfc8, ACCESS
000E56 00E28 MOVLW 0x28
000E58 06EC6 MOVWF 0xfc6, ACCESS
000E5A 08EC7 BSF 0xfc7, 0x7, ACCESS
000E5C 09CC7 BCF 0xfc7, 0x6, ACCESS
000E5E 09A94 BCF 0xf94, 0x5, ACCESS
000E60 09A8B BCF 0xf8b, 0x5, ACCESS
114: setup_adc_ports(NO_ANALOGS); // desabilita entradas anal�gicas
but even if i do it manually, its not working.
any other comments? |
|
|
agrj
Joined: 26 Sep 2003 Posts: 48
|
|
Posted: Wed Jan 14, 2004 8:23 am |
|
|
Mark wrote: | It is hard to say without a code snippet demonstrating the problem. However, a typical problem that some people make is that they forget to add pullups to the data and clock lines. These are needed. |
I have those pull-ups. when I run the software without force_hw, it works, but doing like this the SSPCONx registers are not updated.
thanks
Dinho |
|
|
agrj
Joined: 26 Sep 2003 Posts: 48
|
I2C, PIC18F8720 and force_hw |
Posted: Wed Jan 14, 2004 8:50 am |
|
|
Hi,
after some tries, I could set the PIC18F8720 to hardware I2C mode. I included the folowing lines:
#byte SSPCON1 = 0x0FC6
SSPCON1 = 0b00101000;
now, I'm trying the sequence:
I2C_start();
I2C_write(0x0A);
I2C_write(0x0F);
I2C_Stop();
well,
I2C_start() works fine, but I2C_write() get stuck checking PIR1.SSPIF. this shoud be set by hardware, but looks like it's not.
any ideas?
thanks
Dinho |
|
|
agrj
Joined: 26 Sep 2003 Posts: 48
|
I2C, PIC18F8720 and force_hw |
Posted: Wed Jan 14, 2004 10:26 am |
|
|
Hi,
one more question, do I have to set the Baud rate? where?
thanks
Dinho |
|
|
SteveS
Joined: 27 Oct 2003 Posts: 126
|
i2c, 18f8720, force_hw |
Posted: Wed Jan 14, 2004 11:46 am |
|
|
What compiler version are you using?
As far as baud, the #use I2C has a SLOW and FAST option to set one of two speeds. I forget which is used by default. You may want to try forcing SLOW in case it's a peripheral that can't do FAST that's hanging you up.
- Steve |
|
|
agrj
Joined: 26 Sep 2003 Posts: 48
|
|
Posted: Wed Jan 14, 2004 11:49 am |
|
|
Hi,
I'm using CCS 3.184. my problem now is regarding PIR1.SSPIF. I don't know why it's no set when I write something in SSPBUF.
Thanks
Dinho |
|
|
SteveS
Joined: 27 Oct 2003 Posts: 126
|
i2c, 18f8720, force_hw |
Posted: Wed Jan 14, 2004 12:41 pm |
|
|
Using V3.182:
I compiled for the 18f6720 (which works) and then for 18F8720
- they look identical, does it match your output?
Compiled for 18F6720:
.................... #use I2C(master, sda=PIN_C4, scl=PIN_C3, FORCE_HW)
*
1342: BCF FC6.7
1344: BCF F9E.3
1346: MOVFF 214,FC9
134A: MOVLW 02
134C: BTFSC FC6.7
134E: GOTO 135E
1352: BTFSS F9E.3
1354: GOTO 1352
1358: MOVLW 00
135A: BTFSC FC5.6
135C: MOVLW 01
135E: MOVWF 01
1360: RETLW 00
*
4184: BSF FC5.3
4186: BTFSC FC5.3
4188: GOTO 4186
418C: BTFSC 00.0
418E: BCF FC5.5
4190: BTFSS 00.0
4192: BSF FC5.5
4194: BSF FC5.4
4196: BTFSC FC5.4
4198: GOTO 4196
419C: MOVFF FC9,01
41A0: RETLW 00
....................
Compiled for 18F8720:
.................... #use I2C(master, sda=PIN_C4, scl=PIN_C3, FORCE_HW)
*
1342: BCF FC6.7
1344: BCF F9E.3
1346: MOVFF 214,FC9
134A: MOVLW 02
134C: BTFSC FC6.7
134E: GOTO 135E
1352: BTFSS F9E.3
1354: GOTO 1352
1358: MOVLW 00
135A: BTFSC FC5.6
135C: MOVLW 01
135E: MOVWF 01
1360: RETLW 00
*
4184: BSF FC5.3
4186: BTFSC FC5.3
4188: GOTO 4186
418C: BTFSC 00.0
418E: BCF FC5.5
4190: BTFSS 00.0
4192: BSF FC5.5
4194: BSF FC5.4
4196: BTFSC FC5.4
4198: GOTO 4196
419C: MOVFF FC9,01
41A0: RETLW 00
.................... |
|
|
agrj
Joined: 26 Sep 2003 Posts: 48
|
|
Posted: Wed Jan 14, 2004 12:53 pm |
|
|
Hi,
it looks like the same. I had one line : setup_SPI(False) that was overwriting the SSPCON configuration.
I just erase that, and now the initializtion and I2C_START are working correct. although, when I try to write something, for example, I2C_WRITE(0x0A), the program get stuck at line 9CC and 9CE below.
2: #use i2c(Master,fast,sda=PIN_C4,scl=PIN_C3,restart_wdt,noforce_sw)
0009BC 09EC6 BCF 0xfc6, 0x7, ACCESS
0009BE 0969E BCF 0xf9e, 0x3, ACCESS
0009C0 0C0D0 MOVFF 0xd0, 0xfc9
0009C4 00E02 MOVLW 0x2
0009C6 0BEC6 BTFSC 0xfc6, 0x7, ACCESS
0009C8 0EFEC GOTO 0x9d8
0009CC 0A69E BTFSS 0xf9e, 0x3, ACCESS
0009CE 0EFE6 GOTO 0x9cc
0009D2 00E00 MOVLW 0
0009D4 0BCC5 BTFSC 0xfc5, 0x6, ACCESS
0009D6 00E01 MOVLW 0x1
0009D8 06E01 MOVWF 0x1, ACCESS
0009DA 00C00 RETLW 0
0xf9e is PIR1 and bit 0x3 is SSPIF. it should be set when something is writen in SSPBUF, but I don't know why it's not happening.
any idea?
thanks
Dinho |
|
|
agrj
Joined: 26 Sep 2003 Posts: 48
|
|
Posted: Tue Jan 20, 2004 10:06 am |
|
|
Til now I couldn't find why it's happening!!!
any idea?
thanks |
|
|
agrj
Joined: 26 Sep 2003 Posts: 48
|
|
Posted: Tue Jan 20, 2004 2:20 pm |
|
|
I found the problem. it's me!!! I need a slave to ACK a master transmition!!!!
you can call me dumb!!!
I just simulate an ACK, and everything is working well.
thanks |
|
|
|
|
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
|