Hallo,
hm.. okay.. das bringt mich wenigstens schon mal einen schritt weiter. Allerdings hab ich nun das Beispielprogramm des Cmps03 mal wie folgt umgeschrieben:
Allerdings, das Ergebnis:Code:/* * **************************************************************************** * RP6 ROBOT SYSTEM - ROBOT BASE EXAMPLES * **************************************************************************** * Example: I2C Master - Hdmm01 Rp6 * Author(s): M.Hunfeld * **************************************************************************** * Description: * * This Example shows how to use the compass module Hdmm01 * with RP6Library. * * **************************************************************************** */ /*****************************************************************************/ // Includes: #include "RP6RobotBaseLib.h" // IMPORTANT: #include "RP6I2CmasterTWI.h" // Include the I²C-Bus Slave Library /*****************************************************************************/ // I2C Event handlers: /** * 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). * The most common mistakes are: * - using the wrong address for the slave * - slave not active or not connected to the I2C-Bus * - too fast requests for a slower slave * Be sure to check this if you get I2C errors! */ void I2C_transmissionError(uint8_t errorState) { writeString_P("\nI2C ERROR --> TWI STATE IS: 0x"); writeInteger(errorState, HEX); writeChar('\n'); } /*****************************************************************************/ #define CMPS 0x60//Die Adresse des Hdmm01 Moduls #define Read 0x61//Die Adresse des Hdmm01 Moduls zum Lesen #define MEASURE_16_BIT 0x00//Die Register-Adresse uint16_t readCMPS(uint8_t datareg) {uint16_t result = 0xffff; uint8_t results[3]; I2CTWI_transmitByte(CMPS, datareg); if (datareg == MEASURE_16_BIT) { I2CTWI_readBytes(Read, results, 2); result = (results[0] << 8) + results[1]; } else { result = I2CTWI_readByte(Read); } return result; } void task_CMPS(void) {uint16_t degrees; if (getStopwatch1() > 500) { degrees = readCMPS(MEASURE_16_BIT); writeString_P("Richtung: "); writeIntegerLength((degrees / 10), DEC, 3); writeChar('.'); writeIntegerLength(degrees, DEC, 1); writeString_P(" Grad\n"); setStopwatch1(0); } } /*****************************************************************************/ // Main - The program starts here: int main(void) { initRobotBase(); I2CTWI_initMaster(100); // Initialize the TWI Module for Master operation // with 100kHz SCL Frequency // Register the event handlers: I2CTWI_setTransmissionErrorHandler(I2C_transmissionError); powerON(); startStopwatch1(); while(true) { task_I2CTWI(); task_RP6System(); task_CMPS(); } return 0; }
Es wird wahrscheinlich daran liegen, dass es bei dem Hdmm01 Modul nur ein Register gibt, welches man allerdings manipulieren muss. Malthy hat es in Bascom so gelöst:Code:I2C ERROR --> TWI STATE IS: 0x20 I2C ERROR --> TWI STATE IS: 0x48 Richtung: 000.0 Grad I2C ERROR --> TWI STATE IS: 0x20 I2C ERROR --> TWI STATE IS: 0x48 Richtung: 000.0 Grad
072.' sensor adressieren (schreiben)
073.I2cwbyte Cmp_w
074.' register adressieren
075.I2cwbyte &H00
076.'
077.' register manipulieren -> reset coil
078.I2cwbyte &B00000100
Doch wie realisiert man dies in "C", für die Rp6 Lib tauglich?
Liebe Grüße Marcel







Zitieren


Lesezeichen