@SlyD: Ja, die I2C Beispielprogramm auf der M32 laufen alle einwandfrei. Jetzt hab ich mal deinen Rat befolgt und habe das letzte! Beispielprogramm (RP6Control_10_Move2) komplett zerpflückt.
das ergebnis ist leider sehr ernüchternd: obwohl ich seit gestern abend mit so gut wie nichts anderem beschäftigt war und jede menge probiert habe. ein problem ist mit unter auch, dass ich einzelne programmteile in diesem Beispielprogramm nicht richtig verstehe:
Was hat es zum Beispiel genau damit auf sich?:
Code:
typedef struct {
uint8_t speed_left; // left speed (is used for rotation and
// move distance commands - if these commands are
// active, speed_right is ignored!)
uint8_t speed_right; // right speed
unsigned dir:2; // direction (FWD, BWD, LEFT, RIGHT)
unsigned move:1; // move flag
unsigned rotate:1; // rotate flag
uint16_t move_value; // move value is used for distance and angle values
uint8_t state; // state of the behaviour
} behaviour_command_t;
ich vermute das hängt irgendwie damit zusammen, aber wie?
Code:
behaviour_command_t STOP = {0, 0, FWD, false, false, 0, IDLE};
behaviour_command_t cruise = {CRUISE_SPEED_FWD, CRUISE_SPEED_FWD, FWD,
false, false, 0, MOVE_FORWARDS};
behaviour_command_t escape = {0, 0, FWD, false, false, 0, IDLE};
behaviour_command_t avoid = {0, 0, FWD, false, false, 0, IDLE};
behaviour_command_t waitForStart = {0, 0, FWD,
false, false, 0, PREPARE};
warum darf man das so schreiben:
Code:
escape.move = true; //Warum kann man das hier so "escape.move" schreiben?
escape.rotate = true; //Hier das selbe, habe das noch nie gesehen
was hat es hier mit den zeichen * und -> auf sich?
Code:
void moveCommand(behaviour_command_t * cmd)
{
if(cmd->move_value > 0) // move or rotate?
{
if(cmd->rotate)
rotate(cmd->speed_left, cmd->dir, cmd->move_value, false);
da ich aus diesen programmteilen bisher nicht wirklich schlau geworden bin, habe ich jetzt einmal den großteil aus dem programm geworfen. zur erklärung: vorerst ist erstmal nur mein ziel, dass sich der RP6 dreht.
das programm schaut dann so aus:
Code:
#include "RP6ControlLib.h" // The RP6 Control Library.
// Always needs to be included!
#include "RP6I2CmasterTWI.h" // I2C Master Library
/*****************************************************************************/
/*****************************************************************************/
// Include our new "RP6 Control I2C Master library":
#include "RP6Control_I2CMasterLib.h"
/*****************************************************************************/
void RP6_Bewegung(void)
{if (getStopwatch3() >3000)
{rotate(50,FWD,90,false);}
}
/**
* Timed Watchdog display - the other heartbeat function
* does not work in this example as we use blocked moving functions here.
*/
void watchDogRequest(void)
{
static uint8_t heartbeat2 = false;
if(heartbeat2)
{
clearPosLCD(1, 14, 1);
heartbeat2 = false;
}
else
{
setCursorPosLCD(1, 14);
writeStringLCD_P("#");
heartbeat2 = true;
}
}
/*****************************************************************************/
// I2C Requests:
/**
* The I2C_requestedDataReady Event Handler
*/
void I2C_requestedDataReady(uint8_t dataRequestID)
{
checkRP6Status(dataRequestID);
}
/*****************************************************************************/
// I2C Error handler
/**
* This function gets called automatically if there was an I2C Error like
* the slave sent a "not acknowledge" (NACK, error codes e.g. 0x20 or 0x30).
*/
void I2C_transmissionError(uint8_t errorState)
{
writeString_P("\nI2C ERROR - TWI STATE: 0x");
writeInteger(errorState, HEX);
writeChar('\n');
}
/*****************************************************************************/
// Main function - The program starts here:
int main(void)
{
initRP6Control();
initLCD();
writeString_P("\n\nRP6 CONTROL M32 I2C Master Example Program!\n");
writeString_P("\nMoving...\n");
// ---------------------------------------
WDT_setRequestHandler(watchDogRequest);
// ---------------------------------------
I2CTWI_initMaster(100);
I2CTWI_setRequestedDataReadyHandler(I2C_requestedDataReady);
I2CTWI_setTransmissionErrorHandler(I2C_transmissionError);
sound(180,80,25);
sound(220,80,25);
setLEDs(0b1111);
showScreenLCD("################", "################");
mSleep(500);
showScreenLCD("I2C-Master", "Behaviours");
mSleep(1000);
setLEDs(0b0000);
// ---------------------------------------
// Setup ACS power:
I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, CMD_SET_ACS_POWER, ACS_PWR_MED);
// Enable Watchdog for Interrupt requests:
I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, CMD_SET_WDT, true);
// Enable timed watchdog requests:
I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, CMD_SET_WDT_RQ, true);
startStopwatch1();
startStopwatch2();
startStopwatch3();
showScreenLCD("Active Behaviour", "");
while(true)
{
task_checkINT0();
task_I2CTWI();
RP6_Bewegung();
}
return 0;
}
auch wenn ich bisher keine erklärung dafür finde, tut das programm bisher gar nichts. nicht einmal die textmeldungen im main teil werden im terminal ausgegeben.
zur erinnerung: das original Beispielprogramm (RP6_Control_Move2) lief einwandfrei also kann man einen I2C defekt ausschließen.
bin für jede hilfe dankbar
mfg andi
Lesezeichen