Hallo
Wenn man weiß wie es funktioniert klappt das auch mit der orginalen RP6-TWI-Library in C:
Code:
// WII-Nunchuk am RP6 erste Versuche mit TWI in C 8.8.2008 mic
#include "rblib.h"
#include "rblib.c"
#include "rblcdlib.c"
#include "RP6I2CmasterTWI.h"
#include "RP6I2CmasterTWI.c"
uint8_t i=0; // Hilfsvariable
uint8_t nunchuk_data[6]; // Nunchuk-Daten
void lcd_start(void)
{
lcd_init(); // lcd initialisieren
lcd_cls(); // lcd Inhalt löschen
lcd_locate(2,0);
lcd_writeString("RP6 ROBOT SYSTEM");
lcd_locate(1,1);
lcd_writeString("WII-Nunchuk am RP6");
}
void lcd_ausgabe(void)
{
lcd_locate(2,2);
for(i=0; i<5; i++)
{
lcd_writeInteger((nunchuk_data[i] ^ 0x17) + 0x17, 16);
lcd_writeString(" ");
}
lcd_writeInteger(((nunchuk_data[i] ^ 0x17) + 0x17) & 3, 16);
lcd_locate(2,3);
lcd_writeString("Tasten: ");
lcd_writeInteger(128+lcd_getkeys(), 2);
}
int main(void)
{
rblib_init(); // rblib initialisieren
I2CTWI_initMaster(400); // TWI mit 400kHz initialisieren
I2CTWI_transmit2Bytes(0xa4, 0x40, 0); // Nunchuk Speicheradresse setzen
lcd_start(); // LCD-Startbildschirm darstellen
while(1)
{
I2CTWI_transmitByte(0xa4, 0); // Datenlesemodus starten
I2CTWI_readBytes(0xa5, &nunchuk_data[0], 6); // sechs Bytes lesen
for(i=0; i<5; i++)
{
writeInteger((nunchuk_data[i] ^ 0x17) + 0x17, 16);
writeString(" ");
}
writeInteger(((nunchuk_data[i] ^ 0x17) + 0x17) & 3, 16);
writeString("\n");
lcd_ausgabe();
delay_ms(50);
}
return(0);
}
Die Ausgabe dazu sind die sechs Daten-Bytes des Nunchuk:
Code:
Terminal cleared!
7c 81 76 84 dc 3
7c 81 7a 8c df 3
7c 81 82 8e dc 3
7c 81 83 8a dc 3
7c 81 7d 8c df 3
7c 81 6f 8c dd 3
7b 81 4b 7f c2 3
7b 81 42 79 a7 3
7b 81 3f 79 ab 3
7b 81 4b 82 d3 3
7b 81 88 8d db 3
7c 81 af 7d b1 3
7c 81 ab 6e 91 3
7c 80 a0 7b b5 3
7b 80 8b a7 c0 3
7b 80 91 bc a8 3
7b 80 85 c1 a8 3
7b 80 86 b2 cb 3
7b 80 81 7e de 3
7b 80 7b 58 aa 3
7b 80 76 57 bf 3
7b 80 8e 88 dc 3
7b 81 93 8f d9 3
78 81 89 8f d6 3
4f 7f 87 91 db 3
1b 7d 85 90 dd 3
1b 7e 86 90 dd 3
1b 7e 82 90 dc 3
1b 7e 82 90 dc 3
7a 81 83 91 dd 3
7b 81 84 8f dc 3
80 80 85 8f db 3
a5 7d 86 8f db 3
df 80 86 8f dc 3
df 7f 85 8f dc 3
df 7f 88 8f db 3
df 7f 88 90 db 3
79 81 87 8e db 3
7a 80 86 8e db 3
78 a0 86 8f dc 3
71 d5 84 8e db 3
71 df 87 8d dc 3
71 df 85 8d dd 3
71 df 86 8e dd 3
7a 81 85 8d dd 3
7a 81 85 8c dd 3
80 79 85 8c db 3
82 3d 84 8c dc 3
83 22 85 8c dc 3
82 21 85 8c dc 3
81 20 84 8c dc 3
80 1f 86 8c dc 3
7a 81 84 8c dc 3
7a 81 86 8d dd 3
7a 81 81 8b db 3
7a 81 7e 8b db 3
7a 81 7d 87 db 3
7a 81 7e 8a df 3
7a 81 81 8a dc 3
[RP6BOOT]
[READY]
Echt einfach.
Gruß
mic
Lesezeichen