• AVR Freaks

Hot!I2C Slave with Harmony 2.0.6.0 in StaticMode

Author
EH
Starting Member
  • Total Posts : 50
  • Reward points : 0
  • Joined: 2010/11/28 03:09:31
  • Location: 0
  • Status: offline
2019/07/05 03:59:22 (permalink)
0

I2C Slave with Harmony 2.0.6.0 in StaticMode

Hi Community,
 
I want to use two I2C modules. One as Master the other as Slave. I`m using the "DriverLibrary". The Master (index 0) is working without problems. For tests, I have two I2C modules as Slave (index1/index2).
 
For the Slave I have such SW:
 
void I2C_SlaveTasks(void)
{
    
    switch (i2cDataSlave.state)
    {
        case I2C_STATE_INIT:
        {
            ESP8266.drvI2CHandle = DRV_I2C_Open(DRV_I2C_INDEX_2, DRV_IO_INTENT_NONBLOCKING|DRV_IO_INTENT_READWRITE);
            if (DRV_HANDLE_INVALID == ESP8266.drvI2CHandle)
            {
// Handle open error
                Nop();
            }
// DRV_I2C_BufferEventHandlerSet( ESP8266.drvI2CHandle,
// APP_I2C_SlaveTransfer_Callback,
// ESP8266.TxBuffer);

            i2cDataSlave.state = SET_BUFFER;
            
            
            
          
            break;
        }
        case SET_BUFFER:
        {
            ESP8266.TxBuffer[0] = TempIstE.Val_H + 48;
            ESP8266.TxBuffer[1] = TempIstE.Val_T + 48;
            ESP8266.TxBuffer[2] = TempIstE.Val_O + 48;
            ESP8266.TxBuffer[3] = TempIstI.Val_H + 48;
            ESP8266.TxBuffer[4] = TempIstI.Val_T + 48;
            ESP8266.TxBuffer[5] = TempIstI.Val_O + 48;
            ESP8266.TxBuffer[6] = HumyIstI.Val_H + 48;
            ESP8266.TxBuffer[7] = HumyIstI.Val_T + 48;
            ESP8266.TxBuffer[8] = HumyIstI.Val_O + 48;

            ESP8266.BufferHandleTx = DRV_I2C_Transmit( ESP8266.drvI2CHandle,
                                                        ESP8266.address,
                                                        &ESP8266.TxBuffer[0],
                                                        ESP8266.TxNumBytes,
                                                        &ESP8266.TxBuffer[0]);
            i2cDataSlave.state = WAIT_FOR_MASTER;
            break;
        }
        case WAIT_FOR_MASTER:
        {
            ESP8266.BufferEvent = DRV_I2C_TransferStatusGet ( ESP8266.drvI2CHandle,
                            ESP8266.BufferHandleTx);
            
            if (ESP8266.BufferEvent == DRV_I2C_BUFFER_EVENT_COMPLETE)
            {
// ESP8266.TxBuffer[0] = TempIstE.Val_H + 48;
// ESP8266.TxBuffer[1] = TempIstE.Val_T + 48;
// ESP8266.TxBuffer[2] = TempIstE.Val_O + 48;
// ESP8266.TxBuffer[3] = TempIstI.Val_H + 48;
// ESP8266.TxBuffer[4] = TempIstI.Val_T + 48;
// ESP8266.TxBuffer[5] = TempIstI.Val_O + 48;
// ESP8266.TxBuffer[6] = HumyIstI.Val_H + 48;
// ESP8266.TxBuffer[7] = HumyIstI.Val_T + 48;
// ESP8266.TxBuffer[8] = HumyIstI.Val_O + 48;
                i2cDataSlave.state = SET_BUFFER;
            }
            break;
        }
    }
}

 
When I`m using the "DRV_I2C_BufferEventHandlerSet", then after the first sent package, all the Bytes get a "0xFF" and my program stops. When the MasterModule is inactive, all is working fine with the slave. When I have the solution above (without the "HandlerSet"), in the most cases the correct data was sent, but sometimes "0x00" packages. The other parts of my program is working. For the I2C Drivers, I´m using the "DynamicMode".
 
Then I decide to switch to the "StaticMode". I think, the different is, that all the I2C modules are using theyr own DriverFunktions. It is more divided, I guess. Here is the SlaveCallBackFunction required. But I could not get a working solution. The interrupt is enabled during the "DRV_I2C_Transmit" function, But the ISR is not started.
 
 
 
void __ISR(_I2C_5_VECTOR, ipl2AUTO) _IntHandlerDrvI2CInstance2(void)
{
    DRV_I2C2_Tasks(); <--Breakpoint set here, PC did not stop
 
}
 

 
 
For the MasterModule, the ISR is called.
 
So far I could see, all the interrupt-stuff was configured by Harmony during the SystemInit, I guess.
 
It would be nice, when I could get some suggestions/hints where could be the problem.
 
Thank you
Henry
 
 
 
 
 
#1

2 Replies Related Threads

    EH
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2010/11/28 03:09:31
    • Location: 0
    • Status: offline
    Re: I2C Slave with Harmony 2.0.6.0 in StaticMode 2019/07/22 00:59:29 (permalink)
    0
    Who is interested for:
     
    I did some more investigations and found out, that the Harmony created ISR for the I2C slave is calling the Application-CallBack two times: for the read-from-master operation and for the write-to-master operation. So the data buffer must be available syncronized when the master is requesting the related operation. I changed my code, so that the buffer nomination was done in the App-CallBack:
     
    void APP_I2C_ID5_SlaveTransfer_Callback(DRV_I2C_BUFFER_EVENT event, void * context)
    {
        Nop(); // for test
        if (event == DRV_I2C_BUFFER_SLAVE_WRITE_REQUESTED)
        {
            ESP8266.TxBuffer[0] = TempIstE.Val_H + 48;
            ESP8266.TxBuffer[1] = TempIstE.Val_T + 48;
            ESP8266.TxBuffer[2] = TempIstE.Val_O + 48;
            ESP8266.TxBuffer[3] = TempIstI.Val_H + 48;
            ESP8266.TxBuffer[4] = TempIstI.Val_T + 48;
            ESP8266.TxBuffer[5] = TempIstI.Val_O + 48;
            ESP8266.TxBuffer[6] = HumyIstI.Val_H + 48;
            ESP8266.TxBuffer[7] = HumyIstI.Val_T + 48;
            ESP8266.TxBuffer[8] = HumyIstI.Val_O + 48;
            ESP8266.BufferHandleTx = DRV_I2C_Transmit( ESP8266.drvI2CHandle,
                                                            ESP8266.address,
                                                            &ESP8266.TxBuffer[0],
                                                            ESP8266.TxNumBytes,
                                                            &ESP8266.TxBuffer[0]);
            i2cDataSlave.state = WAIT_FOR_MASTER; //state machine for my I2C-Tasks
        }
        if (event == DRV_I2C_BUFFER_SLAVE_READ_REQUESTED)
        {
            Nop(); //slave read currently not needed
        }
    }

     
    So it is working.
     
    Unfortunately the I2C module as slave is not really good described in the Driver-Lib of Harmony. At least I could not find it as detailed as needed.
    #2
    Paul PortSol
    Super Member
    • Total Posts : 471
    • Reward points : 0
    • Joined: 2015/07/03 11:52:03
    • Location: Newfoundland, Canada
    • Status: offline
    Re: I2C Slave with Harmony 2.0.6.0 in StaticMode 2019/07/22 06:01:39 (permalink)
    0
    Ensure you check the Harmony notes and the errata for your PIC, the "Bit Bang" I2C option in MHC may be needed for reliable operation.
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5