Exemplo n.º 1
0
/*
 * Initiate the Wire library and join the I2C bus as a slave. This should normally be called only once.
 * Parameters: address: the 7-bit slave address (optional);
 */
void WireClass::begin(uint8_t address){
    // Init the I2C as slave
    //xI2CSlaveInit(i2cPort, address, xI2C_GENERAL_CALL_EN); //mcy
    xI2CSlaveEnable(i2cPort);
    xI2CIntCallbackInit(i2cPort, WireClass::I2CCallbackFunc);
    xI2CSlaveIntEnable(i2cPort, xI2C_SLAVE_INT_DATA | xI2C_MASTER_INT_DATA);
    xIntEnable(xSysCtlPeripheraIntNumGet(i2cPort));
}
Exemplo n.º 2
0
//*****************************************************************************
//
//! The main function of the i2c slave receive with poll mode
//
//! return none
//
//*****************************************************************************
void SlaveReceivePoll(void)
{
    
    //
    // Congigure the i2c pin
    //
     xSPinTypeI2C(I2C0SCK, PA11);
     xSPinTypeI2C(I2C0DATA, PA10);
    
    //
    // Enable the i2c peripheral
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_I2C0);
    
    //
    // Init the I2C as slave 
    //
    I2CSlaveInit(I2C0_BASE, SlaveAddress, I2C_GENERAL_CALL_DIS);
    
    //
    // Install the i2c0 interrupt service function
    //
   // I2CIntCallbackInit(I2C0_BASE, ( xtEventCallback)SlavaRecvFunc);
    
    WriteBuf[8] = '\0';
    //
    // I2C master transfer config
    //
    I2CSlaveRcCfg.pvWBuf = WriteBuf;
    I2CSlaveRcCfg.ulWLen = WriteLength;
    I2CSlaveRcCfg.ulWCount = 0;
    I2CSlaveRcCfg.pvRBuf = ReceiveBuf;
    I2CSlaveRcCfg.ulRLen = ReceiveLength;
    //I2CSlaveRcCfg.pvRBuf = 0;
    //I2CSlaveRcCfg.ulRLen = 0;
    I2CSlaveRcCfg.ulRCount = 0;
    
    //
    // UART initialize
    //
    UART0Configuration();    
    xI2CIntCallbackInit(I2C0_BASE, SlavaRecvFunc);
    
    //
    // I2C salve receive wiht pollint mode
    //
    I2CSlaveTransfer(I2C0_BASE, &I2CSlaveRcCfg, I2C_TRANSFER_POLLING);
    
    //
    // Print the receive data form the master
    //
    while(1)
    {

    }
    
}
Exemplo n.º 3
0
//*****************************************************************************
//
//! The function is to set the i2c slave receive with poll mode
//
//! return none
//
//*****************************************************************************
void SlaveReceivePoll(void)
{
    //
    // Set system clock 
    //
    xSysCtlClockSet(12000000, xSYSCTL_XTAL_12MHZ | xSYSCTL_OSC_MAIN);
    
    //
    // Congigure the i2c pin
    //
    xSPinTypeI2C(I2C0SCK, PD5);
    xSPinTypeI2C(I2C0SDA, PD4);
    
    //
    // Enable the i2c peripheral
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_I2C0);
    
    //
    // Init the I2C as slave 
    //
    xI2CSlaveInit(I2C0_BASE, SlaveAddress, I2C_GENERAL_CALL_DIS);
    
    WriteBuf[8] = '\0';
    
    //
    // I2C master transfer config
    //
    I2CSlaveRcCfg.pvWBuf = WriteBuf;
    I2CSlaveRcCfg.ulWLen = WriteLength;
    I2CSlaveRcCfg.ulWCount = 0;
    I2CSlaveRcCfg.pvRBuf = ReceiveBuf;
    I2CSlaveRcCfg.ulRLen = ReceiveLength;
    I2CSlaveRcCfg.ulRCount = 0;
    
    xI2CIntCallbackInit(I2C0_BASE, SlavaRecvFunc);
    
    //
    // I2C salve receive wiht polling mode
    //
    xI2CSlaveTransfer(I2C0_BASE, &I2CSlaveRcCfg, xI2C_TRANSFER_POLLING);
}
Exemplo n.º 4
0
//*****************************************************************************
//
//! The main function of the i2c slave receive with poll mode
//
//! return none
//
//*****************************************************************************
void SlaveReceivePoll(void)
{
    //
    //Set the external 12MHZ clock as system clock 
    //
    SysCtlKeyAddrUnlock();
    xHWREG(SYSCLK_PWRCON) |= SYSCLK_PWRCON_XTL12M_EN;
    
    //
    // Congigure the i2c pin
    //
    // XPinTypeI2C(I2C0SCL, PA9);
    // XPinTypeI2C(I2C0DATA, PA8);
    GPIOPinFunctionSet(GPIO_FUNCTION_I2C , GPIO_PORTA_BASE , GPIO_PIN_9);
    GPIOPinFunctionSet(GPIO_FUNCTION_I2C , GPIO_PORTA_BASE , GPIO_PIN_8);
    
    //
    // Enable the i2c peripheral
    //
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_I2C0);
    
    //
    // Init the I2C as slave 
    //
    I2CSlaveInit(I2C0_BASE, SlaveAddress, I2C_GENERAL_CALL_DIS);
    
    //
    // Install the i2c0 interrupt service function
    //
   // I2CIntCallbackInit(I2C0_BASE, ( xtEventCallback)SlavaRecvFunc);
    
    WriteBuf[8] = '\0';
    //
    // I2C master transfer config
    //
    I2CSlaveRcCfg.pvWBuf = WriteBuf;
    I2CSlaveRcCfg.ulWLen = WriteLength;
    I2CSlaveRcCfg.ulWCount = 0;
    I2CSlaveRcCfg.pvRBuf = ReceiveBuf;
    I2CSlaveRcCfg.ulRLen = ReceiveLength;
    //I2CSlaveRcCfg.pvRBuf = 0;
    //I2CSlaveRcCfg.ulRLen = 0;
    I2CSlaveRcCfg.ulRCount = 0;
    
    //
    // UART initialize
    //
    UART0Configuration();    
    xI2CIntCallbackInit(I2C0_BASE, SlavaRecvFunc);
    
    //
    // I2C salve receive wiht pollint mode
    //
    I2CSlaveTransfer(I2C0_BASE, &I2CSlaveRcCfg, I2C_TRANSFER_POLLING);
    
    //
    // Print the receive data form the master
    //
    while(1)
    {

    }
    
}