Hello, > In the program with picc, the routines are included, and timing seems > ok. Perhaps the pull-up resistor is to strong (4.7k). I have joined my > small test program. About 1/20 up to 1/10 of my rom readings have a > bad CRC, and it's allways a bit wich is 1 and must have been 0. > Do You have any interrupts that can extend the delays. If You read one bit and it is a 0 and your delays are too long (due to an interrupt for example) you will read a 1. Also some notes on your code: > int16 read_tempe() > { > int i,crc,crc_calcul,entiere,virgule; > int t[9]; > int16 result; > if (touch_present()==TRUE){ > delay_ms(10); > i=touch_write_byte(SKIPROM); > delay_ms(10); > i=touch_write_byte(CONVERT); > // delay_ms(800); > } > else > return(10000); > if (touch_present()==TRUE){ You send a reset (touch_present) right after you issue the CONVERT_T command if the delay_ms(800) is commented out. > if (touch_present()==TRUE){ > i=touch_write_byte(SKIPROM); > delay_ms(10); > i=touch_write_byte(READSCRA); > delay_ms(10); > for (i=0;i<9;i++) { > t[i]=touch_read_byte(); > delay_ms(10); > } > i=touch_write_byte(SKIPROM); > delay_ms(10); > i=touch_write_byte(READSCRA); > delay_ms(10); > for (i=0;i<9;i++) { > t[i]=touch_read_byte() & t[i]; > delay_ms(10); > } > crc=t[8]; > crc_calcul=generate_8bit_crc(t,8); > } Why do you (attempt) to read the scratchpad twice and AND the two results together? The CRC in itself is enough to do error checking. Also You send two commands right after each other without having done a reset in between. Try removing the second read and put back the 800 ms delay after the CONVERT_T command. The delay_ms(10) is not needed between the bytes. 4.7k pullup is good. The internal pull up should not matter. Good Luck / Ruben ============================== Ruben Jvnsson AB Liros Elektronik Box 9124, 200 39 Malmv, Sweden TEL INT +46 40142078 FAX INT +46 40947388 ruben@pp.sbbs.se ============================== -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu