klappt bei mir nicht mit Mega und Levelshifter:
für die ersten 10 bis 30 Arrays werden vom Slave Daten ausgetauscht, dann passiert am Mega plötzlich nichts mehr;
auch der Raspi kriegt keine neuen Daten mehr: I2C tot.
i2cdetect -y l zeigt anschließend keinen i2c-slave mehr an 0x04 an.
Jetzt hab ich noch einen 3. Levelshifter gefunden, da sind aber noch keine Pins dran....: morgen also....Code:pi@raspberrypi ~ $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
Der Raspi-Code muss übrigens noch etwas abgeändert werden, dass er nur dann seine Test-Variable weiterzählt, wenn er vorher einen korrekten Array vom Slave bekommen hat - er ist jetzt schon besser, aber noch nicht 100% ok:
dann alles wieder umgesteckt auf 3,3V Due...:Code:// Raspberry Pi Master code to send/receive byte arrays // to an Arduino as an I2C slave // // ver. 0.002 // // protected under the friendly Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License // http://creativecommons.org/licenses/by-nc-sa/3.0/ // #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <wiringPi.h> #include <wiringPiI2C.h> #include <errno.h> #include <string.h> #define MSGSIZE 30 unsigned char calcchecksum( unsigned char array[]) { int32_t sum=0; for(int i=2; i<MSGSIZE; ++i) sum+=(array[i]); return (sum & 0x00ff); } int main (void) { int fd, i ; unsigned char test=0; unsigned char data [MSGSIZE] ; if ((fd = wiringPiI2CSetup (0x04) ) < 0) { fprintf (stderr, "Can't open RTC: %s\n", strerror (errno)) ; exit (EXIT_FAILURE) ; } for (;;) { memset(data, 0, sizeof(data) ); data[0]= 0xff; // init for transmission error check read (fd, data, MSGSIZE) ; if( data[1] != calcchecksum( data ) ) { // handle transmission error ! } else { printf ("read: "); for (i = 0 ; i < MSGSIZE ; ++i) printf (" %3d", data [i]) ; printf ("\n") ; delay(10) ; memset(data, 0, sizeof(data) ); data[5]= test++; data[0]= 0xff; data[MSGSIZE-1]= 0x04; data[1] = calcchecksum( data ); write(fd, data, MSGSIZE) ; printf ("write: "); for (i = 0 ; i < MSGSIZE ; ++i) printf (" %3d", data [i]) ; printf ("\n\n") ; delay(10) ; } } return 0 ; }
fluppt.
- - - Aktualisiert - - -
ps,
im Augenblick re-synced er sogar automatisch:
nach Rausnehmen einer i2c-Leitung stoppt die Transmission auf dem Slave
(blöderweise zählt der Raspi trotzdem weiter...: to do: error handling),
aber nach wiedereinstecken machen Raspi und Arduino wieder ganz normal weiter.







Zitieren

Lesezeichen