PSoC4200L I2C Master Interrupt Example code

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

cross mob
YongseokJeon
Level 4
Level 4
Distributor
50 replies posted 50 questions asked 25 replies posted

Hi All,

Is there an example source code for I2C master using Interrupt?

Please refer to below.

- IDE : PSoC Creator 4.2

- PSOC4200L

- I2C SCB

- I2C Master example using interrupt

  a. transfer

     When the Tx start interrrupt flag is triggered, then I2C ISR starts transferring rest of the data.

  b. receive

     If there is data in the I2C rx buffer, then the data is transferred from I2C Rx FIFO to the user defined buffer by the ISR.

Thanks and Regards,

YS

0 Likes
1 Solution
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi YSJE_3566666

Since the master initiates the read and the write command, an interrupt is not required. You could have a timer interrupt that periodically calls the read and write commands. But the slave will not write to the master's Tx buffer unless the communication is initiated by the master.

So the implementation is that you read the packet by calling the I2CMasterReadBuf API and transfer to the buffer directly. The API takes the buffer as a parameter.

Best regards,
Hari

View solution in original post

3 Replies
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi YSJE_3566666

Since the master initiates the read and the write command, an interrupt is not required. You could have a timer interrupt that periodically calls the read and write commands. But the slave will not write to the master's Tx buffer unless the communication is initiated by the master.

So the implementation is that you read the packet by calling the I2CMasterReadBuf API and transfer to the buffer directly. The API takes the buffer as a parameter.

Best regards,
Hari

YongseokJeon
Level 4
Level 4
Distributor
50 replies posted 50 questions asked 25 replies posted

Hi Hari,

Thanks for your reply.

Except for the a/b situation I mentioned, are there any other examples using interrupt?

There is something I want to test by referring to an I2C interrupt example.

Thanks and Regards,

YS

0 Likes
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hello YSJE_3566666

These interrupts are handled internally and you don't have to process in your application. You can, however, have your custom function if required by defining the variable I2C_SCB_IRQ_INTERRUPT_INTERRUPT_CALLBACK in cyapicallbacks.h and defining the function I2C_SCB_IRQ_Interrupt_InterruptCallback(). Please see the ISR present in I2C_SCB_IRQ.c file.

Best regards,
Hari

0 Likes