PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : SD21 an RP6



blobelix
15.12.2010, 20:35
Hallo, bin Anfänger und benötige Hilfe. Ich habe ein SD21-Servoboard am I2C-Bus des RP6 angeschlossen. Ich erhalte im Terminal folgende Fehlermeldung: "RP6 CONTROL M32 I2C Master Servoboard SF21 I2C ERROR - TWI STATE: 0x20". Wo liegt der Fehler?
Das Program sieht wie folgt aus:


#include "RP6ControlLib.h" // The RP6 Control Library.
// Always needs to be included!

#include "RP6I2CmasterTWI.h"

/************************************************** ***************************/

#define I2C_RP6_BASE_ADR 10 // The default address of the Slave Controller
// on the RP6 Mainboard
#define I2C_SD21_BASE_ADR 0xC2
uint8_t i;
/************************************************** ***************************/
// I2C Error handler
void I2C_transmissionError(uint8_t errorState)
{
writeString_P("\nI2C ERROR - TWI STATE: 0x");
writeInteger(errorState, HEX);
writeChar('\n');
}
/************************************************** ***************************/
// Initiirung SD21
// uint8_t servo = 1 // 1 ... 21
// uint8_t speed = 10 // Geschwindigkeit 0...255
// uint16_t angle = 1500; //Min 1000, 0 1500, Max 2000


// SD21 Sendefunktion
void I2C_SD21(uint8_t servo, uint8_t speed, uint16_t angle) // vollstaendig
// void I2C_SD21(uint8_t speed, uint16_t angle)
{
uint8_t transmitBuf[4];
transmitBuf[0] = (servo -1)*3; // Register 0-2 = Servo1, 3-5 = Servo2, ...
transmitBuf[1] = speed; // Geschwindigkeit 0...255
transmitBuf[2] = (angle & 0xff); // Low Byte Position
transmitBuf[3] = ((angle >> 8) & 0xff); // High Byte Position

// I2CTWI_transmitBytes(I2C_SD21_BASE_ADR,&transmitBuf[0],4);
I2CTWI_transmitBytes(I2C_SD21_BASE_ADR,transmitBuf[0],4);
}

int main(void)
{
initRP6Control(); // Always call this first! The Processor will not work
initLCD(); // Initialize the LC-Display (LCD)
// Always call this before using the LCD!

writeString_P("\n\nRP6 CONTROL M32 I2C Master Servoboard SF21\n");

// IMPORTANT:
I2CTWI_initMaster(100); // Initialize the TWI Module for Master operation
// with 100kHz SCL Frequency

// Register the event handlers:
I2CTWI_setTransmissionErrorHandler(I2C_transmissio nError);

// Play two sounds:
sound(180,80,25);
sound(220,80,25);

setLEDs(0b1111); // Turn all LEDs on!

showScreenLCD("################", "################");
mSleep(500);
showScreenLCD("I2C-Master", "Funktion auf den Schaltern");
mSleep(1000);
// ---------------------------------------
setLEDs(0b0000); // All LEDs off!

while(true)
{
uint8_t key = checkReleasedKeyEvent();

if(key)
{
switch(key)
{
case 1: // Servo 1 in Mittelstellung
setLEDs(0b0001);
showScreenLCD("Servo 1 Mitte","Tempo 10");
I2C_SD21(1,10,1500);
break;
case 2: // Servo 1 in linker Anschlag
setLEDs(0b0010);
showScreenLCD("Servo 1 links","Tempo 10");
I2C_SD21(1,10,1000);
break;
case 3: // Servo 1 in rechter Anschlag
setLEDs(0b0011);
showScreenLCD("Servo 1 rechts","Tempo 10");
I2C_SD21(1,10,2000);
break;
case 4: // Servo 1 10x alternierend mit Stopwatch
startStopwatch1();

for(i = 0; i < 10; i++)
{
I2C_SD21(1,10,2000);
if(getStopwatch1()>2000)
{
I2C_SD21(1,10,1000);
setStopwatch1(0);
}
}
break;
case 5: // Servo 1 alternierend mit msleep BLOCKIERT
for(i = 0; i < 10; i++)
{
I2C_SD21(1,10,2000); // 2s blockiert
mSleep(2000);
I2C_SD21(1,10,1000);
}
break;
}
}
}
return 0;

}

blobelix
16.12.2010, 20:37
Nach Beseitigung eines Kabeldrehers und Korrektur der Sendefunktion auf "I2CTWI_transmitBytes(I2C_SD21_BASE_ADR,&transmitBuf[0],4); " habe ich die Schalter 1-3 (Mitte,rechts, links) zum Laufen bekommen.
Was muss ich anstellen, damit das Servo wechselseitig auf Anschlag läuft?