View previous topic :: View next topic |
Author |
Message |
syndetic1
Joined: 02 Jan 2007 Posts: 76
|
Posted: Mon Mar 26, 2018 9:55 pm Post subject: I2C Hardware Hang |
|
|
I am using an ATMEGA 128 as the I2C master connected to a slave device.
I am using the hardware I2C
The slave gets 5V power separately. If the slave has no power then both SDA and SCL are low because the I2C pullups are powered by the slave 5V.
With the slave OFF, The program hangs (See below)
What ways are there to detect a I2C hang and how to recover from it.
Are there bits in a register somewhere that clears the TWI.
Does the TWI / I2C use interrupts
Thanks in advance
Code: | $LIB "I2CV2.LIB"
Config Sda = Portd.1
Config Scl = Portd.0
I2cinit
config TWI = 100000 ' Configure TWI clock frequency for $lib "I2C_TWI.LBX"
I2cstart
Locate 1,1
LCD "Done I2start" '<- This works
I2cwbyte &H1C ' Address 14
Locate 1,1
LCD "Done Address 14 " '<- This never works
I2cwbyte &HE3 ' Set PPS Page 122
I2cwbyte Tic_1
I2cwbyte Tic_2
I2cwbyte Tic_3
I2cwbyte Tic_4
I2cstop |
(BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.8.1 ) |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Tue Mar 27, 2018 11:54 am Post subject: |
|
|
Pull up to Vcc is mandatory to I2C, no exception. Even when there is no slave attached. So hanging is not a software issue.
Design your hardware in a way where the pull ups are supplied from the master's Vcc. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
syndetic1
Joined: 02 Jan 2007 Posts: 76
|
Posted: Wed Mar 28, 2018 12:58 am Post subject: I2C Hardware Hang - ERR Flag |
|
|
Hi EDC,
I replicated your program and I agree it works. The I2CSTOP needs to be inside the "IF" statement as you note.
I will use this for the moment.
I suspect though that IF the power to my I2C slave and it's pull up resistors drops out at exactly the wrong time during a I2C communications then it may hang. But this for now makes the system a whole lot better.
Thank you |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Mar 28, 2018 7:33 am Post subject: |
|
|
You can always use Watchdog for those worst cases but I take a look into the TWI lib and I saw curious thing.
If you declare "Const _TWI_STOP_TIMEOUT = 1" in the code then compiler add timeout for I2cStop routine and whole code will be safe.
I wish you good day |
|
Back to top |
|
|
syndetic1
Joined: 02 Jan 2007 Posts: 76
|
Posted: Thu Mar 29, 2018 2:13 am Post subject: |
|
|
Hi EDC,
Thank you for the tip about "Const _TWI_STOP_TIMEOUT = 1"
I have opened
C:\Program Files (x86)\MCS Electronics\BASCOM-AVR\LIB\
i2c_TWI.LBX
and
i2c_TWI.lib
I don't find "TWI_STOP_TIMEOUT" anywhere.
In fact I used the find-in-files feature of notepad++ to search all the MCS Electronics files for TWI_STOP_TIMEOUT and I get no hits.
Can you show me where you found it?
Thanks in advance. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Thu Mar 29, 2018 7:09 am Post subject: |
|
|
I check this and this Timeout was added in 2080 version. So if you have registered version simply go to the Updates tab on the www.mcselec.com site and download newest version. |
|
Back to top |
|
|
syndetic1
Joined: 02 Jan 2007 Posts: 76
|
Posted: Mon Apr 09, 2018 1:59 am Post subject: |
|
|
Thank you EDC works a treat. |
|
Back to top |
|
|
|