PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Probleme beim Nunchuck auslesen... Bibliothek von Peter Fleury



deko
14.05.2012, 15:19
Hallo,
ich habe meinen Nunchuck wie hier angeschlossen:
https://www.roboternetz.de/community/threads/37522-Nunchuk-Bascom-Atmega8-Brauche-hilfe-)/page7?p=428731#post428731 (https://www.roboternetz.de/community/threads/37522-Nunchuk-Bascom-Atmega8-Brauche-hilfe-%29/page7?p=428731#post428731)

rot - 3,3V
weis - GND
grün - SDA mit 10k pullup an 3,3V
gelb - SCL mit 10k pullup an 3,3V

Ich benutze die I2C Bibliothek von Peter Fleury Bus läuft auf 100khz.

mein quellcode:

#define SLAVE_ADRESSE 0x52

int main(void)
{
uart_init();

sei();
uart_puts("Hallo!\r\n");

i2c_init(); // initialize I2C library

i2c_start_wait(SLAVE_ADRESSE+I2C_WRITE); // set device address and write mode
uart_puts("Test1\r\n");
i2c_write(0x40);
i2c_write(0x00);
i2c_stop(); // set stop conditon = release bus

i2c_start_wait(SLAVE_ADRESSE+I2C_WRITE); // set device address and write mode
uart_puts("Test2!\r\n");

i2c_write(0x00);
i2c_rep_start(SLAVE_ADRESSE+I2C_READ); // set device address and read mode
uart_puts("Test3\r\n");

uart_putc(i2c_readNak());
i2c_stop();
}

Er giebt mir nur hallo aus, test1, test2 oder test3 nicht...

hat einer eine Idee woran das liegen kann?

gruß
Deko

Klebwax
15.05.2012, 06:50
Ich glaube das Problem liegt hier:

i2c_start_wait(SLAVE_ADRESSE+I2C_WRITE);

Die I2C-Adresse liegt in den oberen 7 Bit des ersten Byte, es sollte also heißen (SLAVE_ADRESSE << 1) | I2C_WRITE

MfG Klebwax

radbruch
15.05.2012, 08:17
Hallo

Klebwax hat recht:


'Const Nunchuck_write = &H52 ' Slaveadresse
'Const Nunchuck_read = &H53
Const Nunchuck_write = &HA4 ' Slaveadresse
Const Nunchuck_read = &HA5(Aus https://www.roboternetz.de/community/threads/37522-Nunchuk-Bascom-Atmega8-Brauche-hilfe-%29?p=357342&viewfull=1#post357342)

Gruß

mic

deko
15.05.2012, 14:14
leider führt i2c_start_wait((SLAVE_ADRESSE << 1) | I2C_WRITE); oder i2c_start_wait(0xA4); zu keiner Besserung