• AVR Freaks

Hot!DS1307 for dspic33ev256gm106 using MCC

Author
ashoksam
Starting Member
  • Total Posts : 49
  • Reward points : 0
  • Joined: 2018/11/04 22:05:35
  • Location: 0
  • Status: offline
2019/10/10 02:32:58 (permalink)
0

DS1307 for dspic33ev256gm106 using MCC

Hi all,
I am new to this i2c communication.I am trying to build a ds1307 RTC with dspic33ev256gm106 through i2c communication.
my concern is to print the actual time and date with serial port using mcc library.
Can anyone give some ideas or steps to begin.
Thanks in advance
 
#1

4 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24278
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: DS1307 for dspic33ev256gm106 using MCC 2019/10/10 02:59:04 (permalink)
    0
    Do one step at a time.
    Are you able to send a fixed string through the serial port?
    Have you ever worked with I2C?
     

    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!
    #2
    ashoksam
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2018/11/04 22:05:35
    • Location: 0
    • Status: offline
    Re: DS1307 for dspic33ev256gm106 using MCC 2019/10/10 03:45:59 (permalink)
    0
    Hi ric,
    I have no experience with I2C ,Can you please guide me how to proceed?
    I don't have any analyzer and oscillator to monitor the status.so due to that i am trying to print on serial port.
    If it possible can you please suggest step by step to work with I2C.
    why i choose mplab code configurator means it seems easy for me,so for thats the reason i choose MCC.
    Through the serial port i am able to send the string correctly.Only thing is i need to configure ds1307 to monitor the current time.
     
    post edited by ashoksam - 2019/10/10 03:47:41
    #3
    ashoksam
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2018/11/04 22:05:35
    • Location: 0
    • Status: offline
    Re: DS1307 for dspic33ev256gm106 using MCC 2019/10/15 05:02:36 (permalink)
    0
    Hi all,
    As a beginner of working with I2C and ds1307 RTC  i want to print the seconds value from 0 to 59 in uart .As of now i have written the below code,but i don't know what is the next step required  to print the seconds value.If anyone know about this please help me.
        
     
    Mplab x ide version: 5.15
    controller : dspic33ev256gm106
    MCC verion : 3.75
     
     
     
    #include "stdio.h"
    #include "string.h"
    #include "mcc_generated_files/system.h"
    #include "mcc_generated_files/mcc.h"
    #include "mcc_generated_files/pin_manager.h"
    #include "mcc_generated_files/uart2.h"
    #include "mcc_generated_files/i2c1.h"

    #define FCY 8000000UL
    #include <libpic30.h>
    /*
    Main application
    */
    uint16_t i2c_address = 0x68;
    uint8_t i2c1_data;
    I2C1_MESSAGE_STATUS i2c_status;
    uint8_t seconds = 0x00;
     
    int main(void)
    {
    char length[50];
    I2C1_Initialize();
    SYSTEM_Initialize();
    LED1_SetHigh();
    while (1)
    {

    I2C1_MasterWrite(&seconds,1,i2c_address,&i2c_status);
    __delay_ms(100);
    I2C1_MasterRead(&i2c1_data,1,i2c_address,&i2c_status);
    __delay_ms(100);
    sprintf(length,"%d\n",i2c1_data);
    UART2_WriteBuffer((uint8_t *)length,strlen(length));
    }
    return 1;
    }
     
     
     
     
    Thanks in advance
    #4
    Mysil
    Super Member
    • Total Posts : 3421
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: DS1307 for dspic33ev256gm106 using MCC 2019/10/16 16:48:42 (permalink)
    0
    Hi,
    Have done some experiments with the code you provide in message #4,
    and it actually seem that some of it may work,
    even if the code is somewhat light on checking and error handling.
    This is with the restriction that all MCC setup and hardware connections are correctly done.
     
    I do not have the same dsPIC33 device you are using.
    Have established a MCC configuration and stepped thru some of it in MPLAB simulator. I2C peripheral cannot be simulated.
    Have used your main code in a MCC configuration for a different dsPIC33 device,
    and run some experiments.
     
    UART communication for results may be used, but correct functioning of asynchronous serial,
    depend on MCC setup beeing correctly done with oscillator selection and settings,
    and UART baudrate corresponding with the terminal (emulator program) used to display messages.
    Note that microcontroller cannot be connected directly to RS-232 port (9 pin) of a computer or laptop,
    there is transciever hardware needed.
     
    I2C communication do not depend on any precision timing or particular frequency,
    as long as SCL signaling is not much too fast.
    Be aware that I2C hardware and MCC driver will check that slave device respond as expected,
    so if DS1307 is not correctly connected, I2C1_MasterWrite(...) function will return a error status value into the  i2c_status variable. You should check the value in this variable, after the delay have ended, 
    either in debugger or in the program.
     
    I2C slave address used by the program, seem correct for the DS1307 real time clock
     
    From datasheet for DS1307, it seem to me that when the RTC have been without power,
    neither Vbat nor Vcc, 
    then the clock will not run, until you start it by writing a valid value to the Seconds register,
    0x00 should work. 
    Only reading, without writing a start value, is likely to always return the same value.
     
    When the RTC is eventually running, it will return time values as packed BCD numbers,
    (up to) 4 bits for each decimal digit, 2 decimal digits in each 8 bit byte.
    BCD values are not directly useable for sprintf(...) formatting or UART printing.
    You must separate the 2 digits from each BCD byte, into 2 single digit decimal values,
    and insert into separate bytes in a char array, together with a prefix value that make it a valid text digit.
    Or combine digits into integer values that may be processed by sprintf(...).
    Example:
        i = 0;
        text[i] = ((i2c1_data >> 4) & 0x07) + '0';  /* 10 seconds digit value + character code of '0' symbol. */
        i++;                           /* next character position in text string. */
        text[i] = (i2c1_data & 0x0F) + '0';        /* single seconds digit character. */
        i++;
        text[i] = '\r';
        i++;
        text[i] = '\n'
        i++;
        text[i] = 0x00;        /*  String terminator. */
        UART2_WriteBuffer((uint8_t *)text, i);

     
        Mysil
     
     
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5