The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
Hello everybody.I´m new in the forum but i would be very glad if somebody could help me. I´m trying to read the seven registers of the DS1307 where there are the time values of this RTC. The registers go from 0x00 to 0x06.I have the SDA pin conected to my Netduino´s Analog pin 4 and the SCL pin to my Netduino´s Analog pin 5. The way i see if the operations are well done, is to see how much data is transfered by the bus only to see if something has bee read. It always gives me 0 data read. The code is the next:
Please, i´ve been 3 days with it and i can´t find a solution.
namespace I2C_RTC
{
public class Program
{
public static void Main()
{
byte[] buffer_read = new byte[7];
byte[] buffer_write = new byte[1];
I2CDevice.Configuration config = new I2CDevice.Configuration(0x68, 100);
I2CDevice RTC = new I2CDevice(config);
buffer_write[0] = 0x00;
I2CDevice.I2CReadTransaction tran_read = I2CDevice.CreateReadTransaction(buffer_read);
I2CDevice.I2CWriteTransaction tran_write = I2CDevice.CreateWriteTransaction(buffer_write);
I2CDevice.I2CTransaction[] tran = new I2CDevice.I2CTransaction[]{tran_write};
int data = RTC.Execute(tran, 100);
Debug.Print("\nThe number of data transfered is: "+ data.ToString());
tran = new I2CDevice.I2CTransaction[] { tran_read };
data = RTC.Execute(tran, 100);
Debug.Print("\nThe number of data transfered is: " + data.ToString());
}
}
}
I say simular board, since mine isn't from Sparkfun but from Adafruit.
A big difference I noticed are the pullup resistors which aren't placed on the Sparkfun version. You should put them in yourself I suppose.
Hi Stefan.
First thank you for answering me. I already tried to use your proyect´s code but there is no way, it doesn´t work. I also tried with pullup resistors and without them, but nothing.......the extrangest thing is that it seams to send data to the board but, i don´t know why, it can´t read nothing from the board(the registers)......
When i use the code you told me yesterday, it gives me this error:
"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll"
And the compiler tells that the problem is in this part of the code:
public DateTime Now()
{
var data = new byte[7];
int result = Read(0x00, data);
//TODO: Add exception handling if result == 0
var dt = new DateTime(
(int)2000 + data[6].FromBCD(), // Year
(int)data[5].FromBCD(), // Month
(int)data[4].FromBCD(), // Day
(int)(((byte)(data[2] & 0x3f)).FromBCD()), // Hour
(int)data[1].FromBCD(), // Minute
(int)(((byte)(data[0] & 0x7f)).FromBCD()) // Second
);
return dt;
}
I don´t know wehat could be the problem, the hardware or the software.........
The "//TODO: Add exception handling if result == 0" tells me that there can happen an error if no date is set.
The first time you use the chip, it needs to know the current date. Have you used the SetClock method since you placed the battery?
Yes, the date is ok, we tried the hardware with an Arduino and it worked well,and at the first time we introduced the correct date in the boards DS1307 registers. The problem came when we started to work with the Netduino and .net MicroFramework, thats the reason why I think that the problem is probabilly a software problem,becouse the conections are well done and the board works fine with Arduino. I don´t know what I am doing wrong but its trying me crazy!
Just a wild guess, have you tried swapping the analog pins 4 and 5?
I know the chip doesn't work on 3.3V, only 5V. perhaps that could be an issue as well?
I completely understand your frustrations, but I know the project in that other tread works with the Adafruit board which has the same chip and the only difference I can see are the missing resistors on the Sparkfun board.
Just to add as i dont know if its been touched on in this thread.
The DS1207 requires the repeated start support of one of the custom built FW's (Im using 4.1 with CW's OneWire Library)
Can you confirm if you are using the stock firmware or a custom build with the repeated start bit support?
I2CDevice.I2CTransaction[] tran = new I2CDevice.I2CTransaction[]{tran_write};
int data = RTC.Execute(tran, 100);
Debug.Print("\nThe number of data transfered is: "+ data.ToString());
tran = new I2CDevice.I2CTransaction[] { tran_read };
data = RTC.Execute(tran, 100);
After each Execute, it would produce a stop bit. Thus cancelling the address it was at (I think) and the read may not know where to reference.
Stefan, Can you confirm this? as i dont have my DS1307....yet...
I have the 4.1.0.6 firmware version......this could be the problem??????, I also have to say that doing the adders write and the read transacations at the same Execute it doesn´t work neither.
I updated the firmware to 4.1.1 beta version but I´m in the same way, it doesn´t work neither with my code not with that one you posted, it gives me the same error that i have told you before..........
I updated the firmware to 4.1.1 beta version but I´m in the same way, it doesn´t work neither with my code not with that one you posted, it gives me the same error that i have told you before..........
After the firmware you connected everyting -including resistors- on 5v I suppose?
When I'm home, I'll try your code with my board. Hopefully we can work to a solution!
I updated the firmware to 4.1.1 beta version but I´m in the same way, it doesn´t work neither with my code not with that one you posted, it gives me the same error that i have told you before..........
OK,
Can you post the code you have used, please bare in mind that the transaction for a read should include an initial write (to write the address of the register to be read) and then a read.
Please see this excract of code from the FusionWare I2C Library (attached).
/// <summary>Performs a common Write-repeatstart-read command response operation</summary>
/// <param name="Config">Configuration for the bus during this operation</param>
/// <param name="WriteBuffer">Buffer containing data to write</param>
/// <param name="ReadBuffer">Buffer to receive data. The Length property of ReadBuffer determines the number of bytes to read</param>
/// <param name="TimeOut">Millisecond time out value</param>
/// <remarks>
/// Many I2C devices have a simple command response protocol of some sort
/// this method simplifies the implementation of device specific drivers
/// by wrapping up the I2CTransaction creation and timeout detection etc.
/// to support a simple command/response type of protocol. It creates a write
/// transaction and a read transaction with a repeat-start condition in between
/// to maintain control of the bus for the entire operation.
/// </remarks>
/// <exception cref="T:System.IO.IOException">Operation failed to complete</exception>
public void WriteRead(I2CDevice.Configuration Config, byte[] WriteBuffer, byte[] ReadBuffer, int TimeOut)
{
ThrowIfDisposed();
lock(this.Device)
{
this.Device.Config = Config;
I2CDevice.I2CTransaction[] xacts = new I2CDevice.I2CTransaction[] {
I2CDevice.CreateWriteTransaction(WriteBuffer),
I2CDevice.CreateReadTransaction(ReadBuffer)
};
// I2CDevice.Execute returns the total number of bytes
// transfered in BOTH directions for all transactions
int byteCount = this.Device.Execute(xacts, TimeOut);
if(byteCount < (WriteBuffer.Length + ReadBuffer.Length))
throw new System.IO.IOException();
}
}
Yes, I connected everithing well again......thank you very much for wasting your time with my problem, shure that the problem it´s a little detail(a dumb detail shure) but if I can i would try to put a photo of whow I´ve got the connections.........