Hallo Ich versuche die Zeit von RTC-DS1338 mit meinem Linux Single Board Computer zu lesen, aber es gibt ein Problem mit meinem Code. Ich lese schlechte Ausgaben damit.DS1338 i2c Ausgabe lesen
Ich versuchte zu lesen mit i2cget -y 0 0x68 0
es funktioniert. aber mein Code nicht.
Kann mir jemand helfen?
#include <stdio.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <errno.h>
#define I2C_ADDR 0x68
int main (void)
{
char value;
int fd;
unsigned char pData[10];
char i;
if ((fd = open("/dev/i2c-0", O_RDWR)) < 0)
{
printf("Error: Couldn't open device! %d\n", fd);
return 1;
}
if (ioctl(fd, I2C_SLAVE, I2C_ADDR) < 0)
{
printf("Error: Couldn't find device on address!\n");
return 1;
}
while (1)
{
if (read(fd, &pData, 4) != 4)
{
perror("Read conversion");
}
else
{
for(i=0;i<4;i++) printf(" %02x ",(pData[i] & 0xFF));
printf("\n");
}
sleep(2);
}
return 0;
}
Bad Ausgang:
00 b3 49 47
4e 27 09 21
24 81 29 00
1a 20 02 10
16 1e 1a 46
1a 00 96 18
45 82 03 e0
24 40 88 1c
Gute Daten:
00 05 08 00
01 05 08 00
02 05 08 00
03 05 08 00
04 05 08 00
05 05 08 00
Was bedeutet die guten Daten aus? – donjuedo
Ich habe die gute Datenausgabe hinzugefügt. Sekunden sollten sinnvoller werden – elanktronik