View previous topic :: View next topic |
Author |
Message |
O-Family
Joined: 23 May 2010 Posts: 320 Location: Japan
|
Posted: Wed Oct 18, 2017 3:53 am Post subject: I2C Clock Stretching problem |
|
|
I am using the CCS811 CO2/VOC sensor.
In the "I2creceive" instruction, hardware TWI has no problem.
When software I2C is used, when clock stretch occurs, repeated start condition becomes abnormal and data can not be read out.
Is there a solution?
By the way, once issue a stop condition and use "I2crbyte" can read it normally.
It is unstable because I think it is a solution due to waiting time.
Code: |
$lib "i2c_TWI.LBX" 'For TWI setting.
Config Twi = 100000
Config Scl = Portc.5
Config Sda = Portc.4
I2cinit
$lib "i2cV2.LBX" 'For softwareI2C setting.
Config Scl = Portd.2
Config Sda = Portd.3
Config I2cdelay = 1
I2cinit
I2cbuff(1) = &H00 'CCS811 Status read.
I2creceive Ccs811_adr , I2cbuff(1) , 1 , 1
|
(BASCOM-AVR version : 2.0.8.0 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Wed Oct 18, 2017 3:27 pm Post subject: |
|
|
If soft-I2C does not support clock-stretching, simply insert a wait-SCL-low loop before calling I2CStop. Maybe add a timeout to the loop. |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
|
Back to top |
|
|
O-Family
Joined: 23 May 2010 Posts: 320 Location: Japan
|
Posted: Thu Oct 19, 2017 1:38 am Post subject: |
|
|
Everyone, thank you for advice.
Even in other posts, it was written that softwareI2C corresponds to Clock Stretching.
However, I think that it does not correspond to the repeated start condition.
After transmitting the register address, I also know how to issue a stop condition, wait with "Wait" or wait until SLC goes high and use "I2crbyte" to read it.
However, this method should use the "I2cstart","I2cwbyte","I2cstop" instructions when the slave device demands an operation different from the general purpose I2C.
Actually, the "I2creceive" command works normally in TWI, but in softwareI2C it will become abnormal, I can not understand it.
If I cope with such first-aid measures that wait for SCL to go high, I think users will be troubled with the same problem. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Thu Oct 19, 2017 8:35 am Post subject: |
|
|
you ask for a solution and you get some.
you probably mean : is there a new version of this lib/lbx.
If you feel there is a bug, you should contact support. Only then you can be sure that it will be checked.
This forum is for/by users. It is not the official support system.
Once in a while i read the forum and i answer random.
ok, to the problem :
In the lib find this label : _i2c_rep_start
then replace this :
; then make clock 1 too
* cbi _sclDDR,_SCL ; release SCL to make it 1
by :
; then make clock 1 too
rcall _release_scl
and save and compile the lib using Lib Manager _________________ Mark |
|
Back to top |
|
|
O-Family
Joined: 23 May 2010 Posts: 320 Location: Japan
|
Posted: Fri Oct 20, 2017 1:01 am Post subject: |
|
|
Thanks for the reply.
After listening to the power user, if I can be sure that it is a bug, I will contact support.
I think it is important to discuss at the forum and keep records.
That's because the same problematic user will repeat the same question until the problem is found and version upgrade is offered. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Sun Oct 22, 2017 8:09 pm Post subject: |
|
|
sure you can discuss it here.
I classify it as a bug and fixed it the way i described. _________________ Mark |
|
Back to top |
|
|
|