Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    emard
    @emard
    @lawrie flat side (+) up to the metallic shell contact. smaller side (-) to PCB contact. Proper initialization makes RTC "tick" and remeber time. It is not just plug battery and it will start ftom 1970. I have not yet used lcc but now will download. You can take micropython i DVI example here to check battery etc is ok https://github.com/emard/ulx3s-misc/tree/master/examples/rtc/i2c_master/proj
    this one for initialization (it will set RTC to NTP time using esp32) https://github.com/emard/ulx3s-misc/tree/master/examples/rtc/micropython-mcp7940n
    Paul Ruiz
    @pnru_gitlab
    How are you accessing it, esp32 or SaxonSoc? Is it possible that either one shuts the RTC down on repowering?
    Lawrie Griffiths
    @lawrie
    I am using the i2cset and i2cget commands on SaxonSoc.
    ESP32 is not directly connected to RTC so it can only talk to RTC thru FPGA inbetween
    RTC has register flag that indicated "keep time if battery present" This flag must be initialized. otherwise, even battery is there,, power off and RTC will forget :)
        self._i2c.writeto_mem(MCP7940.ADDRESS, 0x03, bytes([0x07 | 8])) # weekday | battery_backup
    its hidden in the weekday :)
    Lawrie Griffiths
    @lawrie
    I am reading the data sheet and have now spotted it.
    OK, it is working now.
    Lawrie Griffiths
    @lawrie
    I did i2cset -y 0 0x6F 0x03 0x09
    Lawrie Griffiths
    @lawrie
    Or perhaps 0x0b for Tuesday, depending on how it is encoded.
    emard
    @emard
    I think from esp32 that it encodes from 1 as monday to 7 as sunday
    Lawrie Griffiths
    @lawrie
    So I should set 0x0a.
    emard
    @emard
    I think so from my memory :) I can also try to run esp32 NTP example to verify it.
    Lawrie Griffiths
    @lawrie
    I have started using fujprog -t, but it loses the connection a lot.
    emard
    @emard
    Perhaps it talks to ftdi in libusb mode hmmm. I dont remember now is -P the same as without (but before at ujprog it wasnt) so maybe -P/dev/ttyUSB0 -t could open port in unix standard mode, maybe that would be more reliable. But fujprog obviously has there a bug
    fujprog -P/dev/ttyUSB0 -t doesnt work
    ujprog -P/dev/ttyUSB0 -t works
    Lawrie Griffiths
    @lawrie
    oot@buildroot:~# cat date.sh 
    R6=`i2cget -y 0 0x6f 0x06`
    R5=`i2cget -y 0 0x6f 0x05`
    R4=`i2cget -y 0 0x6f 0x04`
    R2=`i2cget -y 0 0x6f 0x02`
    R1=`i2cget -y 0 0x6f 0x01`
    
    YY="${R6:2:2}"
    MON="$((${R5:2:2}-20))"
    DD="${R4:2:2}"
    HH="${R2:2:2}"
    MM="${R1:2:2}"
    
    echo "20$YY-$MON-$DD $HH:$MM"
    root@buildroot:~# ./date.sh 
    2020-9-22 19:40
    Lawrie Griffiths
    @lawrie
    date -s "`./date.sh`"
    emard
    @emard
    I have 12F updated everything from images but not the bitstream. my /dev/i2c-0 exists but i2cdetect wont detect anything. RTC works from ESP32 and FPGA i2c bridge. Do I need new 12F bitstream?
    (I think I have to download it :)
    Lawrie Griffiths
    @lawrie
    I believe so
    emard
    @emard
    So far i2c is not working maybe I need to try to download again and refresh
    root@buildroot:/home/root/rtc# i2cget -y 0 0x6f 0x06
    Error: Read failed
    root@buildroot:/home/root/rtc# ls -al /dev/i2c-0 
    crw-------    1 root     root       89,   0 Jan  1 00:00 /dev/i2c-0
    Lawrie Griffiths
    @lawrie
    Have you got the latest bitstream?
    emard
    @emard
    Yes right now
    root@buildroot:/home/root/rtc# uname -a
    Linux buildroot 5.0.9 #2 SMP Tue Sep 22 14:10:04 BST 2020 riscv32 GNU/Linux
    Lawrie Griffiths
    @lawrie
    Bitstream should be 484632 bytes.
    emard
    @emard
    Hmm it isnt :)
    root@buildroot:/mt/fat/linux/smp# ls -al ulx3s_12f_1core_saxonsoc.bit
    -rwxr-xr-x    1 root     root        486868 Sep 18  2020 ulx3s_12f_1core_saxonsoc.bit
    Maybe I wrong downloaded
    Dolu1990
    @Dolu1990
    you need the last bitstream, as it added the connections to the i2c
    emard
    @emard
    It was wrong download, I found the bitstream
    OOOOYEEEE now it works
    root@buildroot:/home/root/rtc# ./date.sh 
    2020-9-22 19:09:
    emard
    @emard
    R0 was missing. those regs must be AND-filetered otherwise we have this
    root@buildroot:/home/root/rtc# ./date.sh 
    2020-9-22 19:11:91
    great achievement i2c !!!!!
    emard
    @emard
    #include <stdio.h>
    #include <stdlib.h>
    
    #define I2C_SLAVE 0x703
    #define O_RDWR 2
    
    int i2c_rtc;
    
    void rtc_open(int addr)
    {
      i2c_rtc = open("/dev/i2c-0", O_RDWR);
      ioctl(i2c_rtc, I2C_SLAVE, addr);
    }
    
    void rtc_read(unsigned char *buf, int reg, int n)
    {
      buf[0] = reg;
      write(i2c_rtc, buf, 1);
      read(i2c_rtc, buf, n);
    }
    
    void i2cdemo(void)
    {
      int i;
      unsigned char buf[7];
      // mask for BCD          SEC   MIN   HOUR  WKDAY DAY   MONTH YEAR
      unsigned char mask[7] = {0x7F, 0x7F, 0x3F, 0x07, 0x3F, 0x1F, 0xFF};
    
      rtc_read(buf, 0, sizeof(buf));
      for(i = sizeof(buf)-1; i >= 0; i--)
        printf(" %02x", buf[i] & mask[i]);
      printf("\n");
    }
    
    int main(int argc, char *argv[])
    {
      int i;
      rtc_open(0x6F);
      for(i = 0; i < 60; i++)
      {
        i2cdemo();
        sleep(1);
      }
      return 0;
    }
    root@buildroot:/home/root/rtc# ./a.out 
     20 09 22 02 21 14 27
     20 09 22 02 21 14 28
     20 09 22 02 21 14 29
     20 09 22 02 21 14 30
     20 09 22 02 21 14 31
    emard
    @emard
    Everything works and I hope that also read() of multiple registers does i2c atomic read at which RTC prevents reg update until read is finished
    Dolu1990
    @Dolu1990
    Nice :D
    emard
    @emard
    great stuff, I'playing with it. Can we also have shutdown gpio :)
    Or better to say, can shutdown raise shutdown pin so board powers off really
    Dolu1990
    @Dolu1990
    So, normaly, those feature should be integrated at the opensbi level
    emard
    @emard
    Wherever you suggest is the proper place. From bitstream, this pin needs a kind of "fuze" logic in order not to be triggered at early start of bitstream when the LUTs set up and can do some glitch.. I use some counter that starts from 0 and must be clocked few times. shutdown pin is connected to MSB bit of this counter.
    Lawrie Griffiths
    @lawrie
    @emard That is impressive, doing all the i2c access from C. And it good that lcc and its library had all the features you needed. Some of them only added in the last day or two.
    Dolu1990
    @Dolu1990
    i will add a ulx3s opensbi plateform specific port