Kids, always read the datasheet before starting wiring your module. I always said it to other people, but sometimes I’m anxious to get things working and fail to follow my own advice.
It happened again with DS1307 Module that I got from Aliexpress:
I connected it to STM32F4Discovery board this way:
---------------------------------- STM32F4Discovery | DS1307 Module -----------------+---------------- GND | GND 3V | VCC SDA | PB9 SCL | PB7 -----------------+----------------
But when NuttX was starting it was failing to communicate with the module, returning error -6 (= ENXIO = “No such device or address”) :
ABCDF stm32_ds1307_init: Initialize I2C1 stm32_ds1307_init: Bind the DS1307 RTC driver to I2C1 up_rtc_getdatetime: ERROR: I2C_TRANSFER failed: -6
I used the Logic Analyzer and saw that the address was sent correctly, but the board wasn’t responding. After some time I decided to look the datasheet to confirm that it could work with 3V (I assumed it because the module uses a 3V battery) and to my surprise it only works from 4.5V to 5V.
Then connecting the VCC from the module to 5V worked:
ABCDF
stm32_ds1307_init: Initialize I2C1
stm32_ds1307_init: Bind the DS1307 RTC driver to I2C1
rtc_dumptime: Returning:
rtc_dumptime: tm_sec: 00000026
rtc_dumptime: tm_min: 00000024
rtc_dumptime: tm_hour: 00000004
rtc_dumptime: tm_mday: 00000019
rtc_dumptime: tm_mon: 00000009
rtc_dumptime: tm_year: 00000068
nsh> date
Oct 25 04:36:56 2004
nsh> date -s "Sep 22 08:04:00 2019"
up_rtc_settime: Setting time tp=(1569139440,0)
rtc_dumptime: New time:
rtc_dumptime: tm_sec: 00000000
rtc_dumptime: tm_min: 00000004
rtc_dumptime: tm_hour: 00000008
rtc_dumptime: tm_mday: 00000016
rtc_dumptime: tm_mon: 00000008
rtc_dumptime: tm_year: 00000077
nsh>
I turned the board OFF and let it alone some minutes and when I connected it again the time was correct:
NuttShell (NSH) nsh> date Sep 22 08:23:41 2019 nsh>
These are the main options I enabled on NuttX to get it working:
STM32_I2C1 STM32_I2C RTC RTC_DATETIME RTC_DS1307 RTC_DSXXXX RTC_EXTERNAL