hi all, I am a relatively new PIC user. I am using the PIC16F876 with a 4Mhz Crystal. I was trying to get the MSSP module on the pic to communicate with a I2C EEPROM (Atmel 24c16). I tried writing the program myself, but it did not work. So i looked up the FAQs on this list, and came up with a program. I modified it a little to suit my needs. It still refused to work. I isolated the error to the point where I set up SEN in SSPCON2. I have attached the relevant parts of the program. 103 start_i2c MACRO ;[S] 104 Bank0 105 movlw 's' 106 movwf TXREG 107 call Dlay 108 bcf PIR1,SSPIF 109 Bank1 ;bank1 110 bsf SSPCON2,SEN ;send i2c START [S] bit 111 Bank0 ;bank0 112 movlw ',' 113 movwf TXREG 114 call Dlay 115 movlw ',' 116 movwf TXREG 117 btfss PIR1,SSPIF ;start bit cycle complete? 118 goto $-2 119 movlw 'S' 120 movwf TXREG 121 call Dlay 122 endm 123 124 enable_receive_i2c MACRO 125 Bank1 ;bank1 126 bsf SSPCON2,RCEN ;enable receiving at master 16f876 127 Bank0 ;bank0 128 bcf PIR1,SSPIF 129 btfss PIR1,SSPIF ;sspbuf buffer full byte? 130 goto $-1 131 endm 132 133 stop_i2c MACRO ;[P] 134 Bank0 ;bank0 135 bcf PIR1,SSPIF 136 Bank1 ;bank1 137 bsf SSPCON2,PEN ;send i2c STOP [P] bit 138 Bank0 ;bank0 139 btfss PIR1,SSPIF ;stop bit cycle completed? 140 goto $-1 141 endm 142 143 wait_for_ack_i2c MACRO 144 Bank0 ;bank0 145 movlw 'w' 146 movwf TXREG 147 call Dlay 148 bcf PIR1,SSPIF 149 btfss PIR1,SSPIF ;ACK received? 150 goto $-1 151 movlw 'W' 152 movwf TXREG 153 call Dlay 154 endm 155 156 setup_i2c MACRO ;setup mssp for i2c 157 movlw '+' 158 movwf TXREG 159 call Dlay 160 movlw 0x28 161 movwf SSPCON 162 Bank1 163 movlw 0x80 164 movwf SSPSTAT 165 movlw 0x60 166 movwf SSPCON2 167 movlw 9 168 movwf SSPADD 169 Bank0 170 movlw '*' 171 movwf TXREG 172 call Dlay 173 endm 174 175 read_mem MACRO 176 start_i2c 177 movlw 0xA1 178 movwf SSPBUF 179 wait_for_ack_i2c 180 enable_receive_i2c 181 movf SSPBUF,W 182 movwf mem_rd_data 183 stop_i2c 184 endm 185 186 write_mem MACRO 187 start_i2c 188 movlw 0xA0 189 movwf SSPBUF 190 wait_for_ack_i2c 191 movf mem_wr_data,W 192 movwf SSPBUF 193 wait_for_ack_i2c 194 stop_i2c 195 endm 196 197 loop 198 setup_i2c 199 loop2 200 movlw 'a' 201 movwf TXREG 202 call Dlay 203 movwf mem_wr_data 204 write_mem 205 movlw '-' 206 movwf TXREG 207 call Dlay 208 read_mem 209 movf mem_rd_data,W 210 movwf TXREG 211 call Dlay 212 goto loop2 the error occurs when we set the SSPCON2,SEN and then wait for SSPIF to be set. The flag is never set, and the program goes into an infinte loop. Please see lines numbered 117,118. The USART communications are for me to know what th pic is doing currently and do not have any other pupose as such. I just can't make out where i am going wrong. I would be thankful to anyone who could suggest corrections to the above code, or maybe give me a better way to use the MSSP. Thanking all in advance. -- Sirish.K.A DeepRoot Linux Pvt. Ltd. Yelahanka Bangalore -560064 Ph : +91(80)8565624 -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads