• AVR Freaks

Helpful ReplyHot!Facing problem setting data on DS1307

Author
RKS
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/11/25 04:31:12
  • Location: INDIA
  • Status: offline
2020/08/29 05:00:04 (permalink)
0

Facing problem setting data on DS1307

Hi all, 
        I am facing problem to set time on RTC.I have generated I2C driver form MPLAB harmony v3.My actual Problem 
"DRV_I2C_WriteTransfer(const DRV_HANDLE handle,uint16_t address,void* const buffer,const size_t size)" using this function i need to set the time on RTC. In this function argument i am not getting how to write memory address and data. kindly some one guide me how to do that, or any additional driver is required, because i have worked on I2C based EEProm using AT24 driver.
 
Controller-ATSAMC21J18A
MPLAB XIDE v5.40
MPLAB harmony v3 for code generation
   
 
post edited by RKS - 2020/08/29 05:03:52
#1
karan123
Super Member
  • Total Posts : 1029
  • Reward points : 0
  • Joined: 2009/02/02 11:11:21
  • Location: 0
  • Status: offline
Re: Facing problem setting data on DS1307 2020/08/30 11:22:23 (permalink)
0
If you have DSO ..
Have you seen pulses on Clock and data on I2C_SDA and I2C_SCL Pins ? 
 
 
#2
LdB_ECM
Super Member
  • Total Posts : 456
  • Reward points : 0
  • Joined: 2019/04/16 22:01:25
  • Location: 0
  • Status: offline
Re: Facing problem setting data on DS1307 2020/08/30 20:56:41 (permalink) ☄ Helpfulby RKS 2020/08/31 04:07:10
5 (1)
It's described in the interface section of the help file :-)

handle 
A valid open-instance handle, returned from the driver's open routine DRV_IC2_Open function.

address 
Slave Address

buffer 
Source buffer containing data to be written.

size 
Size in bytes of data to be written.

 
So assuming you have called DRV_I2C_Initilaize then  use is something like
#define I2C_ADDRESS 0x6F
uint8_t buf[3] = {0x80, 0x50, 0x12}; // some random data
handle = DRV_I2C_Open(DRV_I2C_INDEX_0, DRV_IO_INTENT_EXCLUSIVE);
if (handle == DRV_HANDLE_INVALID)
{
    // Unable to open the driver
    // May be the driver is not initialized or the initialization
    // is not complete.
}
DRV_I2C_WriteTransfer(handle, I2C_ADDRESS, &buf[0], 3); // write the 3 bytes

post edited by LdB_ECM - 2020/08/30 21:07:48
#3
RKS
New Member
  • Total Posts : 26
  • Reward points : 0
  • Joined: 2019/11/25 04:31:12
  • Location: INDIA
  • Status: offline
Re: Facing problem setting data on DS1307 2020/09/01 01:40:47 (permalink)
0
Thanks all, 
                I am using DSO to see SCL AND SDA line.while data writing there is no problem ,i can see all bytes.But while data reading from RTC ,i can see only slave address and memory address other bytes i can't see.kindly see source code below, where i am doing wrong.
 
i am using Mplab harmony v3 for code generation.
micro controller-ATSAMC21J18A
 
#include <stddef.h> // Defines NULL
#include <stdbool.h> // Defines true
#include <stdlib.h> // Defines EXIT_FAILURE
#include "definitions.h" // SYS function prototypes
#define RTCslaveaddr           0x68
#define sec_addr                 0x00
#define min_addr                0x01
#define hr_addr                  0x02
#define date_addr               0x04
#define month_addr            0x05
#define year_addr               0x06
#define sec                         0
#define min                        10
#define hr                          10
#define date                       1
#define month                    9
#define year                       20
 
unsigned char tx_b[]={0,sec,min,hr,date,month,year};
unsigned char ch=0;
unsigned char rx_b[7];

void delay_ms(unsigned int ms)
{
    ms=ms*1600;
    for(;ms>0;ms--);
}
// *****************************************************************************
// *****************************************************************************
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************
void RTC_SETtime(void)
{
         SERCOM2_I2C_Write(RTCslaveaddr, &tx_b[0],7);
          delay_ms(10);
}
void RTC_GETtime(void)
{
            SERCOM2_I2C_Write(RTCslaveaddr, &ch,1);
             delay_ms(2);
             SERCOM2_I2C_Read(RTCslaveaddr |1,&rx_b[0],6);
             delay_ms(10);
              SERCOM3_USART_Write(rx_b,6);
}






int main ( void )
{
/* Initialize all modules */
SYS_Initialize ( NULL );


while ( true )
{
            RTC_SETtime();
           // delay_ms(1000);
           RTC_GETtime();
          SERCOM3_USART_Write((unsigned char*)"hello world",11);

}
/* Execution should not come here during normal operation */
return ( EXIT_FAILURE );
}

/*******************************************************************************
End of File
*/
 
post edited by RKS - 2020/09/01 01:42:06
#4
LdB_ECM
Super Member
  • Total Posts : 456
  • Reward points : 0
  • Joined: 2019/04/16 22:01:25
  • Location: 0
  • Status: offline
Re: Facing problem setting data on DS1307 2020/09/01 02:57:59 (permalink) ☄ Helpfulby RKS 2020/09/01 21:42:19
5 (1)
I am guessing this is junk
SERCOM2_I2C_Read(RTCslaveaddr |1,&rx_b[0],6);

The routine should do everything it needs with the the address. I imagine you think you are setting read mode with the OR 1. However even if that was needed you need to left shift the address before the OR it would be (RTCslaveaddr << 1) | 1.  However I am very skeptical it needs that I would check the SERCOM2_I2C_Read code it seems illogical they would call it address if you were required to mess with it yourself. My guess is you are asking for a read from device 0x69 and it is ignoring you like it should.
 
Perhaps just try the obvious
SERCOM2_I2C_Read(RTCslaveaddr, &rx_b[0], 6);

 
#5
ric
Super Member
  • Total Posts : 28975
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Facing problem setting data on DS1307 2020/09/01 03:32:04 (permalink) ☄ Helpfulby RKS 2020/09/01 21:42:15
5 (2)
LdB_ECM
Perhaps just try the obvious

+1

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#6
Jump to:
© 2020 APG vNext Commercial Version 4.5