Content originally posted in LPCWare by robertpalmerjr on Tue Mar 25 09:16:16 MST 2014
Which mode you should use is really dependent on your application. Generally speaking...
Polling Advantages:
1. simpler to understand. You start the transfer, the call blocks until the transfer is complete, when the call returns, your code continues on doing the next thing
2. uses fewer resources (no interrupt required)
Polling Disadvantages:
1. the call blocks, which means you can't do anything else while the transfer is occurring (well, there are exceptions, you could be running in an RTOS task, see below)
2. draws more power, the CPU is constantly running attempting to determine the state of the transfer and progress through the transfer.
Interrupt Advantages:
1. asynchronous, the transfer happens in the back ground. You just set up the transfer and start it then go off and do other work. You'll get notified with the transfer is complete.
2. if you use any low power configurations and use the WFI instruction, the processor will go to sleep in between states, thus saving power.
Interrupt Disadvantages:
1. more complex, you must understand and deal with the fact that when your code returns from the "write" call that the data has not yet been written, it is only complete after you receive the final state in the interrupt.
2. uses more resources - you have to manage the interrupt for i2c interface
One other option is to use an RTOS (e.g. freeRTOS) and put a polling instruction in a separate task. This can give you the non-blocking effect, you send a message to the i2c task with the data to be transferred, the task will then handle the transfer.
This addresses the blocking disadvantage, however, this does not address the power savings disadvantage of polling. The i2c task will still keep the processor awake and consume more power.
If you're developing a simple app that just periodically updates a digital potentiometer and you're only transferring a few bytes at a time, and you don't care about power consumption, then polling is for you. If you're developing a complex application that has many things to do, needs to be very responsive, has to transfer large numbers of bytes at a time and you're sensitive to power consumption, interrupt driven is for you.
Taking a quick look at your code and not testing it, I'm guessing you need to use the board API (board.h) or chip API to configure the I2C1 pins and enable the I2C module. I2C0 is by default connected to external pins, I think I2C1 may be multiplexed with GPIO and therefore the pins need to be configured first. Look at the examples in lpcopen for the i2c driver.