Mar 18, 2011 #1 N Navid T Full Member level 3 Joined Jan 21, 2005 Messages 186 Helped 1 Reputation 2 Reaction score 0 Trophy points 1,296 Location Iran Activity points 1,385 Hi friends I write this kind of code to send start bit and address to slave: Code: _SEN=1; while(_SEN); I2CTRN = 0B11010000; while(_TRSTAT); It works but the problem is if slave doesn't send ack it'll always wait for ack for ever, how should i write my code that wait for ack but not always? Regards
Hi friends I write this kind of code to send start bit and address to slave: Code: _SEN=1; while(_SEN); I2CTRN = 0B11010000; while(_TRSTAT); It works but the problem is if slave doesn't send ack it'll always wait for ack for ever, how should i write my code that wait for ack but not always? Regards
Mar 18, 2011 #2 R raco_rage Member level 3 Joined Mar 14, 2011 Messages 61 Helped 18 Reputation 36 Reaction score 18 Trophy points 1,288 Activity points 1,601 Code: int counter_i2c = 0xFFFF; while((_TRSTAT == 0) && (counter_i2c != 0)) counter_i2c--; Obviously you can change the counter_i2c value depending on how long you want to wait.
Code: int counter_i2c = 0xFFFF; while((_TRSTAT == 0) && (counter_i2c != 0)) counter_i2c--; Obviously you can change the counter_i2c value depending on how long you want to wait.