I've now exhausted my new resources ;) Using debug statements I've figured out that the acknowledge bit never clears, as though the SRF08 never gets the transmission. Are there any recommendations anyone can make for debugging this further? How can I figure out if the problem is my code, the wiring, or the SRF08? The code is below. The problem first arises in the sub I2C_WriteW, it hangs while waiting for the acknowledge bit to clear. Thanks much, Ian ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; srf08.asm ; Controls an array of 8 SRF08 ultrasonic rangefinders ; ; by Ian Smith-Heisters ; February 26th, 2005: Started ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; title "SRF08 Control" List p=18f452,f=inhx32 #include ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Configuration ;The config aliases are already defined in the 18f452 header file. __CONFIG _CONFIG1H, _OSCS_ON_1H & _XT_OSC_1H ; External Clock on OSC1 & OSC2 __CONFIG _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_OFF_2L ; Brown out reset on at 2.0V, no power-up timer __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H ; watchdog off, postscaler count to 128 __CONFIG _CONFIG3H, _CCP2MX_ON_3H ; CCP2 pin Mux enabled. What is this? __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_ON_4L & _DEBUG_OFF_4L ; Stack under/overflow reset on, LVP on, debug off __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L ; all protection off __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L __CONFIG _CONFIG7H, _EBTRB_OFF_7H ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Variable Definitions ; Define Constants #define DELIMETER ' ' #define EOL '\n' ; Define variables cblock 0x000 count1 ; count variables. Useful for loops etc. count2 count3 char ; a holder for a single character NumH ; digit variables for sending 10 bit hex NumL ; numbers as decimal TenK Thou Hund Tens Ones endc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Macro Definitions mov MACRO litval, file ; move a literal directly to a register movlw litval movwf file endm _encda MACRO x ; encode in ASCII movlw 0x30 addwf x, F endm _puts MACRO s ; output a NUL-terminated inline string call putstrpc dw s endm _i2c_write MACRO x ; write x on the I2C bus movlw x call I2C_WriteW endm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Vectors org 0x0000 ; reset vector Start goto Init org 0x0008 ; high priority interrupt vector Interrupt1 goto HighInterrupt org 0x0018 ; low priority interrupt vector Interrupt2 goto LowInterrupt ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Initialize Init bsf RCON, IPEN ; enable interrupt priorities clrf TRISD ; Set port D to all output for LED call UART_Init ; call initialization subs call I2C_Init goto Main ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Main loop Main _puts "beginning...\n\r\0" ;; Start ranging call I2C_Start _i2c_write 0xE0 ; slave's address _i2c_write 0x00 ; command register _i2c_write 0x50 ; start ranging in inches call I2C_Stop call del_5msec _puts "reached debug point 1\n\r" ;; Read results call I2C_Start _i2c_write 0xE0 ; slave's address _i2c_write 0x02 ; first read address call I2C_Restart _i2c_write 0xE1 ; slave's read address _puts "reached debug 2\n\r\0" call I2C_Receive _puts "reached debug 3\n\r\0" call I2C_Stop _puts "reached debug 4\n\r\0" call I2C_Print goto Main ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Interrupt Handling ;; High Interrupt HighInterrupt _puts "High priority interrupt triggered.\n\r\0" retfie 0 goto Start ;; Low Interrupt LowInterrupt _puts "Low priority interrupt triggered.\n\r\0" retfie 0 goto Start ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Subroutine Definitions #include ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; I2C ;; Initialize the PIC I2C I2C_Init mov b'00011000', TRISC ; SDA and SCL to I2C mov b'00101000', SSPCON1 ; I2C on, set to master mov b'10000000', SSPSTAT ; slew disabled: standard speed control mov 0x09, SSPADD ; 100kHz @ 4MHz bsf TRISC, SCL ; I2C SCL pin is input bsf PORTC, SCL ; (will be controlled by SSP) bsf TRISC, SDA ; I2C SDA pin is input bsf PORTC, SDA ; (will be controlled by SSP) return ;; Send an I2C start sequence I2C_Start bsf SSPCON2, SEN ; start sequence i2cstart btfsc SSPCON2, SEN bra i2cstart return ;; Repeat an I2C start sequence I2C_Restart bsf SSPCON2, RSEN ; repeated start sequence i2crestart btfsc SSPCON2, RSEN bra i2crestart return ;; Send an I2C stop sequence I2C_Stop bsf SSPCON2, PEN ; stop bit i2cstop btfsc SSPCON2, PEN bra i2cstop return ;; Write the WREG to the I2C bus I2C_WriteW bcf PIR1, SSPIF ; clear interrupt flag movwf SSPBUF ; load byte and send i2cwritew1 btfss PIR1, SSPIF ; send complete? bra i2cwritew1 i2cwritew2 btfsc SSPCON2, ACKSTAT ; acknowledge received? bra i2cwritew2 return ;; Receive a byte over I2C I2C_Receive bcf PIR1, SSPIF ; clear interrupt flag bsf SSPCON2, RCEN ; enable reception i2creceive1 btfss PIR1, SSPIF ; byte received bra i2creceive1 bsf SSPCON2, ACKDT bsf SSPCON2, ACKEN ; send acknowledge i2creceive2 btfsc SSPCON2, ACKEN ; sent? bra i2creceive2 return ;; Print a value from the I2C via UART I2C_Print _puts "sensor value: \0" movff SSPBUF, Ones _encda Ones movff Ones, W call UART_Put _puts "\n\r" return ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Delays ;; A 1 millisecond delay @ 4MHz del_1msec mov d'16', count2 loop1 mov d'250', count1 decfsz count1, F bra loop1 decfsz count2, F bra loop1 return ;; A 5 msec (+~ .5 msec) delay based on del_1msec del_5msec mov d'5', count3 call del_1msec decfsz count3, F bra $-2 return ;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Strings ;; print NUL-terminated string at TBLPTR ;; from http://forum.microchip.com/tm.asp?m=69235 putstrtail: loop: tblrd *+ movf TABLAT,w bz done rcall UART_Put bra loop done:return ;; print NUL-terminated string at PC putstrpc: movff TOSU,TBLPTRU movff TOSH,TBLPTRH movff TOSL,TBLPTRL putstr2:rcall putstrtail ; adjust return address to after end of string fixuppc:btfsc TBLPTRL,0 ; is ptr odd? tblrd *+ ; yes, bump it by one movf TBLPTRU,w ; copy to return PC movwf TOSU ; ** cannot use movff ** movf TBLPTRH,w movwf TOSH movf TBLPTRL,w movwf TOSL return ; Binary (16-bit) to BCD. From Microchip PICDEM 2 PLUS DEMO BOARD ; xxx = highest possible result bin16_bcd: ; Takes number in NumH:NumL ; Returns decimal in TenK:Thou:Hund:Tens:Ones swapf NumH,W andlw 0x0F addlw 0xF0 movwf Thou addwf Thou,F addlw 0xE2 movwf Hund addlw 0x32 movwf Ones movf NumH,W andlw 0x0F addwf Hund,F addwf Hund,F addwf Ones,F addlw 0xE9 movwf Tens addwf Tens,F addwf Tens,F swapf NumL,W andlw 0x0F addwf Tens,F addwf Ones,F rlcf Tens,F rlcf Ones,F comf Ones,F rlcf Ones,F movf NumL,W andlw 0x0F addwf Ones,F rlcf Thou,F movlw 0x07 movwf TenK movlw 0x0A ; Ten Lb1: decf Tens,F addwf Ones,F btfss STATUS,C bra Lb1 Lb2: decf Hund,F addwf Tens,F btfss STATUS,C bra Lb2 Lb3: decf Thou,F addwf Hund,F btfss STATUS,C bra Lb3 Lb4: decf TenK,F addwf Thou,F btfss STATUS,C bra Lb4 return end -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist