[En-Nut-Discussion] TWI aka I2C, not getting an ACK back?
Douglas Pearless
Douglas.Pearless at pearless.co.nz
Wed Mar 16 04:30:00 CET 2005
Hmm,
It appears that I have another problem!!!
I do not appear to actually write or read from the DS1337 RTC.
The READ bit on the address bit in the data on the I2C bus from the
Ethernut to the DS1337 never seems to get set (e.g. my readRTC routine)
( I am using a logic analyser to verify the I2C stream)
If I call the initRTC it sends out a stream of data on the I2C bus that
APPEARS to be OK, but the DS1337 does seem to change (e.g. the square
wave output doesn't change from 32768 Hz to 1Hz by writing 0x00 to
location 0x0E in the DS1337).
I am at a bit of a loss to explain things, I am call the TWTransact
routines correctly???
note 'sla' is 0x68 so that the <<1 in TwMasterTransact changes the
address to the correct 0xD0
ANY ideas?
Cheers Douglas
int readRTC(u_char sla,u_int addr,void *rxxdata,u_short len)
{
u_char adata[1];
adata[0] = (u_char) addr;
return TwMasterTransact(sla, adata, 1,rxxdata, len, 0);
}
int writeRTC(u_char sla,u_int addr,void *txdata,u_short len)
{
u_char data[17];
data[0] = (u_char)(addr);
memcpy(&data[1],txdata,len);
return TwMasterTransact(sla, data,len+1, 0, 0, 0);
}
int initRTC(u_char sla)
{
u_char dataRTC[15];
int rc;
dataRTC[0] = 0b00000000; // this should force the DS1337 to change
to a 1Hz square wave when written to 0x0E
dataRTC[1] = 0b00000000;
dataRTC[2] = 0b00000000;
rc = writeRTC(sla,0x0E,dataRTC,2); //on the i2c bus I get "<start>
110100000 <SDA goes high> 000000000 000000000 000000000<stop>
//where did the 0x0E go which should have been immediately after <SDA
goes high>
//I checked the wrteRTC routine and it does pass 0x0E 0x00 0x00 in the
'data field to TwMasterTransact
return rc;
}
int getRTCtime(u_char sla)
{
u_char dataRTC[12];
int rc;
rc = readRTC(sla,0,dataRTC,12); //on the i2c bus I get "<start>
110100000 011010001 <stop>
return rc;
}
Douglas Pearless wrote:
> Hi All,
>
> I have solved my problem.
>
> The lack of an ACK was for reasons unknown, I turned the unit off for
> a day and it started to work when I turned it back on, rather suspicious!
>
> Also one of my probes (a DSO watching the square wave output from the
> DS1337/DS1307 to verify I have turned on that output) was not properly
> grounded (a loose wire in the oscilloscope probe) and that
> intermittent worked.
>
> Cheers Douglas
>
>> Hi Harald,
>>
>> Yes I know about the 1 bit.
>>
>> I have traced further and found that I hadn't setup the speed
>> correctly (it was too fast, well over 400k!)
>>
>> Cheers Douglas
>>
>> Harald Kipp wrote:
>>
>>> Sure, that you used the 7-bit address?
>>>
>>> The Nut/OS twi driver will shift this left by one bit
>>> to include the R/W bit.
>>>
>>> Harald
>>>
>>> At 22:44 13.03.2005 +1300, you wrote:
>>>
>>>> Hi,
>>>>
>>>> I am trying to interface a DS1307 to the TWI.
>>>>
>>>> I send it the address, and do not get an acknowledge back (I used a
>>>> logic analyser to verify the return code I was getting in the
>>>> software).
>>>>
>>>> Any ideas (yes tried a DS1337 which has the same address too).
>>>>
>>>> Cheers Douglas
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> En-Nut-Discussion mailing list
>>> En-Nut-Discussion at egnite.de
>>> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
>>>
>> _______________________________________________
>> En-Nut-Discussion mailing list
>> En-Nut-Discussion at egnite.de
>> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
>>
> _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
>
More information about the En-Nut-Discussion
mailing list