/* * Initialise the MCP39F511 energy monitor */ bool MCP39F511Interface::initialise() { mcp_comms = new MCP39F511Comms(this); /* Ensure we are notified when a transaction has completed */ connect(mcp_comms, SIGNAL(transactionComplete(Mcp39F511Transaction)), this, SLOT(transactionComplete(Mcp39F511Transaction))); if(!mcp_comms->initialise()) { return false; } outputTransactionId = 0; energyCounterTransactionId = 0; recordTransactionId = 0; calibrationTransactionId = 0; config1TransactionId = 0; config2TransactionId = 0; compPeriphTransactionId = 0; factoryResetId = 0; readAllRegistersId = 0; /* Setup PWM first so readAllRegisters() doesn't overwrite registers that have been configured whilst its in the queue to be sent to the chip. */ setupPWM(MCP_SOUNDER_FREQUENCY, MCP_SOUNDER_PWM_DUTY_CYLCE); readAllRegistersId = readAllRegisters(); initialisationInProgress = true; return true; }
int main(void) { initRP6M256(); initLCD(); writeString_P_WIFI("\n\nRP6 CONTROL M256 I2C Master Example Program!\n"); // IMPORTANT: I2CTWI_initMaster(100); // Initialize the TWI Module for Master operation // with 100kHz SCL Frequency // Register the event handlers: I2CTWI_setTransmissionErrorHandler(I2C_transmissionError); setLEDs(0b1111); // Turn all LEDs on! showScreenLCD("################", "################"); mSleep(500); showScreenLCD("I2C-Master", "Example Program 1"); mSleep(1000); // --------------------------------------- setLEDs(0b0000); // All LEDs off! uint8_t counter = 1; // The command and register used here - in the next example we define them all. #define CMD_SET_ACS_POWER 9 #define ACS_PWR_MED 2 // Set ACS to medium power (you can see the ACS value changes in the raw registers): I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, CMD_SET_ACS_POWER, ACS_PWR_MED); while(true) { // Increment a counter and send value to LEDs of the // Slave Controller: setLEDs(0b0001); showScreenLCD("INCREMENT", "COUNTER"); setCursorPosLCD(1, 11); writeIntegerLengthLCD(counter, DEC, 3); I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, 3, counter); counter++; // Read and display ALL registers of the slave controller: setLEDs(0b0010); readAllRegisters(); // Read the light sensors: setLEDs(0b0100); readLightSensors(); mSleep(250); } return 0; }