MB9A314L I2C Slave Example

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ViKu_1079246
Level 1
Level 1
First reply posted First question asked

Hi,

I use MB9A314L MCU 64Pin in FM_PDL_2.0.1,

Where I can find I2C Slave in interrupt example.

Thank you

0 Likes
1 Solution

Hi,

I have achieved I2C interrupt in my project,

void I2c_Slave_interrupt_init (void)

{

    //I2C Port1 Slave initial

    stc_mfs_i2c_config_t stcI2cConfig;

    stc_i2c_irq_cb_t     stcI2cIrqCb;

    stc_i2c_irq_en_t     stcI2cIrqEn;

   

    PDL_ZERO_STRUCT(stcI2cConfig);

    PDL_ZERO_STRUCT(stcI2cIrqCb);

    PDL_ZERO_STRUCT(stcI2cIrqEn);

   

    SetPinFunc_SOT1_1();

    SetPinFunc_SCK1_1();

   

    /* Initialize interrupt callback functions */

    stcI2cIrqCb.pfnRxIrqCb   = I2cRxCallback;

    stcI2cIrqCb.pfnTxRxIrqCb = I2cIntCallback;

    stcI2cIrqCb.pfnStopDetectIrqCb = I2cStopDetectCallback;

   

    stcI2cIrqEn.bRxIrq        =TRUE;

    stcI2cIrqEn.bTxRxIrq      =TRUE;

    stcI2cIrqEn.bStopDetectIrq=TRUE;

   

    /* Initialize configuration structure */

    stcI2cConfig.enMsMode       = I2cSlave;

    stcI2cConfig.u32BaudRate    = 100000u;

    stcI2cConfig.u8SlaveAddr    = I2C_SLAVE_ADDR;///< Slave address (This is effective on slave mode.)

    stcI2cConfig.u8SlaveMaskAddr= I2C_MASK_ADDR; ///< Slave Mask address (This is effective on slave mode.)

    stcI2cConfig.bWaitSelection = FALSE;

    stcI2cConfig.bDmaEnable     = FALSE;

    stcI2cConfig.pstcFifoConfig = NULL;

    stcI2cConfig.pstcIrqEn  = &stcI2cIrqEn;

    stcI2cConfig.pstcIrqCb  = &stcI2cIrqCb;

    stcI2cConfig.bTouchNvic = TRUE;

   

    if( Ok != Mfs_I2c_Init(I2cCh1, &stcI2cConfig)){

      printf("I2C Slave Port-1 initial NG\n");

    }else{

      printf("I2C Slave Port-1 initial OK\n");

    }

}

#define RX_LEN 16

uint8_t rx[RX_LEN ];

uint8_t rx_cnt;

static void I2cRxCallback(void)

{

    rx[rx_cnt++] = Mfs_I2c_ReceiveData(I2cCh1);

    Mfs_I2c_ConfigAck(I2cCh1, I2cAck);

    Mfs_I2c_ClrStatus(I2cCh1, I2cRxTxIrq);

}

static void I2cIntCallback(void)

{

  if(TRUE == Mfs_I2c_GetStatus(I2cCh1, I2cDevAddrMatch))

   {

      //printf("I2cDevAddrMatch\n");

      Mfs_I2c_ConfigAck(I2cCh1, I2cAck);

      Mfs_I2c_ClrStatus(I2cCh1, I2cRxTxIrq);

   }

 

   if(Mfs_I2c_GetStatus(I2cCh1, I2cBusErr) == TRUE)

   {

      //printf("Bus Error\n");

   }

   Mfs_I2c_ClrStatus(I2cCh1, I2cRxTxIrq);

}

static void I2cStopDetectCallback(void)

{

    uint16_t i=0;

    if(TRUE == Mfs_I2c_GetStatus(I2cCh1, I2cStopDetect))

    {

        Mfs_I2c_ClrStatus(I2cCh1, I2cStopDetect);

        Mfs_I2c_ClrStatus(I2cCh1, I2cRxTxIrq);

        printf("I2C RX datas: "); 

        for( i=0; i<rx_cnt; i++){

              printf(" 0x%X ", rx);

        }

        printf("\n");

    }

}

Thanks

View solution in original post

0 Likes
3 Replies
ShipingW_81
Moderator
Moderator
Moderator
500 replies posted 250 solutions authored 250 replies posted

ViKu_1079246

You can find all available code exmaples for FMx devices from the PDL 2.0.x / 2.1.0. You can check if the existing I2C slave code is what you want.

The resouces are able to access through - https://www.cypress.com/design-guides/peripheral-driver-library-pdl-software-and-documentation-archi...

0 Likes
ViKu_1079246
Level 1
Level 1
First reply posted First question asked

Hi,

The PDL 2.0.1 Example about I2C has i2c_slave_wkup only,

I need I2C Slave transmit/received in interrupt.

Thank you

0 Likes

Hi,

I have achieved I2C interrupt in my project,

void I2c_Slave_interrupt_init (void)

{

    //I2C Port1 Slave initial

    stc_mfs_i2c_config_t stcI2cConfig;

    stc_i2c_irq_cb_t     stcI2cIrqCb;

    stc_i2c_irq_en_t     stcI2cIrqEn;

   

    PDL_ZERO_STRUCT(stcI2cConfig);

    PDL_ZERO_STRUCT(stcI2cIrqCb);

    PDL_ZERO_STRUCT(stcI2cIrqEn);

   

    SetPinFunc_SOT1_1();

    SetPinFunc_SCK1_1();

   

    /* Initialize interrupt callback functions */

    stcI2cIrqCb.pfnRxIrqCb   = I2cRxCallback;

    stcI2cIrqCb.pfnTxRxIrqCb = I2cIntCallback;

    stcI2cIrqCb.pfnStopDetectIrqCb = I2cStopDetectCallback;

   

    stcI2cIrqEn.bRxIrq        =TRUE;

    stcI2cIrqEn.bTxRxIrq      =TRUE;

    stcI2cIrqEn.bStopDetectIrq=TRUE;

   

    /* Initialize configuration structure */

    stcI2cConfig.enMsMode       = I2cSlave;

    stcI2cConfig.u32BaudRate    = 100000u;

    stcI2cConfig.u8SlaveAddr    = I2C_SLAVE_ADDR;///< Slave address (This is effective on slave mode.)

    stcI2cConfig.u8SlaveMaskAddr= I2C_MASK_ADDR; ///< Slave Mask address (This is effective on slave mode.)

    stcI2cConfig.bWaitSelection = FALSE;

    stcI2cConfig.bDmaEnable     = FALSE;

    stcI2cConfig.pstcFifoConfig = NULL;

    stcI2cConfig.pstcIrqEn  = &stcI2cIrqEn;

    stcI2cConfig.pstcIrqCb  = &stcI2cIrqCb;

    stcI2cConfig.bTouchNvic = TRUE;

   

    if( Ok != Mfs_I2c_Init(I2cCh1, &stcI2cConfig)){

      printf("I2C Slave Port-1 initial NG\n");

    }else{

      printf("I2C Slave Port-1 initial OK\n");

    }

}

#define RX_LEN 16

uint8_t rx[RX_LEN ];

uint8_t rx_cnt;

static void I2cRxCallback(void)

{

    rx[rx_cnt++] = Mfs_I2c_ReceiveData(I2cCh1);

    Mfs_I2c_ConfigAck(I2cCh1, I2cAck);

    Mfs_I2c_ClrStatus(I2cCh1, I2cRxTxIrq);

}

static void I2cIntCallback(void)

{

  if(TRUE == Mfs_I2c_GetStatus(I2cCh1, I2cDevAddrMatch))

   {

      //printf("I2cDevAddrMatch\n");

      Mfs_I2c_ConfigAck(I2cCh1, I2cAck);

      Mfs_I2c_ClrStatus(I2cCh1, I2cRxTxIrq);

   }

 

   if(Mfs_I2c_GetStatus(I2cCh1, I2cBusErr) == TRUE)

   {

      //printf("Bus Error\n");

   }

   Mfs_I2c_ClrStatus(I2cCh1, I2cRxTxIrq);

}

static void I2cStopDetectCallback(void)

{

    uint16_t i=0;

    if(TRUE == Mfs_I2c_GetStatus(I2cCh1, I2cStopDetect))

    {

        Mfs_I2c_ClrStatus(I2cCh1, I2cStopDetect);

        Mfs_I2c_ClrStatus(I2cCh1, I2cRxTxIrq);

        printf("I2C RX datas: "); 

        for( i=0; i<rx_cnt; i++){

              printf(" 0x%X ", rx);

        }

        printf("\n");

    }

}

Thanks

0 Likes