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

I2C dreaming

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







I2C dreaming
PostPosted: Tue Nov 13, 2001 12:02 pm     Reply with quote

Hallo !!!

We had 2 pull up 10 k resistor and then with 2.2 k resistor but the sistem did not run.

Below there are the source codes of I2C master and slave, are they correct?

******** MASTER.C ********

#include <master.h>

void i2c_master(byte slave_address, byte data_i2c)
{
i2c_start();
i2c_write(slave_address);
i2c_write(data_i2c);
i2c_stop();
}


void main() {

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
enable_interrupts(global);

do {
i2c_master(0x0E, 23);
} while (TRUE);
}

*************** END ***********************

************ MASTER.H *********************

#include <16F877.h>
#device PIC16F877 *=16 ICD=TRUE
#use delay(clock=8000000)
#fuses HS,NOWDT,PUT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#use i2c(master,sda=PIN_C4,scl=PIN_C3, SLOW, NOFORCE_SW)

*********** END ***********************

************* SLAVE.C *****************

#include <slave.h>

byte dato_i2c;

#INT_SSP
void i2c_ricevi_da_master()
{
if(i2c_poll()==TRUE)
{
dato_i2c=i2c_read();
}
}

void main() {

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
enable_interrupts(INT_SSP);
enable_interrupts(global);

do {} while (TRUE);
}

***************** END *********************

*************** SLAVE.H ********************

#include <16F877.h>
#device PIC16F877 *=16 ICD=TRUE
#use delay(clock=8000000)
#fuses HS,NOWDT,PUT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#use I2C(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x0e, SLOW, NOFORCE_SW)

************ END **************************

Here there are the c/ASM master and slave codes:

********** MASTER *********************

CCS PCW C Compiler, Version 3.043, 11142

Filename: c:\programmi\picc\prove\i2c\master\master.LST

ROM used: 617 (8\%)
Largest free fragment is 2048
RAM used: 45 (12\%) at main() level
58 (16\%) worst case
Stack: 3 locations

*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 183
0003: NOP
.................... #include "C:\Programmi\PICC\Prove\i2c\master\master.h"
.................... #include <16F877.h>
.................... //////// Standard Header file for the PIC16F877 device ////////
.................... #device PIC16F877
.................... #list
....................
.................... #device *=16
.................... #use delay(clock=8000000)
*
013E: MOVLW 48
013F: MOVWF 04
0140: BCF 03.7
0141: MOVF 00,W
0142: BTFSC 03.2
0143: GOTO 151
0144: MOVLW 02
0145: MOVWF 78
0146: CLRF 77
0147: DECFSZ 77,F
0148: GOTO 147
0149: DECFSZ 78,F
014A: GOTO 146
014B: MOVLW 97
014C: MOVWF 77
014D: DECFSZ 77,F
014E: GOTO 14D
014F: DECFSZ 00,F
0150: GOTO 144
0151: RETLW 00
.................... #fuses HS,NOWDT,PUT
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
.................... #use i2c(master,sda=PIN_C4,scl=PIN_C3)
.................... #use I2C(master, sda=PIN_C4, scl=PIN_C3, SLOW, NOFORCE_SW)
*
0152: BCF 14.7
0153: BCF 0C.3
0154: MOVF 49,W
0155: MOVWF 13
0156: MOVLW 02
0157: BTFSC 14.7
0158: GOTO 160
0159: BTFSS 0C.3
015A: GOTO 159
015B: MOVLW 00
015C: BSF 03.5
015D: BTFSC 11.6
015E: MOVLW 01
015F: BCF 03.5
0160: MOVWF 78
0161: RETLW 00
....................
.................... void i2c_master(byte slave_address, byte data_i2c)
.................... {
.................... i2c_start();
0162: BCF 0D.3
0163: BCF 14.7
0164: BSF 03.5
0165: BSF 11.0
0166: BCF 03.5
0167: BTFSC 0D.3
0168: GOTO 162
0169: BTFSC 14.7
016A: GOTO 162
016B: BSF 03.5
016C: BTFSS 11.0
016D: GOTO 170
016E: BCF 03.5
016F: GOTO 16B
.................... i2c_write(slave_address);
0170: BCF 03.5
0171: MOVF 47,W
0172: MOVWF 49
0173: CALL 152
.................... i2c_write(data_i2c);
0174: MOVF 48,W
0175: MOVWF 49
0176: CALL 152
.................... i2c_stop();
0177: BSF 03.5
0178: BSF 11.2
0179: BCF 03.5
017A: BSF 03.5
017B: BTFSS 11.2
017C: GOTO 17F
017D: BCF 03.5
017E: GOTO 17A
017F: BCF 03.5
0180: BCF 0A.3
0181: BCF 0A.4
0182: GOTO 25A (RETURN)
.................... }
....................
....................
.................... void main() {
0183: CLRF 04
0184: BCF 03.7
0185: MOVLW 1F
0186: ANDWF 03,F
0187: MOVLW 9F
0188: MOVWF 04
0189: BCF 03.7
018A: MOVLW 07
018B: MOVWF 00
018C: MOVLW 0C
018D: BSF 03.5
018E: MOVWF 19
018F: MOVLW 22
0190: MOVWF 18
0191: MOVLW 90
0192: BCF 03.5
0193: MOVWF 18
0194: MOVLW FF
0195: MOVWF 20
0196: CLRF 23
0197: MOVLW 01
0198: MOVWF 24
0199: MOVLW 02
019A: MOVWF 25
019B: MOVLW 03
019C: MOVWF 26
019D: MOVLW 04
019E: MOVWF 27
019F: MOVLW 05
01A0: MOVWF 28
01A1: MOVLW 06
01A2: MOVWF 29
01A3: MOVLW 07
01A4: MOVWF 2A
01A5: MOVLW 08
01A6: MOVWF 2B
01A7: MOVLW 09
01A8: MOVWF 2C
01A9: MOVLW 0A
01AA: MOVWF 2D
01AB: MOVLW 0B
01AC: MOVWF 2E
01AD: MOVLW 0C
01AE: MOVWF 2F
01AF: MOVLW 0D
01B0: MOVWF 30
01B1: MOVLW 0E
01B2: MOVWF 31
01B3: MOVLW 0F
01B4: MOVWF 32
01B5: MOVLW 10
01B6: MOVWF 33
01B7: MOVLW 11
01B8: MOVWF 34
01B9: MOVLW 12
01BA: MOVWF 35
01BB: MOVLW 13
01BC: MOVWF 36
01BD: MOVLW 14
01BE: MOVWF 37
01BF: MOVLW 15
01C0: MOVWF 38
01C1: MOVLW 16
01C2: MOVWF 39
01C3: MOVLW 17
01C4: MOVWF 3A
01C5: MOVLW 18
01C6: MOVWF 3B
01C7: MOVLW 19
01C8: MOVWF 3C
01C9: MOVLW 1A
01CA: MOVWF 3D
01CB: MOVLW 1B
01CC: MOVWF 3E
01CD: MOVLW 1C
01CE: MOVWF 3F
01CF: MOVLW 1D
01D0: MOVWF 40
01D1: MOVLW 1E
01D2: MOVWF 41
01D3: MOVLW 1F
01D4: MOVWF 42
01D5: BCF 46.0
01D6: BCF 46.1
01D7: BCF 46.2
01D8: BSF 20.3
01D9: MOVF 20,W
01DA: BSF 03.5
01DB: MOVWF 07
01DC: BCF 03.5
01DD: BSF 20.4
01DE: MOVF 20,W
01DF: BSF 03.5
01E0: MOVWF 07
01E1: MOVLW 12
01E2: MOVWF 13
01E3: MOVLW 28
01E4: BCF 03.5
01E5: MOVWF 14
01E6: BSF 03.5
01E7: BSF 14.7
01E8: BCF 14.6
01E9: BCF 03.5
....................
.................... setup_adc_ports(NO_ANALOGS);
01EA: MOVLW 06
01EB: BSF 03.5
01EC: MOVWF 1F
.................... setup_adc(ADC_CLOCK_DIV_2);
01ED: BCF 03.5
01EE: MOVF 1F,W
01EF: ANDLW 38
01F0: IORLW 01
01F1: MOVWF 1F
.................... setup_spi(FALSE);
01F2: BCF 14.5
01F3: BCF 20.5
01F4: MOVF 20,W
01F5: BSF 03.5
01F6: MOVWF 07
01F7: BCF 03.5
01F8: BSF 20.4
01F9: MOVF 20,W
01FA: BSF 03.5
01FB: MOVWF 07
01FC: BCF 03.5
01FD: BCF 20.3
01FE: MOVF 20,W
01FF: BSF 03.5
0200: MOVWF 07
0201: MOVLW 00
0202: BCF 03.5
0203: MOVWF 14
0204: BSF 03.5
0205: MOVWF 14
.................... setup_psp(PSP_DISABLED);
0206: BCF 09.4
.................... setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
0207: CLRF 77
0208: CLRF 77
0209: BTFSC 77.3
020A: GOTO 20D
020B: BCF 03.5
020C: GOTO 217
020D: MOVLW 07
020E: BCF 03.5
020F: CLRF 01
0210: MOVLW 81
0211: MOVWF 04
0212: BCF 03.7
0213: MOVF 00,W
0214: ANDLW C0
0215: IORLW 0F
0216: MOVWF 00
0217: CLRWDT
0218: MOVLW 81
0219: MOVWF 04
021A: MOVF 00,W
021B: ANDLW C0
021C: IORWF 77,W
021D: MOVWF 00
.................... setup_timer_1(T1_DISABLED);
021E: CLRF 10
.................... setup_timer_2(T2_DISABLED,0,1);
021F: MOVLW 00
0220: BCF 03.0
0221: RLF 00,W
0222: MOVWF 77
0223: RLF 77,F
0224: RLF 77,F
0225: MOVLW F8
0226: ANDWF 77,F
0227: MOVF 77,W
0228: MOVWF 78
0229: MOVWF 12
022A: MOVLW 00
022B: BSF 03.5
022C: MOVWF 12
.................... setup_ccp1(CCP_OFF);
022D: ANDLW F8
022E: BTFSS 03.2
022F: GOTO 233
0230: BCF 03.5
0231: BCF 07.2
0232: BSF 03.5
0233: BCF 03.5
0234: CLRF 17
0235: CLRF 17
.................... setup_ccp2(CCP_OFF);
0236: MOVLW 00
0237: ANDLW F8
0238: BTFSC 03.2
0239: BCF 07.1
023A: CLRF 1D
023B: CLRF 1D
.................... enable_interrupts(INT_SSP);
023C: BSF 03.5
023D: BSF 0C.3
.................... enable_interrupts(global);
023E: MOVLW C0
023F: BCF 03.5
0240: IORWF 0B,F
....................
.................... do {
.................... display(1, 1, 1, 0);
0241: MOVLW 01
0242: MOVWF 47
0243: MOVWF 48
0244: MOVWF 49
0245: CLRF 4A
0246: CALL 07E
.................... delay_ms(300);
0247: MOVLW 02
0248: MOVWF 47
0249: MOVLW 96
024A: MOVWF 48
024B: CALL 13E
024C: DECFSZ 47,F
024D: GOTO 249
.................... if(input(PIN_C0)) i2c_master(0x0E, 23);
024E: BSF 20.0
024F: MOVF 20,W
0250: BSF 03.5
0251: MOVWF 07
0252: BCF 03.5
0253: BTFSS 07.0
0254: GOTO 25A
0255: MOVLW 0E
0256: MOVWF 47
0257: MOVLW 17
0258: MOVWF 48
0259: GOTO 162
.................... display(3, 3, 3, 0);
025A: MOVLW 03
025B: MOVWF 47
025C: MOVWF 48
025D: MOVWF 49
025E: CLRF 4A
025F: CALL 07E
.................... delay_ms(300);
0260: MOVLW 02
0261: MOVWF 47
0262: MOVLW 96
0263: MOVWF 48
0264: CALL 13E
0265: DECFSZ 47,F
0266: GOTO 262
.................... } while (TRUE);
0267: GOTO 241
.................... }
0268: SLEEP

****************** END *******************

************** SLAVE *********************

CCS PCW C Compiler, Version 3.043, 11142

Filename: c:\programmi\picc\prove\i2c\slave\slave.LST

ROM used: 630 (8\%)
Largest free fragment is 2048
RAM used: 54 (15\%) at main() level
68 (19\%) worst case
Stack: 4 worst case (3 in main + 1 for interrupts)

*
0000: NOP
0001: MOVLW 00
0002: MOVWF 0A
0003: GOTO 19A
0004: MOVWF 7F
0005: SWAPF 03,W
0006: BCF 03.5
0007: BCF 03.6
0008: MOVWF 21
0009: MOVF 0A,W
000A: MOVWF 20
000B: CLRF 0A
000C: MOVF 04,W
000D: MOVWF 22
000E: MOVF 77,W
000F: MOVWF 23
0010: MOVF 78,W
0011: MOVWF 24
0012: MOVF 79,W
0013: MOVWF 25
0014: MOVF 7A,W
0015: MOVWF 26
0016: MOVF 7B,W
0017: MOVWF 27
0018: BCF 03.7
0019: BCF 03.5
001A: MOVLW 8C
001B: MOVWF 04
001C: BTFSS 00.3
001D: GOTO 020
001E: BTFSC 0C.3
001F: GOTO 033
0020: MOVF 22,W
0021: MOVWF 04
0022: MOVF 23,W
0023: MOVWF 77
0024: MOVF 24,W
0025: MOVWF 78
0026: MOVF 25,W
0027: MOVWF 79
0028: MOVF 26,W
0029: MOVWF 7A
002A: MOVF 27,W
002B: MOVWF 7B
002C: MOVF 20,W
002D: MOVWF 0A
002E: SWAPF 21,W
002F: MOVWF 03
0030: SWAPF 7F,F
0031: SWAPF 7F,W
0032: RETFIE
0033: BCF 0A.3
0034: BCF 0A.4
0035: GOTO 036
.................... #include "C:\Programmi\PICC\Prove\i2c\slave\slave.h"
.................... #include <16F877.h>
.................... //////// Standard Header file for the PIC16F877 device ////////
.................... #device PIC16F877
.................... #list
....................
.................... #device PIC16F877 *=16 ICD=TRUE
.................... #use delay(clock=8000000)
*
0186: MOVLW 51
0187: MOVWF 04
0188: BCF 03.7
0189: MOVF 00,W
018A: BTFSC 03.2
018B: GOTO 199
018C: MOVLW 02
018D: MOVWF 78
018E: CLRF 77
018F: DECFSZ 77,F
0190: GOTO 18F
0191: DECFSZ 78,F
0192: GOTO 18E
0193: MOVLW 97
0194: MOVWF 77
0195: DECFSZ 77,F
0196: GOTO 195
0197: DECFSZ 00,F
0198: GOTO 18C
0199: RETLW 00
.................... #fuses HS,NOWDT,PUT
.................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
.................... #use I2C(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x0e, SLOW, NOFORCE_SW)
....................
.................... int dato_i2c=16;
....................
.................... #INT_SSP
.................... void i2c_ricevi_da_master()
.................... {
.................... if(i2c_poll()==TRUE)
*
0036: MOVLW 00
0037: BSF 03.5
0038: BTFSC 14.0
0039: MOVLW 01
003A: SUBLW 01
003B: BTFSC 03.2
003C: GOTO 03F
003D: BCF 03.5
003E: GOTO 048
003F: BCF 03.5
.................... {
.................... dato_i2c=i2c_read();
0040: BSF 03.5
0041: BTFSC 14.0
0042: GOTO 045
0043: BCF 03.5
0044: GOTO 040
0045: BCF 03.5
0046: MOVF 13,W
0047: MOVWF 4F
.................... }
0048: BCF 0C.3
0049: BCF 0A.3
004A: BCF 0A.4
004B: GOTO 020
.................... }
....................
.................... void main() {
*
019A: CLRF 04
019B: BCF 03.7
019C: MOVLW 1F
019D: ANDWF 03,F
019E: MOVLW 9F
019F: MOVWF 04
01A0: BCF 03.7
01A1: MOVLW 07
01A2: MOVWF 00
01A3: MOVLW 0C
01A4: BSF 03.5
01A5: MOVWF 19
01A6: MOVLW 22
01A7: MOVWF 18
01A8: MOVLW 90
01A9: BCF 03.5
01AA: MOVWF 18
01AB: MOVLW FF
01AC: MOVWF 28
01AD: BSF 28.3
01AE: MOVF 28,W
01AF: BSF 03.5
01B0: MOVWF 07
01B1: BCF 03.5
01B2: BSF 28.4
01B3: MOVF 28,W
01B4: BSF 03.5
01B5: MOVWF 07
01B6: MOVLW 0E
01B7: MOVWF 13
01B8: MOVLW 36
01B9: BCF 03.5
01BA: MOVWF 14
01BB: CLRF 2B
01BC: MOVLW 01
01BD: MOVWF 2C
01BE: MOVLW 02
01BF: MOVWF 2D
01C0: MOVLW 03
01C1: MOVWF 2E
01C2: MOVLW 04
01C3: MOVWF 2F
01C4: MOVLW 05
01C5: MOVWF 30
01C6: MOVLW 06
01C7: MOVWF 31
01C8: MOVLW 07
01C9: MOVWF 32
01CA: MOVLW 08
01CB: MOVWF 33
01CC: MOVLW 09
01CD: MOVWF 34
01CE: MOVLW 0A
01CF: MOVWF 35
01D0: MOVLW 0B
01D1: MOVWF 36
01D2: MOVLW 0C
01D3: MOVWF 37
01D4: MOVLW 0D
01D5: MOVWF 38
01D6: MOVLW 0E
01D7: MOVWF 39
01D8: MOVLW 0F
01D9: MOVWF 3A
01DA: MOVLW 10
01DB: MOVWF 3B
01DC: MOVLW 11
01DD: MOVWF 3C
01DE: MOVLW 12
01DF: MOVWF 3D
01E0: MOVLW 13
01E1: MOVWF 3E
01E2: MOVLW 14
01E3: MOVWF 3F
01E4: MOVLW 15
01E5: MOVWF 40
01E6: MOVLW 16
01E7: MOVWF 41
01E8: MOVLW 17
01E9: MOVWF 42
01EA: MOVLW 18
01EB: MOVWF 43
01EC: MOVLW 19
01ED: MOVWF 44
01EE: MOVLW 1A
01EF: MOVWF 45
01F0: MOVLW 1B
01F1: MOVWF 46
01F2: MOVLW 1C
01F3: MOVWF 47
01F4: MOVLW 1D
01F5: MOVWF 48
01F6: MOVLW 1E
01F7: MOVWF 49
01F8: MOVLW 1F
01F9: MOVWF 4A
01FA: BCF 4E.0
01FB: BCF 4E.1
01FC: BCF 4E.2
01FD: MOVLW 10
01FE: MOVWF 4F
....................
.................... setup_adc_ports(NO_ANALOGS);
01FF: MOVLW 06
0200: BSF 03.5
0201: MOVWF 1F
.................... setup_adc(ADC_CLOCK_DIV_2);
0202: BCF 03.5
0203: MOVF 1F,W
0204: ANDLW 38
0205: IORLW 01
0206: MOVWF 1F
.................... setup_spi(FALSE);
0207: BCF 14.5
0208: BCF 28.5
0209: MOVF 28,W
020A: BSF 03.5
020B: MOVWF 07
020C: BCF 03.5
020D: BSF 28.4
020E: MOVF 28,W
020F: BSF 03.5
0210: MOVWF 07
0211: BCF 03.5
0212: BCF 28.3
0213: MOVF 28,W
0214: BSF 03.5
0215: MOVWF 07
0216: MOVLW 00
0217: BCF 03.5
0218: MOVWF 14
0219: BSF 03.5
021A: MOVWF 14
.................... setup_psp(PSP_DISABLED);
021B: BCF 09.4
.................... setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
021C: CLRF 77
021D: CLRF 77
021E: BTFSC 77.3
021F: GOTO 222
0220: BCF 03.5
0221: GOTO 22C
0222: MOVLW 07
0223: BCF 03.5
0224: CLRF 01
0225: MOVLW 81
0226: MOVWF 04
0227: BCF 03.7
0228: MOVF 00,W
0229: ANDLW C0
022A: IORLW 0F
022B: MOVWF 00
022C: CLRWDT
022D: MOVLW 81
022E: MOVWF 04
022F: MOVF 00,W
0230: ANDLW C0
0231: IORWF 77,W
0232: MOVWF 00
.................... setup_timer_1(T1_DISABLED);
0233: CLRF 10
.................... setup_timer_2(T2_DISABLED,0,1);
0234: MOVLW 00
0235: BCF 03.0
0236: RLF 00,W
0237: MOVWF 77
0238: RLF 77,F
0239: RLF 77,F
023A: MOVLW F8
023B: ANDWF 77,F
023C: MOVF 77,W
023D: MOVWF 78
023E: MOVWF 12
023F: MOVLW 00
0240: BSF 03.5
0241: MOVWF 12
.................... setup_ccp1(CCP_OFF);
0242: ANDLW F8
0243: BTFSS 03.2
0244: GOTO 248
0245: BCF 03.5
0246: BCF 07.2
0247: BSF 03.5
0248: BCF 03.5
0249: CLRF 17
024A: CLRF 17
.................... setup_ccp2(CCP_OFF);
024B: MOVLW 00
024C: ANDLW F8
024D: BTFSC 03.2
024E: BCF 07.1
024F: CLRF 1D
0250: CLRF 1D
.................... enable_interrupts(INT_SSP);
0251: BSF 03.5
0252: BSF 0C.3
.................... enable_interrupts(global);
0253: MOVLW C0
0254: BCF 03.5
0255: IORWF 0B,F
....................
.................... dato_i2c=16;
0256: MOVLW 10
0257: MOVWF 4F
.................... do {
....................
.................... display(dato_i2c, 1, 1, 0);
0258: MOVF 4F,W
0259: MOVWF 50
025A: MOVLW 01
025B: MOVWF 51
025C: MOVWF 52
025D: CLRF 53
025E: CALL 0C6
.................... delay_ms(300);
025F: MOVLW 02
0260: MOVWF 50
0261: MOVLW 96
0262: MOVWF 51
0263: CALL 186
0264: DECFSZ 50,F
0265: GOTO 261
.................... display(dato_i2c, 3, 3, 0);
0266: MOVF 4F,W
0267: MOVWF 50
0268: MOVLW 03
0269: MOVWF 51
026A: MOVWF 52
026B: CLRF 53
026C: CALL 0C6
.................... delay_ms(300);
026D: MOVLW 02
026E: MOVWF 50
026F: MOVLW 96
0270: MOVWF 51
0271: CALL 186
0272: DECFSZ 50,F
0273: GOTO 26F
....................
.................... } while (TRUE);
0274: GOTO 258
.................... }
0275: SLEEP

****************** END ********************

IDE Version = 2.32
PCB Version = 3.043
PCM Version = 3.043
Thank you for the support. Best regards
___________________________
This message was ported from CCS's old forum
Original Post ID: 1085
Tomi
Guest







Re: I2C dreaming
PostPosted: Tue Nov 13, 2001 12:44 pm     Reply with quote

I have had a quick view on your code.
Your PICs are in Low Voltage Programming Mode. Probably the PIC is waiting for programming signals.
Insert the NOLVP keyword into the #fuses directive, e.g.
#fuses HS,NOWDT,PUT, NOLVP

Another problem:
The SPI and the I2C HW is common, so your line:
setup_spi(FALSE);
will disable the I2C hardware:
0216: MOVLW 00 // load NULL
0217: BCF 03.5
0218: MOVWF 14 // move to SSPCON

BTW, here are the lines to init the slave IIC you are looking for:
01B8: MOVLW 36 // as I wrote in previous post
01B9: BCF 03.5
01BA: MOVWF 14 // move to SSPCON
But, once more, your setup_spi(FALSE) call will overwrite this correct setting.

Additionally, the rest of your init lines at the top of the main() is unnecessary. PLEASE, see and read the "ex_slave.c" example! You can use it as a good base code to find out a "to do list".
In your case only the
setup_adc_ports(NO_ANALOGS);
is necessary (the default state of these pins are analog after startup).
Why write setup_adc(ADC_CLOCK_DIV_2) if no analog pins?
PSP, counters, CCP are disabled at startup.

Hope this helps.
Brg,
Tomi




___________________________
This message was ported from CCS's old forum
Original Post ID: 1087
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