So, SRF02 ist angeschlossen, LIB sollte eingebunden sein.
Dennoch bekomme ich eine Fehlermeldung.
Hier mein Code aus der SRF02-Lib:
Code:
// wurde früher aus PCConnection aufgerunfen, jetzt aus Slave!!
uint8_t messageBuf[8];
void checkSRFStatus(uint8_t dataRequestID){
static uint8_t dist_tmp;
switch(dataRequestID)
{
case MEASURE_US_HIGH: // High data register
// get received data ...
I2CTWI_getReceivedData(messageBuf, 2);
dist_tmp = (messageBuf[0]);
// ... and request low data byte:
I2CTWI_transmitByte(SRF_ADR, 3);
I2CTWI_requestDataFromDevice(SRF_ADR, MEASURE_US_LOW, 1);
break;
case MEASURE_US_LOW: // low data byte:
I2CTWI_getReceivedData(messageBuf, 2);
gemesseneEntfernungSRF = messageBuf[0] + (dist_tmp << 8);
break;
default:break;
}
}
void task_SRF02(void)
{
if(messungOkay>=1){
static uint8_t measureInProgress = false;
if(!measureInProgress) // Start measurement ONCE only
{
if(TWI_operation == I2CTWI_NO_OPERATION) // If there is no request in progress...
{
I2CTWI_transmit2Bytes(SRF_ADR, 0, 81); // 81 means return distance in cm
measureInProgress = true;
setStopwatch7(0);
}
}
else if(getStopwatch7() > 70) // 120ms (measurement delay)
{
I2CTWI_transmitByte(SRF_ADR, 2); // range register high byte
I2CTWI_requestDataFromDevice(SRF_ADR, MEASURE_US_HIGH, 1); // receive it
measureInProgress = false; // allow to start new measurement
setStopwatch7(0);
// Die Messung mitteln
zaehler++;
SRF02_zwischenergebnis=SRF02_zwischenergebnis+gemesseneEntfernungSRF;
}
if(zaehler>=3){
SRF02_Dist = SRF02_zwischenergebnis/zaehler;
zaehler = 0;
SRF02_zwischenergebnis = 0;
}
}else{
SRF02_Dist=-1;
}
}
Und hier, wie ichs in meiner M32-Slave aufrufe:
Code:
uint16_t mic = getMicrophonePeak();
uint16_t SRF02_Dist = task_SRF02();
I2CTWI_readRegisters[I2C_BUTTON] = (getPressedKeyNumber());
I2CTWI_readRegisters[I2C_MICROPHONEPEAKLOW] = (mic & 0x00ff);
I2CTWI_readRegisters[I2C_MICROPHONEPEAKHIGH] = (mic & 0xff00) >> 8;
I2CTWI_readRegisters[I2C_ADC_2] = (uint16_t)readADC(ADC_2);
I2CTWI_readRegisters[I2C_ADC_3] = (uint16_t)readADC(ADC_3);
I2CTWI_readRegisters[I2C_ADC_4] = (uint16_t)readADC(ADC_4);
I2CTWI_readRegisters[I2C_ADC_5] = (uint16_t)readADC(ADC_5);
I2CTWI_readRegisters[I2C_ADC_6] = (uint16_t)readADC(ADC_6);
I2CTWI_readRegisters[I2C_ADC_7] = (uint16_t)readADC(ADC_7);
I2CTWI_readRegisters[I2C_RF02_DIST_LOW] = (SRF02_Dist & 0x00ff);
I2CTWI_readRegisters[I2C_RF02_DIST_HIGH] = (SRF02_Dist & 0xff00) >> 8 ;
In der Zeile mit uint16_t SRF02_Dist... kommt dieser Fehler:
Code:
RP6M32_I2CSlave.c: In function 'task_updateRegisters':
RP6M32_I2CSlave.c:92: error: void value not ignored as it ought to be
make: *** [RP6M32_I2CSlave.o] Error 1
Danke Euch!
EDIT: Ich habe zum EInen vergessen, "checkSRFStatus" in meiner Slave aufzurufen... Wie und wo??
Lesezeichen