fujprog -P/dev/ttyUSB0 -t doesnt work
ujprog -P/dev/ttyUSB0 -t works
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
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
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
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
root@buildroot:/home/root/rtc# ./date.sh
2020-9-22 19:09:
root@buildroot:/home/root/rtc# ./date.sh
2020-9-22 19:11:91
#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
date
is also off and I now have matched errors on the Cortex :^). Here is a reviewed routine. @lawrie - in this form it is not suitable for c.lib, because it does not take an argument but works on a global var.