1

I am trying to interface STM32F091Rc with MCP79411 through i2c bus, i am able to get Unique ID from the chip(MCP79411) but not able to set or get RTC date and time from the chip.

I am using CUBEMX to generate I2C initialization and other required files also i am using freertos and eclipse IDE.

Cant seem to find any libraries relating to RTC chip. Any help would be useful.

EDIT :(working)Code used for retriving Unique ID from MCP79411 chip.

I2c Declaration are done through STMCubeMX generation.


    uint8_t UID_Address_register[]={0xF2,0xF3,0xF4,0xF5,0xF6,0xF7};
    uint8_t Receive_buffer[6];
    for(int k=0;k<6;k++)
    {
     HAL_I2C_Master_Transmit(&hi2c1,0xAE,(uint8_t*)&UID_Address_register[k],1,100);
     HAL_I2C_Master_Receive(&hi2c1,0xAF,(uint8_t*)&Receive_buffer[k],1,100);
    }

Code used in intention of retrieving RTC date and time but failed.

    uint8_t RTC_Date_Time_Registers[]={0x00,0x01,0x02,0x03,0x04,0x05};
    uint8_t DnT_rec_Buf[6];
    for(int k=0;k<6;k++)
    {
     HAL_I2C_Master_Transmit(&hi2c1,0xDE,(uint8_t*)&RTC_Date_Time_Registers[k],1,100);
     HAL_I2C_Master_Receive(&hi2c1,0xDF,(uint8_t*)&DnT_rec_Buf[k],1,100);
    }

   *Binary to decimal conversion operation done to convert incoming read bytes. But only read "000000".

Thanks in advance.

  • So you can read Unique ID through I2C, but cannot read RTC? Could you provide the code for working and non-working case? Have you checked your commands match those in mcp79411 datasheet? – domen Dec 07 '18 at 08:48
  • @domen sure, i have provided the code that i have used. Yes i have gone through the MCP79411 Datasheet and implemented the command cycle but not helped much. – Gokulram Rajendran Dec 08 '18 at 04:23
  • And it's all 0, not 0,0,0,1,1,1 for example? What about return values of i2c functions? Note about oscillator when reading rtc? – domen Dec 09 '18 at 09:17
  • @domen i2c function doesn't return any error values. seems all ok with i2c function. my doubt is that am i using the correct api for reading the RTC values i.e `HAL_I2C_Master_Transmit` and `HAL_I2C_Master_Receive` or do i need to use `HAL_I2C_Mem_Read()` , `HAL_I2C_Mem_Write()` function api and whats the diffrence between these two APIs. – Gokulram Rajendran Dec 10 '18 at 04:44
  • Are there any configuration steps? Can you just read all the valid addresses, and see how they match the datasheet? I2C_Mem operation could also be a good idea (as far as I understand the difference would be in repeated-start vs. stop/start from I2C perspective). – domen Dec 10 '18 at 08:51
  • @domen Thanks for the continuous support i really appreciate it. Somehow i managed to read and set RTC with `HAL_I2C_Master_Transmit` and `HAL_I2C_Master_Receive` functions.As far as i know the problem is with the BCD to decimal conversation and vice versa. – Gokulram Rajendran Dec 10 '18 at 11:24
  • Well, there you go, part of the reason why it's normally a good idea to post a self contained example, not just a snippet that you think is incorrect. – domen Dec 10 '18 at 13:23

0 Answers0